From aed3d7e1316023b75d0dec3cb730d8987226f262 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 5 Dec 2016 15:20:41 -0500 Subject: [PATCH] Add member/admin notices for events. When member edits an event it will send email notice out to notify. When admin approves an event it will send email notice out to member. --- classes/helper/notification.php | 207 ++++++++++++++++++++++++++++ models/admin/events/list.php | 14 ++ views/admin/events/memberEmail.html | 25 ++++ views/admin/events/ownerEmail.html | 31 +++++ 4 files changed, 277 insertions(+) create mode 100644 classes/helper/notification.php create mode 100644 views/admin/events/memberEmail.html create mode 100644 views/admin/events/ownerEmail.html diff --git a/classes/helper/notification.php b/classes/helper/notification.php new file mode 100644 index 0000000..003aab0 --- /dev/null +++ b/classes/helper/notification.php @@ -0,0 +1,207 @@ + + * @license http://www.galightmedia.com Gaslightmedia + * @release 1 + */ + +// Load the Member Data class +require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMembers.php'; +require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMemberInfo.php'; +require_once GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH . '/data/dataContacts.php'; + + +// Extend the member class +class GlmMembersAdmin_event_notification extends GlmDataMembers +{ + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /** + * Constructor + * + * This constructor performs the work for this model. This model returns + * an array containing the following. + * + * 'status' + * + * True if successful and false if there was a fatal failure. + * + * '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. + * + * @wpdb object Word Press database object + * + * @return array Array containing status, suggested view, and any data + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + /* + * Run constructor for the Events class + */ + parent::__construct($wpdb, $config); + } + + + /** + * Send the member a notice. + * + * This will be the primary contact email if found. + * If not found use the member info record email. + * If nothing in either one then return. + */ + public function sendMemberNotice( $memberId, $event ) + { + $member = $this->getEntry( $memberId ); + // find notify_to + // See if there's a primary member contact for this member + $notify_to = apply_filters( 'glm-member-db-admin-get-member-primary-email', '', $memberId ); + if ( !$notify_to ) { + return false; + } + + $memberInfoData = new GlmDataMemberInfo( $this->wpdb, $this->config ); + $memberInfo = $memberInfoData->getActiveInfoForMember( $memberId ); + // get settings + $settings = $this->config['settings']; + $notify_from = $settings['notify_from']; + + // Setup the Smarty Engine + $smarty = new smartyTemplateSupport(); + $viewPath = GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/views'; + $smarty->template->setTemplateDir( $viewPath ); + + // Add standard parameters + require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php'; + $viewFile = 'admin/events/memberEmail.html'; + + $eventList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-events-list&glm_action=list"; + $smarty->templateAssign( 'location', 'Member Events' ); + $smarty->templateAssign( 'name', $event['fieldData']['name'] ); + $smarty->templateAssign( 'pendingEvents', $eventList ); + + // Generate output from model data and view + $htmlMessage = $smarty->template->fetch( $viewFile ); + + + // change the default wordpress from name when sending mail + add_filter( + 'wp_mail_from_name', + function ( $name ) { + $siteName = get_bloginfo( 'name' ); + return $siteName; + } + ); + // 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' ) ); + + $subject = 'Event Approved'; + $message = $htmlMessage; + $header[] = 'From:' . $notify_from; + $header[] = 'Reply-To:' . $notify_from; + + wp_mail( $notify_to, $subject, $message, $header ); + + // remove the filter to avoid conflicts + remove_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) ); + } + + /** + * Send the admin user a notice. + * + * Sending email notice to the Admin user setting form Event Management. + */ + public function sendAdminNotice( $memberId, $event ) + { + $member = $this->getEntry( $memberId ); + $settings = $this->config['settings']; + $notify_to = $settings['notify_to']; + $notify_from = $settings['notify_from']; + $notify_message = $settings['notify_message']; + + // Setup the Smarty Engine + $smarty = new smartyTemplateSupport(); + $viewPath = GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/views'; + $smarty->template->setTemplateDir( $viewPath ); + + // Add standard parameters + require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php'; + $viewFile = 'admin/events/ownerEmail.html'; + + $eventList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-events-index"; + $smarty->templateAssign( 'notify_message', $notify_message); + $smarty->templateAssign( 'location', 'Member Events' ); + $smarty->templateAssign( 'member', $member ); + $smarty->templateAssign( 'name', $event['fieldData']['name'] ); + $smarty->templateAssign( 'pendingEvents', $eventList ); + + // Generate output from model data and view + $htmlMessage = $smarty->template->fetch( $viewFile ); + + + // change the default wordpress from name when sending mail + add_filter( + 'wp_mail_from_name', + function ( $name ) { + $siteName = get_bloginfo( 'name' ); + return $siteName; + } + ); + // 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' ) ); + + $subject = 'Event Form Submission'; + $message = $htmlMessage; + $header[] = 'From:' . $notify_from; + $header[] = 'Reply-To:' . $notify_from; + + wp_mail( $notify_to, $subject, $message, $header ); + + // remove the filter to avoid conflicts + remove_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) ); + } + + /** + * 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/models/admin/events/list.php b/models/admin/events/list.php index f90a405..3221e63 100644 --- a/models/admin/events/list.php +++ b/models/admin/events/list.php @@ -139,6 +139,10 @@ class GlmMembersAdmin_events_list extends GlmDataEvents $namesList = false; $enable_members = $this->config['settings']['enable_members']; + // Load Notifications from the helper classes + include_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/helper/notification.php'; + $notification = new GlmMembersAdmin_event_notification( $this->wpdb, $this->config ); + // Check if there's a logged in user who is locked to their own entity $lockedToMember = apply_filters('glm_members_locked_to_member_id', false); if ($lockedToMember) { @@ -343,6 +347,11 @@ class GlmMembersAdmin_events_list extends GlmDataEvents // Get this again so we have the created date $event = $this->editEntry($this->eventID); + if ( $lockedToMember ) { + if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest'] ) ) { + $notification->sendAdminNotice( $member_id, $event ); + } + } $option = 'edit'; $eventAdded = true; @@ -400,6 +409,11 @@ class GlmMembersAdmin_events_list extends GlmDataEvents if ( $old_event_status == 20 && $new_status == 10 ) { // Update approved timestamp. $this->updateTimestamp('approved', $this->eventID); + if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest'] ) ) { + $notification->sendMemberNotice( $member_id, $event ); + } + } else if ( $lockedToMember && $old_event_status == 10 && $new_status == 20 ) { + $notification->sendAdminNotice( $member_id, $event ); } } diff --git a/views/admin/events/memberEmail.html b/views/admin/events/memberEmail.html new file mode 100644 index 0000000..159db8f --- /dev/null +++ b/views/admin/events/memberEmail.html @@ -0,0 +1,25 @@ + + + + + + +

Event Approval Notification

+ +
+

Your event has been approved!

+
+ + + + + + +
Event Name:{$name}
+ +
+

A Event has been approved.

+

To view it, please go to the events page in your admin.

+
+ + diff --git a/views/admin/events/ownerEmail.html b/views/admin/events/ownerEmail.html new file mode 100644 index 0000000..b8996d9 --- /dev/null +++ b/views/admin/events/ownerEmail.html @@ -0,0 +1,31 @@ + + + + + + +

Event Submission Notification

+ + {if $notify_message} +
+

{$notify_message}

+
+ {/if} + + + + + + + + + + +
Member Name:{$member.name}
Event Name:{$name}
+ +
+

A new Event has been added to your Website from your "{$location}" page.

+

To approve it, please go to the events page in your admin.

+
+ + -- 2.17.1