From 66c17ba18b241d7489856ef8d6b848f9c6ca875c Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 23 Nov 2016 14:16:26 -0500 Subject: [PATCH] Send the email to notify_to from management When member edits coupon send notify message to the notify_to address. --- classes/helper/notification.php | 52 +++++++++++++++++++++++++++-- models/admin/coupons/list.php | 15 +++++---- views/front/coupons/ownerEmail.html | 39 ++++++++++++++++++++++ 3 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 views/front/coupons/ownerEmail.html diff --git a/classes/helper/notification.php b/classes/helper/notification.php index fc13911..1012324 100644 --- a/classes/helper/notification.php +++ b/classes/helper/notification.php @@ -85,14 +85,60 @@ class GlmMembersAdmin_coupon_notification extends GlmDataMembers /** * Send the admin user a notice */ - public function sendAdminNotice( $memberId ) + public function sendAdminNotice( $memberId, $coupon ) { - echo '
$memberId: ' . print_r( $memberId, true ) . '
'; $member = $this->getEntry( $memberId ); - echo '
$member: ' . print_r( $member, true ) . '
'; $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_COUPONS_PLUGIN_PATH . '/views'; + $smarty->template->setTemplateDir($viewPath); + + // Add standard parameters + require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php'; + $viewFile = 'front/coupons/ownerEmail.html'; + + $smarty->templateAssign('notify_message', $notify_message); + $smarty->templateAssign('name', $coupon['fieldData']['name']); + $smarty->templateAssign('start_date', $coupon['fieldData']['start_date']); + $smarty->templateAssign('end_date', $coupon['fieldData']['end_date']); + $smarty->templateAssign('expire', $coupon['fieldData']['expire']); + + // 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 = 'Coupon 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 + */ + function set_content_type() + { + return "text/html"; } } diff --git a/models/admin/coupons/list.php b/models/admin/coupons/list.php index cc95829..650c173 100644 --- a/models/admin/coupons/list.php +++ b/models/admin/coupons/list.php @@ -239,6 +239,11 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons $option = 'edit'; $couponAdded = true; + if ( $lockedToMember ) { + if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest']) ) { + $notification->sendAdminNotice( $member_id, $coupon); + } + } } else { $option = 'add'; @@ -264,12 +269,6 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons break; case 'update': - // test conditions for sending out notice need to be setup here - // True if the member is editing the record and the status - // turns to pending - if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest']) ) { - $notification->sendAdminNotice( $member_id ); - } // Get the original Coupon Status. Before the update. $old_coupon_status = $this->wpdb->get_var( $this->wpdb->prepare( @@ -296,6 +295,10 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons if ( $old_coupon_status == 20 && $new_status == 10 ) { // Update approved timestamp. $this->updateTimestamp('approved', $this->couponID); + } else if ( $lockedToMember && $old_coupon_status == 10 && $new_status == 20 ) { + if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest']) ) { + $notification->sendAdminNotice( $member_id, $coupon); + } } } diff --git a/views/front/coupons/ownerEmail.html b/views/front/coupons/ownerEmail.html new file mode 100644 index 0000000..1ab995b --- /dev/null +++ b/views/front/coupons/ownerEmail.html @@ -0,0 +1,39 @@ + + + + + + +

Coupon Submission Notification

+ + {if $notify_message} +
+

{$notify_message}

+
+ {/if} + + + + + + + + + + + + + + + + + + +
Coupon Name:{$name}
Coupon Start Date: {$start_date}
Coupon End Date:{$end_date}
Coupon Expire Date:{$expire}
+ +
+

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

+

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

+
+ + -- 2.17.1