From b85c9ab5f4602a094df0fc316e49c4e488bac7f9 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Sat, 25 May 2019 06:54:52 -0400 Subject: [PATCH] Setup database and model views First setup of add edit message. --- classes/data/dataEmailMessages.php | 189 ++++++++++++++++++ models/admin/messages/index.php | 157 +++++++++++++++ setup/adminMenus.php | 20 ++ .../create_database_V0.0.1.sql | 33 +++ setup/databaseScripts/dbVersions.php | 19 ++ setup/validActions.php | 5 +- views/admin/footer.html | 11 + views/admin/header.html | 5 + views/admin/messages/editHtmlEmail.html | 91 +++++++++ views/admin/messages/index.html | 24 +++ views/admin/messages/list.html | 29 +++ 11 files changed, 582 insertions(+), 1 deletion(-) create mode 100644 classes/data/dataEmailMessages.php create mode 100644 models/admin/messages/index.php create mode 100644 setup/databaseScripts/create_database_V0.0.1.sql create mode 100644 setup/databaseScripts/dbVersions.php create mode 100644 views/admin/footer.html create mode 100644 views/admin/header.html create mode 100644 views/admin/messages/editHtmlEmail.html create mode 100644 views/admin/messages/index.html create mode 100644 views/admin/messages/list.html diff --git a/classes/data/dataEmailMessages.php b/classes/data/dataEmailMessages.php new file mode 100644 index 0000000..3e629b5 --- /dev/null +++ b/classes/data/dataEmailMessages.php @@ -0,0 +1,189 @@ + + * @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 + * @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 index 0000000..9e7776a --- /dev/null +++ b/models/admin/messages/index.php @@ -0,0 +1,157 @@ + + * @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 '
' . print_r( $messages, true ) . '
'; + $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 '
$_REQUEST: ' . print_r( $_REQUEST, true) . '
'; + $_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 '
' . print_r( $message, true) . '
'; + } + 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 + ); + + } + + +} diff --git a/setup/adminMenus.php b/setup/adminMenus.php index 916b834..4cf1858 100644 --- a/setup/adminMenus.php +++ b/setup/adminMenus.php @@ -50,3 +50,23 @@ * */ +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', +// '    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 index 0000000..06b81db --- /dev/null +++ b/setup/databaseScripts/create_database_V0.0.1.sql @@ -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 index 0000000..110fc98 --- /dev/null +++ b/setup/databaseScripts/dbVersions.php @@ -0,0 +1,19 @@ + + * @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'), +); + diff --git a/setup/validActions.php b/setup/validActions.php index 89b3787..159fa20 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -59,9 +59,12 @@ $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 index 0000000..6029dc1 --- /dev/null +++ b/views/admin/footer.html @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/views/admin/header.html b/views/admin/header.html new file mode 100644 index 0000000..b4a464d --- /dev/null +++ b/views/admin/header.html @@ -0,0 +1,5 @@ +
+ + {* Navigation *} + +
diff --git a/views/admin/messages/editHtmlEmail.html b/views/admin/messages/editHtmlEmail.html new file mode 100644 index 0000000..5df0869 --- /dev/null +++ b/views/admin/messages/editHtmlEmail.html @@ -0,0 +1,91 @@ +

Html Email

+{include file='admin/header.html'} + +
+ + {if !$newEntry} + + {/if} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
From Name: + +
From Email: + +
Reply To: + +
Subject: + +
Message Content: + {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) + )} +
+ Merge Tags +

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.

+

+ + + + + + + + + + + + + +
{literal}{$member.name}{/literal}Member Name
{literal}{$contact.fname}{/literal}Contact First Name
{literal}{$contact.lname}{/literal}Contact Last Name
+ + +

+
+ +
+ +
+ +{include file='admin/footer.html'} diff --git a/views/admin/messages/index.html b/views/admin/messages/index.html new file mode 100644 index 0000000..0776592 --- /dev/null +++ b/views/admin/messages/index.html @@ -0,0 +1,24 @@ +

Messages Dashboard

+ +{include file='admin/header.html'} + +HTML Messages +Add HTML Email + +This is your dashboard + +
+ +{* + + + + +*} + +{include file='admin/footer.html'} diff --git a/views/admin/messages/list.html b/views/admin/messages/list.html new file mode 100644 index 0000000..337ec76 --- /dev/null +++ b/views/admin/messages/list.html @@ -0,0 +1,29 @@ +

List Messages

+{include file='admin/header.html'} + + + + + + + + + + + + + {if $messages} + {foreach $messages as $message} + + + + + + + + {/foreach} + {/if} + +
IDSubjectLast UpdatedSentStats
{$message.id} {$message.subject} {$message.last_updated.timestamp|date_format}
+ +{include file='admin/footer.html'} -- 2.17.1