From e09194bc1f0e61a2ccfc1db11ca7de66e3bfec33 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Tue, 31 May 2016 13:33:50 -0400 Subject: [PATCH] adding email notification management and html email formatting --- classes/data/dataManagement.php | 21 +++++ index.php | 2 +- models/admin/management/events.php | 3 +- models/front/events/frontAdd.php | 79 +++++++++++++++---- ...0.0.17.sql => create_database_V0.0.18.sql} | 3 + setup/databaseScripts/dbVersions.php | 3 +- .../update_database_V0.0.18.sql | 21 +++++ views/admin/management/events.html | 34 +++++++- views/front/events/ownerEmail.html | 14 ++++ 9 files changed, 161 insertions(+), 19 deletions(-) rename setup/databaseScripts/{create_database_V0.0.17.sql => create_database_V0.0.18.sql} (98%) create mode 100644 setup/databaseScripts/update_database_V0.0.18.sql create mode 100644 views/front/events/ownerEmail.html diff --git a/classes/data/dataManagement.php b/classes/data/dataManagement.php index 834d1e6..faa7fd1 100644 --- a/classes/data/dataManagement.php +++ b/classes/data/dataManagement.php @@ -143,6 +143,27 @@ class GlmDataEventsManagement extends GlmDataAbstract 'type' => 'text', 'required' => false, 'use' => 'a' + ), + // Recipient Email + 'to_email' => array( + 'field' => 'to_email', + 'type' => 'text', + 'required' => false, + 'use' => 'a' + ), + // Sender Email + 'from_email' => array( + 'field' => 'from_email', + 'type' => 'text', + 'required' => false, + 'use' => 'a' + ), + // Email Notification + 'email_notification' => array( + 'field' => 'email_notification', + 'type' => 'text', + 'required' => false, + 'use' => 'a' ) ); diff --git a/index.php b/index.php index 7c58c7d..87454b0 100644 --- a/index.php +++ b/index.php @@ -39,7 +39,7 @@ * version from this plugin. */ define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.0.1'); -define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.0.17'); +define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.0.18'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_EVENTS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '1.0.58'); diff --git a/models/admin/management/events.php b/models/admin/management/events.php index bf0990c..9570a50 100644 --- a/models/admin/management/events.php +++ b/models/admin/management/events.php @@ -191,7 +191,7 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement if (isset($_REQUEST['option'])) { $option = $_REQUEST['option']; } - + switch ($option) { case 'tests': @@ -316,7 +316,6 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement } else { $settingsUpdateError = true; } - break; // Default is to get the current settings and display the form diff --git a/models/front/events/frontAdd.php b/models/front/events/frontAdd.php index 1f31ca9..039e782 100644 --- a/models/front/events/frontAdd.php +++ b/models/front/events/frontAdd.php @@ -11,6 +11,7 @@ require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/data/dataCategories.php'; require_once GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/models/front/events/baseAction.php'; require_once GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php'; require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataRecurrences.php'; +require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataManagement.php'; /** * GLmMembersFront_event_fontAdd @@ -96,6 +97,24 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents $view = 'frontAdd'; // populate category dropdown $categories = new GlmDataEventsCategories($this->wpdb, $this->config); + $emailInfo = new GlmDataEventsManagement($this->wpdb, $this->config); + $emailInfo = $emailInfo->getEntry(1); + + // get and validate recipient email address, put into an array to pass to wp_mail + $toEmail = $emailInfo['to_email']; + $toEmail = explode(',', $toEmail); + foreach($toEmail as $email){ + $email = trim($email); +// $email = filter_var($email, FILTER_VALIDATE_EMAIL); + $to_email[] = $email; + } + + // get the sender's email address and validate it + $fromEmail = trim(filter_var($emailInfo['from_email'], FILTER_VALIDATE_EMAIL)); + + // get the email notification message + $emailNotification = $emailInfo['email_notification']; + $cats = $categories->getList(); foreach($cats as $cat){ $eventCategories[] = $cat; @@ -426,21 +445,50 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents ) ); + $smarty = new smartyTemplateSupport(); + + $eventsList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-events-index&glm_action=index"; + $viewPath = GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/views'; + $smarty->template->setTemplateDir($viewPath); + $smarty->templateAssign('eventUrlBase', get_bloginfo('url') . '/add-an-event/'); + $smarty->templateAssign('title', 'Events'); + $smarty->templateAssign('link', 'main_event_page_url'); + $smarty->templateAssign('description', 'Calendar of Events'); + $smarty->templateAssign('pubDate', date('r')); + $smarty->templateAssign('to_email', $to_email); + $smarty->templateAssign('from_email', $fromEmail); + $smarty->templateAssign('emailNotification', $emailNotification); + $smarty->templateAssign('pendingEvents', $eventsList); + + $eventsList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-events-index&glm_action=index"; + $smarty->templateAssign('items', $events); + + // Add standard parameters + require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php'; + + $viewFile = 'front/events/ownerEmail.html'; + + // Generate output from model data and view + $htmlMessage = $smarty->template->fetch($viewFile); + + function set_content_type(){ + return "text/html"; + } + // Send confirmation email, set the content type to allow html by using this filter + add_filter( 'wp_mail_content_type', 'set_content_type' ); + + $to = $to_email; + $subject = 'Event Form Submission'; + $message = $htmlMessage; + $headers = 'From:'. $fromEmail . "\r\n"; + + wp_mail($to, $subject, $message, $headers); - // Send confirmation email -// $to = 'anthony@localhost'; -// $subject = 'Event Form Submission'; -// $message = "Thank you for submitting your event! \r\n". "Event Name: " . $name . "\r\n" . -// "Scheduled for: " . $starting ; -// $headers = 'From: webmaster@example.com' . "\r\n" . -// 'Reply-To: webmaster@example.com' . "\r\n" . -// 'X-Mailer: PHP/' . phpversion(); -// -// mail($to, $subject, $message, $headers); - $view = 'confirmation'; - } - -// echo '
', print_r($cats), '
'; + // remove the filter to avoid conflicts + remove_filter( 'wp_mail_content_type', 'set_content_type' ); + + $view = 'confirmation'; + } // Compile template data $templateData = array( 'siteBaseUrl' => GLM_MEMBERS_EVENTS_SITE_BASE_URL, @@ -450,6 +498,9 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents 'event' => $newEvent, 'permalink' => $permalink, 'title' => $title, + 'to_email' => $to_email, + 'from_email' => $fromEmail, + 'notification'=> $emailNotification, 'mainImgUrl' => GLM_MEMBERS_PLUGIN_MEDIA_URL . '/images/large/' ); diff --git a/setup/databaseScripts/create_database_V0.0.17.sql b/setup/databaseScripts/create_database_V0.0.18.sql similarity index 98% rename from setup/databaseScripts/create_database_V0.0.17.sql rename to setup/databaseScripts/create_database_V0.0.18.sql index 89432a8..47dac5b 100644 --- a/setup/databaseScripts/create_database_V0.0.17.sql +++ b/setup/databaseScripts/create_database_V0.0.18.sql @@ -168,6 +168,9 @@ CREATE TABLE {prefix}management ( canonical_event_page TINYTEXT NULL, -- Canonical page slug for event detail pdf_logo TINYTEXT NULL, -- Image for the Top of the PDF footer_text TINYTEXT NULL, -- Image for the Top of the PDF + to_email TINYTEXT NULL, -- Email address of the recipient + from_email TINYTEXT NULL, -- Email address of the sender + email_notification TEXT NULL, -- Email notification message PRIMARY KEY (id) ); diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 212bf88..c2382c2 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -28,6 +28,7 @@ $glmMembersEventsDbVersions = array( '0.0.12' => array('version' => '0.0.12', 'tables' => 7), '0.0.15' => array('version' => '0.0.15', 'tables' => 7, 'date' => '4/11/2016'), '0.0.16' => array('version' => '0.0.16', 'tables' => 7, 'date' => '4/11/2016'), - '0.0.17' => array('version' => '0.0.17', 'tables' => 7, 'date' => '5/5/2016') + '0.0.17' => array('version' => '0.0.17', 'tables' => 7, 'date' => '5/5/2016'), + '0.0.18' => array('version' => '0.0.18', 'tables' => 7, 'date' => '5/26/2016') ); diff --git a/setup/databaseScripts/update_database_V0.0.18.sql b/setup/databaseScripts/update_database_V0.0.18.sql new file mode 100644 index 0000000..42ec184 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.18.sql @@ -0,0 +1,21 @@ +-- Gaslight Media Members Database - Events Add-On +-- File Created: 12/09/14 15:27:15 +-- Database Version: 0.0.18 +-- 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 recipient email address +ALTER TABLE {prefix}management ADD COLUMN to_email TINYTEXT; + +---- + +-- Add sender email address +ALTER TABLE {prefix}management ADD COLUMN from_email TINYTEXT; + +---- + +-- Add notification message +ALTER TABLE {prefix}management ADD COLUMN email_notification TEXT; diff --git a/views/admin/management/events.html b/views/admin/management/events.html index f51585b..d246464 100644 --- a/views/admin/management/events.html +++ b/views/admin/management/events.html @@ -13,7 +13,7 @@ {if $settingsUpdated}

Settings Updated

{/if} {if $settingsUpdateError}Settings Update Error{/if} -

Management Settings

+

Management Settings

@@ -50,6 +50,29 @@ {if $eventsSettings.fieldFail.footer_text}

{$eventsSettings.fieldFail.footer_text}

{/if} + + +

E-Mail Notification Settings

+ + + + + + Sender Email Address + + + + Recipient Email Address (comma separated) + + + + Email Notification + + + + + + @@ -147,6 +170,15 @@ {/if} + + + + + + + + +