Setup database and model views master
authorSteve Sutton <steve@gaslightmedia.com>
Sat, 25 May 2019 10:54:52 +0000 (06:54 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Sat, 25 May 2019 10:54:52 +0000 (06:54 -0400)
First setup of add edit message.

classes/data/dataEmailMessages.php [new file with mode: 0644]
models/admin/messages/index.php [new file with mode: 0644]
setup/adminMenus.php
setup/databaseScripts/create_database_V0.0.1.sql [new file with mode: 0644]
setup/databaseScripts/dbVersions.php [new file with mode: 0644]
setup/validActions.php
views/admin/footer.html [new file with mode: 0644]
views/admin/header.html [new file with mode: 0644]
views/admin/messages/editHtmlEmail.html [new file with mode: 0644]
views/admin/messages/index.html [new file with mode: 0644]
views/admin/messages/list.html [new file with mode: 0644]

diff --git a/classes/data/dataEmailMessages.php b/classes/data/dataEmailMessages.php
new file mode 100644 (file)
index 0000000..3e629b5
--- /dev/null
@@ -0,0 +1,189 @@
+<?php
+/**
+ * GLM Member-DB WordPress Add-On Plugin
+ * Data Class Email Messages
+ *
+ * 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 $
+ */
+
+/**
+ * GlmDataEmailMessages 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 GlmDataEmailMessages 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;
+
+    /**
+     * 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_MESSAGES_PLUGIN_DB_PREFIX . 'email_messages';
+
+        /*
+         * Table Data Fields
+         */
+
+        $this->fields = array (
+
+            'id' => array (
+                'field' => 'id',
+                'type' => 'integer',
+                'view_only' => true,
+                'use' => 'a'
+            ),
+
+            // Name
+            'from_email' => array (
+                'field'    => 'from_email',
+                'type'     => 'text',
+                'required' => true,
+                'use'      => 'a'
+            ),
+
+            // Name
+            'from_name' => array (
+                'field'    => 'from_name',
+                'type'     => 'text',
+                'required' => true,
+                'use'      => 'a'
+            ),
+
+            // Name
+            'reply_to_email' => array (
+                'field'    => 'reply_to_email',
+                'type'     => 'text',
+                'required' => true,
+                'use'      => 'a'
+            ),
+
+            // Name
+            'subject' => array (
+                'field'    => 'subject',
+                'type'     => 'text',
+                'required' => true,
+                'use'      => 'a'
+            ),
+
+            // Date/Time Created
+            'last_updated' => array (
+                'field' => 'last_updated',
+                'type'  => 'datetime',
+                'use'   => 'a'
+            ),
+
+            // Name
+            'message_body' => array (
+                'field'    => 'message_body',
+                'type'     => 'text',
+                'required' => 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 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;
+    }
+
+
+}
diff --git a/models/admin/messages/index.php b/models/admin/messages/index.php
new file mode 100644 (file)
index 0000000..9e7776a
--- /dev/null
@@ -0,0 +1,157 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Admin Members Dashboard
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+// Load Members data abstract
+require_once GLM_MEMBERS_MESSAGES_PLUGIN_CLASS_PATH.'/data/dataEmailMessages.php';
+
+/*
+ * This class performs the work for the default action of the "Members" menu
+ * option, which is to display the members dashboard.
+ *
+ */
+class GlmMembersAdmin_messages_index extends GlmDataEmailMessages
+{
+
+    /**
+     * 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 )
+    {
+        $view    = 'index';
+        $success = true;
+        $option  = '';
+
+        if ( isset( $_REQUEST['option'] ) ) {
+            $option = $_REQUEST['option'];
+        }
+
+        $templateData = array(
+            'newEntry' => false,
+        );
+
+        switch ( $option ) {
+        case 'list':
+            $view = 'list';
+            $messages = $this->getList();
+            // echo '<pre>' . print_r( $messages, true ) . '</pre>';
+            $templateData['messages'] = $messages;
+            break;
+        case 'editHtmlEmail':
+            $view = 'editHtmlEmail';
+            if ( isset( $_REQUEST['id'] ) && $id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) {
+                $message = $this->editEntry( $id );
+            } else {
+                $message = $this->newEntry();
+                $templateData['newEntry'] = true;
+            }
+            $templateData['message'] = $message;
+            break;
+        case 'updateHtmlEmail':
+            // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true) . '</pre>';
+            $_REQUEST['last_updated'] = date( 'Y-m-d H:i:s' );
+            if ( isset( $_REQUEST['id'] ) && $id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) {
+                $message = $this->updateEntry( $id );
+            } else {
+                $message = $this->insertEntry();
+                // echo '<pre>' . print_r( $message, true) . '</pre>';
+            }
+            break;
+        default:
+            break;
+        }
+
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status'           => $success,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/messages/'.$view.'.html',
+            'data'             => $templateData
+        );
+
+    }
+
+
+}
index 916b834..4cf1858 100644 (file)
  *
  */
 
+add_submenu_page(
+    'glm-members-admin-menu-members',
+    'Message Center',
+    'Message Center',
+    'glm_members_members',
+    'glm-members-admin-menu-messages',
+    function() {
+        $this->controller( 'messages' );
+    }
+);
+// add_submenu_page(
+//     'glm-members-admin-menu-members',
+//     'Messages',
+//     '&nbsp;&nbsp;&nbsp;&nbsp;Messages',
+//     'glm_members_members',
+//     'glm-members-admin-menu-messages-list',
+//     function() {
+//
+//     }
+// );
diff --git a/setup/databaseScripts/create_database_V0.0.1.sql b/setup/databaseScripts/create_database_V0.0.1.sql
new file mode 100644 (file)
index 0000000..06b81db
--- /dev/null
@@ -0,0 +1,33 @@
+-- Gaslight Media Members Database
+-- File Created: 5/24/19
+-- Database Version: 0.0.1
+-- Database Creation Script - Messages Add-On
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+-- email_messages
+CREATE TABLE {prefix}email_messages (
+    id INT NOT NULL AUTO_INCREMENT,
+    from_email TINYTEXT NOT NULL,
+    from_name TINYTEXT NULL,
+    reply_to_email TINYTEXT NULL,
+    subject TINYTEXT NOT NULL,
+    last_updated DATETIME NOT NULL,
+    message_body TEXT NOT NULL,
+    PRIMARY KEY (id)
+);
+
+----
+
+-- Logs
+CREATE TABLE {prefix}email_logs (
+    id INT NOT NULL AUTO_INCREMENT,
+    to_email TINYTEXT NOT NULL,
+    subject TINYTEXT NOT NULL,
+    from_email TINYTEXT NOT NULL,
+    reply_to_email TINYTEXT NULL,
+    message_body TEXT NOT NULL,
+    send_date DATETIME NOT NULL,
+    PRIMARY KEY (id)
+);
diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php
new file mode 100644 (file)
index 0000000..110fc98
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members Messages DB Versions
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  dbVersions.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+$glmMembersMessagesDbVersions = array(
+    '0.0.1' => array('version' => '0.0.1', 'tables' => 2, 'date' => '05/24/2019'),
+);
+
index 89b3787..159fa20 100644 (file)
 
 $glmMembersMessagesAddOnValidActions = array(
     'adminActions' => array(
+        'messages' => array(
+            'index' => GLM_MEMBERS_MESSAGES_PLUGIN_SLUG,
+        ),
     ),
     'frontActions' => array(
     )
 );
 
-?>
\ No newline at end of file
+?>
diff --git a/views/admin/footer.html b/views/admin/footer.html
new file mode 100644 (file)
index 0000000..6029dc1
--- /dev/null
@@ -0,0 +1,11 @@
+
+    </div> <!-- / admin content area -->
+    <div class="glm-copyright">
+        {$glmPluginName}<br>
+        Copyright &copy; 2014-{$thisYear} Gaslight Media - All Rights Reserved<br>
+        Phone: 231-487-0692 - E-Mail: info@gaslightmedia.com<br>
+        <a href="http://www.gaslightmedia.com">http://www.gaslightmedia.com</a>
+    </div>
+     
+  
+</div> <!-- / wrap -->
\ No newline at end of file
diff --git a/views/admin/header.html b/views/admin/header.html
new file mode 100644 (file)
index 0000000..b4a464d
--- /dev/null
@@ -0,0 +1,5 @@
+<div class="wrap">
+
+    {* Navigation *}
+
+    <div id="glm-admin-content-container">
diff --git a/views/admin/messages/editHtmlEmail.html b/views/admin/messages/editHtmlEmail.html
new file mode 100644 (file)
index 0000000..5df0869
--- /dev/null
@@ -0,0 +1,91 @@
+<h2>Html Email</h2>
+{include file='admin/header.html'}
+
+<form action="{$thisUrl}?page={$thisPage}" method="post">
+    <input type="hidden" name="option" value="updateHtmlEmail" />
+    {if !$newEntry}
+        <input type="hidden" name="id" value="{$message.fieldData.id}" />
+    {/if}
+
+    <table>
+
+        <tr>
+            <th {if $message.fieldRequired.from_name}class="glm-required"{/if}>From Name:</th>
+            <td {if $message.fieldFail.from_name}class="glm-form-bad-input" data-tabid="glm-message-from_name"{/if}>
+                <input type="text" name="from_name" class="glm-form-text-input" value="{$message.fieldData.from_name|escape}" {if $message.fieldRequired.from_name}required{/if} />
+            </td>
+        </tr>
+        <tr>
+            <th {if $message.fieldRequired.from_email}class="glm-required"{/if}>From Email:</th>
+            <td {if $message.fieldFail.from_email}class="glm-form-bad-input" data-tabid="glm-message-from_email"{/if}>
+                <input type="text" name="from_email" class="glm-form-text-input" value="{$message.fieldData.from_email|escape}" {if $message.fieldRequired.from_email}required{/if} />
+            </td>
+        </tr>
+        <tr>
+            <th {if $message.fieldRequired.reply_to_email}class="glm-required"{/if}>Reply To:</th>
+            <td {if $message.fieldFail.reply_to_email}class="glm-form-bad-input" data-tabid="glm-message-reply_to_email"{/if}>
+                <input type="text" name="reply_to_email" class="glm-form-text-input" value="{$message.fieldData.reply_to_email|escape}" {if $message.fieldRequired.reply_to_email}required{/if} />
+            </td>
+        </tr>
+        <tr>
+            <th {if $message.fieldRequired.subject}class="glm-required"{/if}>Subject:</th>
+            <td {if $message.fieldFail.subject}class="glm-form-bad-input" data-tabid="glm-message-subject"{/if}>
+                <input type="text" name="subject" class="glm-form-text-input" value="{$message.fieldData.subject|escape}" {if $message.fieldRequired.subject}required{/if} />
+            </td>
+        </tr>
+        <tr>
+            <th {if $message.fieldRequired.message_body}class="glm-required"{/if}>Message Content:</th>
+            <td {if $message.fieldFail.message_body}class="glm-form-bad-input" data-tabid="glm-message-message_body"{/if}>
+                {if $message}
+                    {$textAreaContent = $message.fieldData.message_body}
+                {else}
+                    {$textAreaContent = ''}
+                {/if}
+                {wp_editor(
+                    $textAreaContent,
+                    'message_body',
+                    json_decode('{
+                        "media_buttons": false,
+                        "quicktags": false,
+                        "textarea_name": "message_body",
+                        "editor_height": 250
+                    }', true)
+                )}
+            </td>
+        </tr>
+        <tr>
+            <td colspan="2">
+                <strong>Merge Tags</strong>
+                <p>The "merge tags" listed below may be used in the email message to include certain information about the Member or Contact. Be sure to include the "{" and "}" and "$" characters exactly as shown.</p>
+                <p>
+                <table>
+                    <tr>
+                        <th>{literal}{$member.name}{/literal}</th>
+                        <td>Member Name</td>
+                    </tr>
+                    <tr>
+                        <th>{literal}{$contact.fname}{/literal}</th>
+                        <td>Contact First Name</td>
+                    </tr>
+                    <tr>
+                        <th>{literal}{$contact.lname}{/literal}</th>
+                        <td>Contact Last Name</td>
+                    </tr>
+                </table>
+
+
+                </p>
+            </td>
+        </tr>
+
+        <tr>
+            <td colspan="2">
+                <input type="submit" class="button button-primary" value="Save" />
+            </td>
+        </tr>
+
+    </table>
+
+</form>
+
+{include file='admin/footer.html'}
diff --git a/views/admin/messages/index.html b/views/admin/messages/index.html
new file mode 100644 (file)
index 0000000..0776592
--- /dev/null
@@ -0,0 +1,24 @@
+<h2>Messages Dashboard</h2>
+
+{include file='admin/header.html'}
+
+<a href="{$thisUrl}?page={$thisPage}&option=list">HTML Messages</a>
+<a href="{$thisUrl}?page={$thisPage}&option=editHtmlEmail" class="button glm-right">Add HTML Email</a>
+
+This is your dashboard
+
+<div id="glm-messages-app"></div>
+
+{*
+<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
+<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
+<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
+<script type="text/babel">
+    ReactDOM.render(
+        <h1>Hello, world!</h1>,
+        document.getElementById("glm-messages-app")
+    );
+</script>
+*}
+
+{include file='admin/footer.html'}
diff --git a/views/admin/messages/list.html b/views/admin/messages/list.html
new file mode 100644 (file)
index 0000000..337ec76
--- /dev/null
@@ -0,0 +1,29 @@
+<h2>List Messages</h2>
+{include file='admin/header.html'}
+
+<table class="wp-list-table striped glm-admin-table-single">
+    <thead>
+        <tr>
+            <th align="left">ID</th>
+            <th align="left">Subject</th>
+            <th align="left">Last Updated</th>
+            <th align="left">Sent</th>
+            <th align="left">Stats</th>
+        </tr>
+    </thead>
+    <tbody>
+        {if $messages}
+            {foreach $messages as $message}
+                <tr>
+                    <td> {$message.id} </td>
+                    <td> <a href="{$thisUrl}?page={$thisPage}&option=editHtmlEmail&id={$message.id}">{$message.subject}</a> </td>
+                    <td> {$message.last_updated.timestamp|date_format} </td>
+                    <td> </td>
+                    <td> </td>
+                </tr>
+            {/foreach}
+        {/if}
+    </tbody>
+</table>
+
+{include file='admin/footer.html'}