From a03c5d4d7944367a7c49bfff4181eb20777ac096 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 5 Jun 2019 11:24:58 -0400 Subject: [PATCH] Updates for message plugin push for review of grid --- classes/data/dataEmailMessages.php | 19 +++ classes/data/dataEmailTemplates.php | 161 ++++++++++++++++++ index.php | 2 +- models/admin/messages/index.php | 151 +++++++--------- .../create_database_V0.0.2.sql | 14 ++ setup/databaseScripts/dbVersions.php | 1 + .../update_database_V0.0.3.sql | 35 ++++ views/admin/header.html | 6 +- views/admin/messages/editHtmlEmail.html | 17 ++ views/admin/messages/editTemplate.html | 55 ++++++ views/admin/messages/index.html | 55 +++--- views/admin/messages/list.html | 25 +-- views/admin/messages/listMessagesTable.html | 24 +++ views/admin/messages/listTemplates.html | 23 +++ views/admin/messages/search.html | 2 +- 15 files changed, 441 insertions(+), 149 deletions(-) create mode 100644 classes/data/dataEmailTemplates.php create mode 100644 setup/databaseScripts/update_database_V0.0.3.sql create mode 100644 views/admin/messages/editTemplate.html create mode 100644 views/admin/messages/listMessagesTable.html create mode 100644 views/admin/messages/listTemplates.html diff --git a/classes/data/dataEmailMessages.php b/classes/data/dataEmailMessages.php index 86291dd..1913c2d 100644 --- a/classes/data/dataEmailMessages.php +++ b/classes/data/dataEmailMessages.php @@ -118,6 +118,25 @@ class GlmDataEmailMessages extends GlmDataAbstract 'use' => 'a' ), + // Has no map data + 'archived' => array( + 'field' => 'archived', + 'type' => 'checkbox', + 'use' => 'a', + ), + + // Member Type + 'template_id' => array ( + 'field' => 'template_id', + 'type' => 'pointer', + 'p_table' => GLM_MEMBERS_MESSAGES_PLUGIN_DB_PREFIX . 'email_templates', + 'p_field' => 'name', + 'p_orderby' => 'name', + 'required' => true, + 'force_list' => true, + 'use' => 'a' + ), + // Name 'from_email' => array ( 'field' => 'from_email', diff --git a/classes/data/dataEmailTemplates.php b/classes/data/dataEmailTemplates.php new file mode 100644 index 0000000..43b4fd3 --- /dev/null +++ b/classes/data/dataEmailTemplates.php @@ -0,0 +1,161 @@ + + * @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 GlmDataEmailTemplates 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; + + public $postStats = false; + public $postSent = 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_templates'; + + /* + * Table Data Fields + */ + + $this->fields = array ( + + 'id' => array ( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a' + ), + + // Name + 'name' => array ( + 'field' => 'name', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + + // Contacts + 'contents' => array ( + 'field' => 'contents', + '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/index.php b/index.php index d0e47bf..b244b59 100644 --- a/index.php +++ b/index.php @@ -44,7 +44,7 @@ if (!defined('ABSPATH')) { * version from this plugin. */ define('GLM_MEMBERS_MESSAGES_PLUGIN_VERSION', '0.0.1'); -define('GLM_MEMBERS_MESSAGES_PLUGIN_DB_VERSION', '0.0.2'); +define('GLM_MEMBERS_MESSAGES_PLUGIN_DB_VERSION', '0.0.3'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_MESSAGES_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0'); diff --git a/models/admin/messages/index.php b/models/admin/messages/index.php index b7c00f6..62c0311 100644 --- a/models/admin/messages/index.php +++ b/models/admin/messages/index.php @@ -15,6 +15,7 @@ // Load Members data abstract require_once GLM_MEMBERS_MESSAGES_PLUGIN_CLASS_PATH.'/data/dataEmailMessages.php'; +require_once GLM_MEMBERS_MESSAGES_PLUGIN_CLASS_PATH.'/data/dataEmailTemplates.php'; /* * This class performs the work for the default action of the "Members" menu @@ -116,6 +117,8 @@ class GlmMembersAdmin_messages_index extends GlmDataEmailMessages 'thisOption' => $option, ); + wp_enqueue_style( 'glmaFoundation', GLM_MEMBERS_PLUGIN_URL . '/css/glma-foundation.min.css' ); + switch ( $option ) { case 'search': // echo '
$this->config: ' . print_r( $this->config, true ) . '
'; @@ -251,7 +254,8 @@ class GlmMembersAdmin_messages_index extends GlmDataEmailMessages $searchResults = $Members->getSimpleMemberInfoList( $where ); // echo '
$searchResults: ' . print_r( $searchResults, true ) . '
'; - $messages = $this->getList(); + $where = "T.archived <> true"; + $messages = $this->getList( $where ); if ( $option2 === 'sendMessages' && isset( $_REQUEST['message_id'] ) && $messageId = filter_var( $_REQUEST['message_id'], FILTER_VALIDATE_INT ) ) { $this->sendHtmlMessages( $searchResults, $messageId ); @@ -270,19 +274,43 @@ class GlmMembersAdmin_messages_index extends GlmDataEmailMessages ); break; - case 'list': - $view = 'list'; - $this->postStats = true; - $this->postSent = true; - $messages = $this->getList(); - $this->postStats = false; - $this->postSent = false; - // echo '
$messages: ' . print_r( $messages, true ) . '
'; + case 'listTemplates': + $view = 'listTemplates'; + $Templates = new GlmDataEmailTemplates( $this->wpdb, $this->config ); + $templates = $Templates->getList(); $tData = array( - 'messages' => $messages, + 'templates' => $templates, + ); + break; + + case 'editTemplate': + $view = 'editTemplate'; + $newEntry = false; + $Templates = new GlmDataEmailTemplates( $this->wpdb, $this->config ); + if ( isset( $_REQUEST['id'] ) && $id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) { + $template = $Templates->editEntry( $id ); + } else { + $template = $Templates->newEntry(); + $newEntry = true; + } + $tData = array( + 'template' => $template, + 'newEntry' => $newEntry, ); break; + case 'updateTemplate': + echo '
'.print_r($_REQUEST, true).'
'; + $Templates = new GlmDataEmailTemplates( $this->wpdb, $this->config ); + if ( isset( $_REQUEST['id'] ) && $id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) { + $message = $Templates->updateEntry( $id ); + } else { + $message = $Templates->insertEntry(); + } + break; + + + case 'editHtmlEmail': $view = 'editHtmlEmail'; $newEntry = false; @@ -307,7 +335,18 @@ class GlmMembersAdmin_messages_index extends GlmDataEmailMessages } break; + case 'list': + $view = 'list'; default: + $where = "T.archived <> true"; + $this->postStats = true; + $this->postSent = true; + $messages = $this->getList( $where ); + $this->postStats = false; + $this->postSent = false; + $tData = array( + 'messages' => $messages, + ); break; } @@ -338,6 +377,7 @@ class GlmMembersAdmin_messages_index extends GlmDataEmailMessages // echo '
$data: ' . print_r( $data, true ) . '
'; $message = $this->getEntry( $messageId ); // echo '
$message: ' . print_r( $message, true ) . '
'; + // exit; $fromEmail = $message['from_email']; $fromName = $message['from_name']; $replyToEmail = $message['reply_to_email']; @@ -367,7 +407,7 @@ class GlmMembersAdmin_messages_index extends GlmDataEmailMessages 'lname' => $contact['lname'], ) ); - $messageBody = $this->generateHTML( $emailData, $message['message_body'], true ); + $messageBody = $this->generateHTML( $emailData, $message['message_body'], $message['template_id']['value'] ); // Add this to the email_queue $this->wpdb->insert( @@ -417,7 +457,7 @@ class GlmMembersAdmin_messages_index extends GlmDataEmailMessages * @access public * @return void */ - function generateHTML( $data, $view, $viewIsString = false ) + function generateHTML( $data, $view, $template ) { // Load Smarty Template support @@ -433,93 +473,16 @@ class GlmMembersAdmin_messages_index extends GlmDataEmailMessages } } + $contents = $smarty->template->fetch( 'eval:' . $view ); - // If is supplied as a string - if ( $viewIsString ) { - - $out = $smarty->template->fetch( 'eval:' . $view ); - - // Otherwise $view is a file name - } else { - - // Get the specified view file - check theme first - $viewPath = GLM_MEMBERS_PLUGIN_CURRENT_THEME_DIR . '/views'; - $viewPath2 = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH . 'views'; // Save default + $Templates = new GlmDataEmailTemplates( $this->wpdb, $this->config ); + $template = $Templates->getEntry( $template ); - // If the view is not found in the theme, fall back to views in the plugin - if ( !is_file( $viewPath . '/' . $view ) ) { - - // Next try the plugin/add-on - $viewPath = GLM_MEMBERS_REGISTRATIONS_PLUGIN_PATH . "/views"; - - if ( !is_file( $viewPath . '/' . $view ) ) { - - if ( GLM_MEMBERS_PLUGIN_FRONT_DEBUG ) { - trigger_error( "Bad or missing view file when generating checkout HTML: $viewPath/$view", E_USER_NOTICE ); - } - - } - - } - - // Update the Smarty view path - $smarty->template->setTemplateDir( $viewPath ); - - // If the view path doesn't match the default, add the default (using theme view) - if ( $viewPath2 != $viewPath ) { - $smarty->template->addTemplateDir( $viewPath2 ); - } - - // Generate output from model data and view - $out = $smarty->template->fetch( $view ); - - } + $smarty->templateAssign( 'contents', $contents ); + $out = $smarty->template->fetch( 'eval:' . $template['contents'] ); return $out; } - /** - * sendHtmlEmail - * - * Create html email and send using wp_mail. - * - * @param mixed $to To email address - * @param mixed $subject Subject line for the email - * @param mixed $htmlMessage Html message for the email - * - * @access public - * @return void - */ - public function sendHtmlEmail( $from, $to, $subject, $htmlMessage ) - { - - // Set the From name using this wordpress hook. - add_filter( - 'wp_mail_from_name', - function ( $name ) { - return $this->config['settings']['reg_org_name']; - } - ); - // Send confirmation email, set the content type to allow html by using this filter - add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) ); - - - $message = $htmlMessage; - $header[] = 'From:' . $fromAddress; - $header[] = 'Reply-To:' . $this->config['settings']['reg_org_from_email']; - - wp_mail( $to, $subject, $message, $header ); - - } - - /** - * Set content type of the email. - * - * Used as filter for the wp_mail_content_type - */ - function set_content_type() - { - return 'text/html'; - } } diff --git a/setup/databaseScripts/create_database_V0.0.2.sql b/setup/databaseScripts/create_database_V0.0.2.sql index 0877c84..b60e3f0 100644 --- a/setup/databaseScripts/create_database_V0.0.2.sql +++ b/setup/databaseScripts/create_database_V0.0.2.sql @@ -9,6 +9,8 @@ -- email_messages CREATE TABLE {prefix}email_messages ( id INT NOT NULL AUTO_INCREMENT, + template_id INT NOT NULL, + archived BOOLEAN DEFAULT false, from_email TINYTEXT NOT NULL, from_name TINYTEXT NULL, reply_to_email TINYTEXT NULL, @@ -30,6 +32,8 @@ CREATE TABLE {prefix}email_logs ( reply_to_email TINYTEXT NULL, message_body TEXT NOT NULL, send_date DATETIME NOT NULL, + email_read BOOLEAN DEFAULT false, + read_date DATETIME NULL, PRIMARY KEY (id) ); @@ -48,3 +52,13 @@ CREATE TABLE {prefix}email_queue ( processed BOOLEAN DEFAULT false, PRIMARY KEY (id) ); + +---- + +-- Template +CREATE TABLE {prefix}email_templates ( + id INT NOT NULL AUTO_INCREMENT, + name TEXT NOT NULL, + contents TEXT NOT NULL, + PRIMARY KEY (id) +); diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index e6b41c1..e918016 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -16,5 +16,6 @@ $glmMembersMessagesDbVersions = array( '0.0.1' => array('version' => '0.0.1', 'tables' => 2, 'date' => '05/24/2019'), '0.0.2' => array('version' => '0.0.2', 'tables' => 3, 'date' => '05/30/2019'), + '0.0.3' => array('version' => '0.0.3', 'tables' => 4, 'date' => '06/04/2019'), ); diff --git a/setup/databaseScripts/update_database_V0.0.3.sql b/setup/databaseScripts/update_database_V0.0.3.sql new file mode 100644 index 0000000..94036ec --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.3.sql @@ -0,0 +1,35 @@ +-- Gaslight Media Members Database - Messages Add-On +-- File Created: 5/30/2019 +-- Database Version: 0.0.2 +-- Database Update From Previous Version Script +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashses + +-- Add template_id to messages +ALTER TABLE {prefix}email_messages ADD COLUMN template_id INT NOT NULL; + +---- + +-- Add archived to messages +ALTER TABLE {prefix}email_messages ADD COLUMN archived BOOLEAN DEFAULT false; + +---- + +-- Add email_read to log table +ALTER TABLE {prefix}email_logs ADD COLUMN email_read BOOLEAN DEFAULT false; + +---- + +-- Add read_date to log table +ALTER TABLE {prefix}email_logs ADD COLUMN read_date DATETIME NULL; + +---- + +-- Template +CREATE TABLE {prefix}email_templates ( + id INT NOT NULL AUTO_INCREMENT, + name TEXT NOT NULL, + contents TEXT NOT NULL, + PRIMARY KEY (id) +); diff --git a/views/admin/header.html b/views/admin/header.html index 60c9db5..3be4b60 100644 --- a/views/admin/header.html +++ b/views/admin/header.html @@ -4,8 +4,8 @@ -
+
diff --git a/views/admin/messages/editHtmlEmail.html b/views/admin/messages/editHtmlEmail.html index f9d0568..9819125 100644 --- a/views/admin/messages/editHtmlEmail.html +++ b/views/admin/messages/editHtmlEmail.html @@ -9,6 +9,23 @@ + + + + + + + +
+ Archived +
Template + + {if $message.fieldFail.template_id}

{$message.fieldFail.template_id}

{/if} +
From Name: diff --git a/views/admin/messages/editTemplate.html b/views/admin/messages/editTemplate.html new file mode 100644 index 0000000..66771f1 --- /dev/null +++ b/views/admin/messages/editTemplate.html @@ -0,0 +1,55 @@ +

Html Email

+{include file='admin/header.html'} + +
+ + {if !$newEntry} + + {/if} + + + + + + + + + + + + + + + + + + + + +
Name: + +
Content: + {if $template} + {$textAreaContent = $template.fieldData.contents} + {else} + {$textAreaContent = ''} + {/if} + {wp_editor( + $textAreaContent, + 'contents', + json_decode('{ + "media_buttons": true, + "quicktags": false, + "textarea_name": "contents", + "editor_height": 250 + }', true) + )} +
+

Place {literal}{$contents}{/literal} where you want the Email Message to be inserted to.

+
+ +
+ +
+ +{include file='admin/footer.html'} diff --git a/views/admin/messages/index.html b/views/admin/messages/index.html index e4300c7..972ac5c 100644 --- a/views/admin/messages/index.html +++ b/views/admin/messages/index.html @@ -2,32 +2,35 @@ {include file='admin/header.html'} - +
+
+
+ + + + + + + +
+ + + +
+
+
+
+
+ + +
+
+
-This is your dashboard - -
- -{* React Part - - - - -*} +{include file='admin/messages/listMessagesTable.html'} {include file='admin/footer.html'} diff --git a/views/admin/messages/list.html b/views/admin/messages/list.html index 12d34eb..afface5 100644 --- a/views/admin/messages/list.html +++ b/views/admin/messages/list.html @@ -1,29 +1,6 @@

List Messages

{include file='admin/header.html'} - - - - - - - - - - - - {if $messages} - {foreach $messages as $message} - - - - - - - - {/foreach} - {/if} - -
IDSubjectLast UpdatedLast SentQueued
{$message.id} {$message.subject} {$message.last_updated.timestamp|date_format:"%D %r"} {$message.sent|date_format:"%D %r"} {$message.stats|date_format:"%D %r"}
+{include file='admin/messages/listMessagesTable.html'} {include file='admin/footer.html'} diff --git a/views/admin/messages/listMessagesTable.html b/views/admin/messages/listMessagesTable.html new file mode 100644 index 0000000..4a264ef --- /dev/null +++ b/views/admin/messages/listMessagesTable.html @@ -0,0 +1,24 @@ + + + + + + + + + + + + {if $messages} + {foreach $messages as $message} + + + + + + + + {/foreach} + {/if} + +
IDSubjectLast UpdatedLast SentQueued
{$message.id} {$message.subject} {$message.last_updated.timestamp|date_format:"%D %r"} {$message.sent|date_format:"%D %r"} {$message.stats|date_format:"%D %r"}
diff --git a/views/admin/messages/listTemplates.html b/views/admin/messages/listTemplates.html new file mode 100644 index 0000000..7aafa62 --- /dev/null +++ b/views/admin/messages/listTemplates.html @@ -0,0 +1,23 @@ +

List Messages

+{include file='admin/header.html'} + + + + + + + + + + {if $templates} + {foreach $templates as $template} + + + + + {/foreach} + {/if} + +
IDName
{$template.id} {$template.name}
+ +{include file='admin/footer.html'} diff --git a/views/admin/messages/search.html b/views/admin/messages/search.html index 95084bd..1b8e624 100644 --- a/views/admin/messages/search.html +++ b/views/admin/messages/search.html @@ -122,7 +122,7 @@ {/if} {if $searchResults} - +
-- 2.17.1
ID