Working on the email notifications
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 2 Dec 2016 15:50:09 +0000 (10:50 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 2 Dec 2016 15:50:09 +0000 (10:50 -0500)
Testing owner email

classes/helper/notification.php
models/admin/coupons/list.php
views/front/coupons/ownerEmail.html

index 1012324..1d99fa6 100644 (file)
@@ -77,9 +77,55 @@ class GlmMembersAdmin_coupon_notification extends GlmDataMembers
     /**
      * Send the member a notice
      */
-    public function sendMemberNotice()
+    public function sendMemberNotice( $memberId, $coupon )
     {
+        $member = $this->getEntry( $memberId );
+        // find notify_to
+        // 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.
+        $settings    = $this->config['settings'];
+        $notify_from = $settings['notify_from'];
+
+        // 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';
+
+        $couponList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-coupons-list";
+        $smarty->templateAssign( 'notify_message', $notify_message);
+        $smarty->templateAssign( 'location', 'Member Coupons' );
+        $smarty->templateAssign( 'name', $coupon['fieldData']['name'] );
+        $smarty->templateAssign( 'pendingCoupons', $couponList );
 
+        // 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' ) );
     }
 
     /**
@@ -87,36 +133,40 @@ class GlmMembersAdmin_coupon_notification extends GlmDataMembers
      */
     public function sendAdminNotice( $memberId, $coupon )
     {
-        $member = $this->getEntry( $memberId );
+        $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();
+        $smarty   = new smartyTemplateSupport();
         $viewPath = GLM_MEMBERS_COUPONS_PLUGIN_PATH . '/views';
-        $smarty->template->setTemplateDir($viewPath);
+        $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']);
+        $viewFile   = 'front/coupons/ownerEmail.html';
+
+        $couponList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-coupons-list";
+        $smarty->templateAssign( 'notify_message', $notify_message);
+        $smarty->templateAssign( 'location', 'Member Coupons' );
+        $smarty->templateAssign( 'member', $member );
+        $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'] );
+        $smarty->templateAssign( 'pendingCoupons', $couponList );
 
         // Generate output from model data and view
-        $htmlMessage = $smarty->template->fetch($viewFile);
+        $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');
+            function ( $name ) {
+                $siteName = get_bloginfo( 'name' );
                 return $siteName;
             }
         );
index 8e5572a..05276e7 100644 (file)
@@ -299,6 +299,8 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
                             // Update approved timestamp.
                             $this->updateTimestamp('approved', $this->couponID);
                         } else if ( $lockedToMember && $old_coupon_status == 10 && $new_status == 20 ) {
+                            // Here the status is changing from active to pending. (member edit)
+                            // Send notice to admin user
                             if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest']) ) {
                                 $notification->sendAdminNotice( $member_id, $coupon);
                             }
index 1ab995b..f591448 100644 (file)
         {/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;">Member Name:</td>
+                <td style="width:200px;padding:5px;border:1px solid #ccc;">{$member.name}</td>
+            </tr>
             <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>
+                <td style="width:200px;padding:5px;border:1px solid #ccc;"> {$start_date.timestamp|date_format:"%D"} </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>
+                <td style="width:200px;padding:5px;border:1px solid #ccc;" >{$end_date.timestamp|date_format:"%D"}</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>
+                <td style="width:200px;padding:5px;border:1px solid #ccc;" >{$expire.timestamp|date_format:"%D"}</td>
             </tr>
         </table>