From e0ff7da40a1f16ab75b64fb33be774a9eb8e9434 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Wed, 16 Aug 2017 10:33:26 -0400 Subject: [PATCH] moving the to and from email addresses, adding declined and approved event email messages adding section in mgmt for approved and declined email messages, moving the to and from email addresses out of mgmt and into the settings section with messages. added some styles to the admin section. Fixed the front end submission form to use the new email sections. updated the database scripts and database versions file, the plugin version and db version. Added tab , model , action and view to the events plugin for the new email notification settings table --- classes/data/dataEmailNotifications.php | 178 ++++++++++++++++++ css/admin.css | 28 ++- index.php | 12 +- models/admin/events/list.php | 22 +-- models/admin/settings/emailNotifications.php | 163 ++++++++++++++++ models/front/events/frontAdd.php | 25 ++- setup/adminTabs.php | 15 ++ ..._V0.1.2.sql => create_database_V0.1.3.sql} | 23 ++- setup/databaseScripts/dbVersions.php | 1 + .../update_database_V0.1.3.sql | 26 +++ setup/validActions.php | 1 + views/admin/events/edit.html | 52 ++--- views/admin/settings/emailNotifications.html | 59 ++++++ 13 files changed, 544 insertions(+), 61 deletions(-) create mode 100644 classes/data/dataEmailNotifications.php create mode 100644 models/admin/settings/emailNotifications.php rename setup/databaseScripts/{create_database_V0.1.2.sql => create_database_V0.1.3.sql} (95%) create mode 100644 setup/databaseScripts/update_database_V0.1.3.sql create mode 100644 views/admin/settings/emailNotifications.html diff --git a/classes/data/dataEmailNotifications.php b/classes/data/dataEmailNotifications.php new file mode 100644 index 0000000..cf8d99a --- /dev/null +++ b/classes/data/dataEmailNotifications.php @@ -0,0 +1,178 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataEvents.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + */ + +/** + * GlmDataEvent 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 GlmDataEmailNotifications 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_EVENTS_PLUGIN_DB_PREFIX . 'email_notifications'; + + /* + * Table Data Fields + */ + + $this->fields = array ( + + 'id' => array ( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a' + ), + + // Event Declined Message + 'declined_message' => array( + 'field' => 'declined_message', + 'type' => 'text', + 'required' => false, + 'use' => 'a' + ), + // Event Declined Message + 'approved_message' => array( + 'field' => 'approved_message', + 'type' => 'text', + 'required' => false, + 'use' => 'a' + ), + // To Email address + 'to_email' => array( + 'field' => 'to_email', + 'type' => 'text', + 'required' => false, + 'use' => 'a' + ), + // From Email Address + 'from_email' => array( + 'field' => 'from_email', + 'type' => 'text', + 'required' => false, + '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/css/admin.css b/css/admin.css index f8dbf91..bb74c62 100644 --- a/css/admin.css +++ b/css/admin.css @@ -5,7 +5,7 @@ and open the template in the editor. */ /* Created on : 15-Feb-2016, 1:53:23 PM - Author : anthony + Author : Gaslight Media */ #occurrences{ display: none; @@ -24,12 +24,28 @@ and open the template in the editor. #startTime, #startDate,#endDate, #endTime{ width: 15%; } -//#endDate, #endTime{ -// width: 15%; -//} + #timeZone{ width: 25%; } -.titles{ - + +/* + Email Notification Settings +*/ +.email-notification-label{ + font-weight: bold; + padding: 0; +} + +@media(min-width: 640px){ + .email-notification-label:not(.email-address-label){ + margin-top: 30px; + } + .email-address-label{ + margin-top: 5px; + } +} +.email-notification-editor{ + padding: 0; + margin-bottom: 25px; } \ No newline at end of file diff --git a/index.php b/index.php index 2100314..c2986d3 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,9 @@ * Plugin Name: GLM Members Database Events * Plugin URI: http://www.gaslightmedia.com/ * Description: Gaslight Media Members Database. - * Version: 1.6.57 + + * Version: 1.6.58 + * Author: Chuck Scott * Author URI: http://www.gaslightmedia.com/ * License: GPL2 @@ -19,7 +21,9 @@ * @package glmMembersDatabaseEventsAddOn * @author Chuck Scott * @license http://www.gaslightmedia.com Gaslightmedia - * @version 1.6.57 + + * @version 1.6.58 + */ // Check that we're being called by WordPress. @@ -43,8 +47,8 @@ if (!defined('ABSPATH')) { * so that we're sure the other add-ons see an up to date * version from this plugin. */ -define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.6.57'); -define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.1.2'); +define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.6.58'); +define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.1.3'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_EVENTS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.9.15'); diff --git a/models/admin/events/list.php b/models/admin/events/list.php index c8e367f..1b6b7d1 100644 --- a/models/admin/events/list.php +++ b/models/admin/events/list.php @@ -894,8 +894,9 @@ class GlmMembersAdmin_events_list extends GlmDataEvents } // DECLINED & APPROVED EVENT EMAIL FUNCTIONALITY /////// - $sql = "SELECT from_email FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "management"; - $from_email = $this->wpdb->get_var($sql); + $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "email_notifications"; + $email_notifications = !empty($this->wpdb->get_results($sql, ARRAY_A)) ? $this->wpdb->get_results($sql, ARRAY_A)[0] : false; + $from_email = $email_notifications ? $email_notifications['from_email'] : false; // echo '
', print_r($event), '
'; $to_email = (isset($event['fieldData']['admin_email']) ? $event['fieldData']['admin_email'] : '' ); @@ -924,7 +925,7 @@ class GlmMembersAdmin_events_list extends GlmDataEvents // Send confirmation email, set the content type to allow html by using this filter add_filter( 'wp_mail_content_type', 'set_content_type' ); - $declined_msg = ''; + $declined = ''; $current_status = $event['fieldData']['status']['value']; if($to_email){ @@ -933,23 +934,16 @@ class GlmMembersAdmin_events_list extends GlmDataEvents $message .= "Event Description: $event_intro
"; $message .= "Contact Name: $admin_name

"; + if( $old_event_status === '20' && $current_status === '10' ) { - $subject = 'Event Approved'; - - $message .= 'Your event has been approved'; + $message .= $email_notifications['approved_message']; wp_mail( $to_email, $subject, $message, $header ); } else if( $old_event_status === '20' && $current_status === '40' ){ - - // $event_notes = (isset($event['fieldData']['notes']) ? filter_var($event['fieldData']['notes'], FILTER_SANITIZE_STRING) : '' ); - // $offset = "DENIED REASON:"; - // $declined_msg = substr($event_notes, strpos($event_notes, 'DENIED REASON:') + strlen($offset)); - $declined_msg = (isset($_REQUEST['deniedText']) ? filter_var(($_REQUEST['deniedText']), FILTER_SANITIZE_STRING) : '' ); - + $declined = $email_notifications['declined_message']; $subject = 'Event Declined'; - $message .= "Your event has been declined for the following reason(s): $declined_msg"; - + $message .= "Your event has been declined for the following reason(s):
$declined"; wp_mail( $to_email, $subject, $message, $header ); } } diff --git a/models/admin/settings/emailNotifications.php b/models/admin/settings/emailNotifications.php new file mode 100644 index 0000000..fb2b854 --- /dev/null +++ b/models/admin/settings/emailNotifications.php @@ -0,0 +1,163 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +// Load Event Categories data abstract +require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataEmailNotifications.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_emailNotifications extends GlmDataEmailNotifications +{ + + /** + * 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 controller 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; + $error = false; + $enable_members = $this->config['settings']['enable_members']; + $email_settings = false; + + $email_settings = $this->getSettings(); + + // If there's an action option + if (isset($_REQUEST['option'])) { + + switch($_REQUEST['option']) { + + case 'update': + $this->updateEntry($email_settings['id']); + + break; + case 'new': + $this->insertEntry(); + break; + } + + } + + $email_settings = $this->getSettings(); + // 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 + ); + } + + + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { + glmMembersAdmin::addNotice($categories, 'DataBlock', 'Categories Data'); + } + + // Compile template data + $templateData = array( + 'enable_members' => $enable_members, + 'email_settings' => $email_settings + ); + + // Return status, suggested view, and data to controller + return array( + 'status' => $success, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/settings/emailNotifications.html', + 'data' => $templateData + ); + + } + private function getSettings(){ + $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'email_notifications'; + $email_settings = $this->wpdb->get_results($sql, ARRAY_A); + return !empty($email_settings) ? $email_settings[0] : false; + } + +} diff --git a/models/front/events/frontAdd.php b/models/front/events/frontAdd.php index 2b58013..2925b5f 100644 --- a/models/front/events/frontAdd.php +++ b/models/front/events/frontAdd.php @@ -336,7 +336,7 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents $admin_name = $this->filterInput( $_REQUEST['admin_name'] ); $admin_org = $this->filterInput( $_REQUEST['admin_org'] ); $adminPhone = $this->filterInput( $_REQUEST['admin_phone'] ); - $adminEmail = $this->filterInput( $_REQUEST['admin_email'] ); + $userEmail = $this->filterInput( $_REQUEST['admin_email'] ); $contactFirst = $this->filterInput( $_REQUEST['contact_fname'] ); $contactLast = $this->filterInput( $_REQUEST['contact_lname'] ); $place = $this->filterInput( $_REQUEST['place'] ); @@ -457,7 +457,7 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents 'contact_phone' => $contactPhone, 'admin_name' => $admin_name, 'admin_phone' => $adminPhone, - 'admin_email' => $adminEmail, + 'admin_email' => $userEmail, 'contact_name' => $contactFirst . " " . $contactLast, 'contact_email' => $contactEmail, 'admin_org' => $admin_org @@ -661,26 +661,31 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents // $siteName = get_bloginfo('name'); // return $siteName; // } -// // Send confirmation email, set the content type to allow html by using this filter +// +// // Send confirmation email to the admin, set the content type to allow html by using this filter + $sql = "SELECT to_email, from_email FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "email_notifications"; + $email_addresses = $this->wpdb->get_results($sql, ARRAY_A)[0]; + add_filter( 'wp_mail_content_type', 'set_content_type' ); $site_name = get_bloginfo('name'); - $to = $to_email; + $adminEmail = $email_addresses['to_email']; + $fromEmail = $email_addresses['from_email']; $subject = 'Event Form Submission'; $message = $htmlMessage; $userBody = $userMessage; $header[] = "From: $site_name <$fromEmail>"; - $header[] = 'Reply-To:' . $adminEmail; - - wp_mail($to, $subject, $message, $header); - + $header[] = 'Reply-To:' . $userEmail; + + wp_mail($adminEmail, $subject, $message, $header); + // send a copy to the user submitting the email, using different headers and email template file $userHeader[] = "From: $site_name <$fromEmail>"; $userHeader[] = 'Reply-To: No-Reply@gaslightmedia.com'; - - if(wp_mail($adminEmail, $subject, $userBody, $userHeader)){ + + if(wp_mail($userEmail, $subject, $userBody, $userHeader)){ } else { echo "Error: Message Not Sent"; diff --git a/setup/adminTabs.php b/setup/adminTabs.php index 72639e8..c233465 100644 --- a/setup/adminTabs.php +++ b/setup/adminTabs.php @@ -66,6 +66,21 @@ if (current_user_can('glm_members_members')) { return $addOnTabs; } ); + add_filter('glm-member-db-add-tab-for-settings', + function($addOnTabs) { + $newTabs = array( + array( + 'text' => 'Event Email Settings', + 'menu' => 'settings', + 'action' => 'emailNotifications' + ), + + ); + $addOnTabs = array_merge($addOnTabs, $newTabs); + return $addOnTabs; + } + ); + add_filter('glm-member-db-add-tab-for-settings', function($addOnTabs) { diff --git a/setup/databaseScripts/create_database_V0.1.2.sql b/setup/databaseScripts/create_database_V0.1.3.sql similarity index 95% rename from setup/databaseScripts/create_database_V0.1.2.sql rename to setup/databaseScripts/create_database_V0.1.3.sql index 3933da2..9272415 100644 --- a/setup/databaseScripts/create_database_V0.1.2.sql +++ b/setup/databaseScripts/create_database_V0.1.3.sql @@ -1,6 +1,6 @@ -- Gaslight Media Members Database - Events Add-On -- File Created: 12/02/15 15:27:15 --- Database Version: 0.1.2 +-- Database Version: 0.1.3 -- Database Creation Script -- -- This file is called to create a new set of tables for this @@ -251,3 +251,24 @@ CREATE TABLE {prefix}feed_import ( events INT NULL, -- The number of events last fetched PRIMARY KEY (id) ); + +---- + +-- Event Email Notifications +CREATE TABLE {prefix}email_notifications ( + id INT NOT NULL AUTO_INCREMENT, + declined_message TEXT NULL, -- Event declined message + approved_message TEXT NULL, -- Event approved message + to_email TINYTEXT NULL, -- To Email Address + from_email TINYTEXT NULL, -- From Email Address + PRIMARY KEY (id) +); + +---- + +-- Set default event email settings +INSERT INTO {prefix}email_notifications + ( id, declined_message, approved_message ) + VALUES + ( 1, 'The Event parameters do not comply with our event guidelines.', 'Your event has been approved.' ) +; \ No newline at end of file diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 2113693..5dad38c 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -38,5 +38,6 @@ $glmMembersEventsDbVersions = array( '0.1.0' => array('version' => '0.1.0', 'tables' => 12, 'date' => '10/20/2016'), '0.1.1' => array('version' => '0.1.1', 'tables' => 12, 'date' => '11/02/2016'), '0.1.2' => array('version' => '0.1.2', 'tables' => 12, 'date' => '05/03/2017'), + '0.1.3' => array('version' => '0.1.3', 'tables' => 13, 'date' => '08/14/2017'), ); diff --git a/setup/databaseScripts/update_database_V0.1.3.sql b/setup/databaseScripts/update_database_V0.1.3.sql new file mode 100644 index 0000000..351ea8f --- /dev/null +++ b/setup/databaseScripts/update_database_V0.1.3.sql @@ -0,0 +1,26 @@ +-- Gaslight Media Members Database - Events Add-On +-- File Created: 2017-08-04 +-- Database Version: 0.1.3 +-- 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 dashes + +-- Event Email Notifications +CREATE TABLE {prefix}email_notifications ( + id INT NOT NULL AUTO_INCREMENT, + declined_message TEXT NULL, -- Event declined message + approved_message TEXT NULL, -- Event approved message + to_email TINYTEXT NULL, -- To Email Address + from_email TINYTEXT NULL, -- From Email Address + PRIMARY KEY (id) +); + +---- + +-- Set default event email settings +INSERT INTO {prefix}email_notifications + ( id, declined_message, approved_message ) + VALUES + ( 1, 'The Event parameters do not comply with our event guidelines.', 'Your event has been approved.' ) +; \ No newline at end of file diff --git a/setup/validActions.php b/setup/validActions.php index c86818c..2ff7c24 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -53,6 +53,7 @@ $glmMembersEventsAddOnValidActions = array( 'settings' => array( 'eventCategories' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG, 'eventAmenities' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG, + 'emailNotifications' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG, ), 'management' => array( 'events' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG diff --git a/views/admin/events/edit.html b/views/admin/events/edit.html index 23d32ca..60858d5 100644 --- a/views/admin/events/edit.html +++ b/views/admin/events/edit.html @@ -1330,32 +1330,32 @@ }); // declined event dialog - (function(){ - var notes = $('[name="notes"'); - var reason = $("#deniedText"); - - $('[name="status"]').on("change", function(){ - var status = $(this).val(); - if(status === '40'){ - $("#deniedReason").dialog("open"); - } - }); - $("#deniedReasonSubmit").on("click", function(){ - - var reason_text = reason.val(); - - if(reason_text){ - $("#deniedReason").dialog("close"); - var content = " DENIED REASON: " + reason_text; - var current_notes = notes.val(); - notes.append(" DENIED REASON: " + reason_text); - notes.val(current_notes + content); - $('#declinedMsg').val(reason_text); - } else { - reason.next().css("display", "block"); - } - }); - })(); +// (function(){ +// var notes = $('[name="notes"'); +// var reason = $("#deniedText"); +// +// $('[name="status"]').on("change", function(){ +// var status = $(this).val(); +// if(status === '40'){ +// $("#deniedReason").dialog("open"); +// } +// }); +// $("#deniedReasonSubmit").on("click", function(){ +// +// var reason_text = reason.val(); +// +// if(reason_text){ +// $("#deniedReason").dialog("close"); +// var content = " DENIED REASON: " + reason_text; +// var current_notes = notes.val(); +// notes.append(" DENIED REASON: " + reason_text); +// notes.val(current_notes + content); +// $('#declinedMsg').val(reason_text); +// } else { +// reason.next().css("display", "block"); +// } +// }); +// })(); }); diff --git a/views/admin/settings/emailNotifications.html b/views/admin/settings/emailNotifications.html new file mode 100644 index 0000000..6650e14 --- /dev/null +++ b/views/admin/settings/emailNotifications.html @@ -0,0 +1,59 @@ +{include file='admin/settings/header.html'} + + +
+ + {if $email_settings} + + {else if} + + {/if} +
+ + +
+
+ + +
+
+ + + + +
+ +
+ + +{include file='admin/footer.html'} -- 2.17.1