/**
* Send the admin user a notice
*/
- public function sendAdminNotice( $memberId )
+ public function sendAdminNotice( $memberId, $coupon )
{
- echo '<pre>$memberId: ' . print_r( $memberId, true ) . '</pre>';
$member = $this->getEntry( $memberId );
- echo '<pre>$member: ' . print_r( $member, true ) . '</pre>';
$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";
}
}
$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';
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(
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);
+ }
}
}
--- /dev/null
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ </head>
+ <body>
+ <h1 id="title"> Coupon Submission Notification</h1>
+
+ {if $notify_message}
+ <div style="width: 500px">
+ <p> {$notify_message} </p>
+ </div>
+ {/if}
+
+ <table cellspacing="0" cellpadding="0" width="500" style="background: lightgrey;border:1px solid #ccc;border-collapse:collapse;">
+ <tr>
+ <td style="font-weight:bold;width:200px;padding:5px;border:1px solid #ccc;">Coupon Name:</td>
+ <td style="width:200px;padding:5px;border:1px solid #ccc;">{$name}</td>
+ </tr>
+ <tr>
+ <td style="font-weight:bold;width:200px;padding:5px;border:1px solid #ccc;">Coupon Start Date: </td>
+ <td style="width:200px;padding:5px;border:1px solid #ccc;"> {$start_date} </td>
+ </tr>
+ <tr>
+ <td style="font-weight:bold;width:200px;padding:5px;border:1px solid #ccc;" >Coupon End Date:</td>
+ <td style="width:200px;padding:5px;border:1px solid #ccc;" >{$end_date}</td>
+ </tr>
+ <tr>
+ <td style="font-weight:bold;width:200px;padding:5px;border:1px solid #ccc;" >Coupon Expire Date:</td>
+ <td style="width:200px;padding:5px;border:1px solid #ccc;" >{$expire}</td>
+ </tr>
+ </table>
+
+ <div id="emailFooter">
+ <p style="margin-bottom: 0px;">A new Coupon has been added to your Website from your "{$location}" page.</p>
+ <p style="margin-top: 0px;">To approve it, please go to the <a style="color: rgb(5, 104, 179);" href="{$pendingCoupons}"> coupons </a> page in your admin.</p>
+ </div>
+ </body>
+</html>