Setting up email notifications when moderated member updates
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 26 Jun 2018 16:48:40 +0000 (12:48 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 26 Jun 2018 16:48:40 +0000 (12:48 -0400)
If a moderated member contact sets the status to pending (for member
info), it will send an email.

classes/helper/notification.php
config.php
config/plugin.ini
models/admin/member/memberInfo.php
views/admin/members/list.html
views/admin/notifications/memberEmail.html [new file with mode: 0644]
views/admin/notifications/ownerEmail.html [new file with mode: 0644]

index ecd2e66..3751056 100644 (file)
@@ -83,7 +83,7 @@ class GlmMembersAdmin_member_notification extends GlmDataMembers
      * If not found use the member info record email.
      * If nothing in either one then return.
      */
-    public function sendMemberNotice( $memberId, $event )
+    public function sendMemberNotice( $memberId, $profile )
     {
         $member = $this->getEntry( $memberId );
         // find notify_to
@@ -100,22 +100,23 @@ class GlmMembersAdmin_member_notification extends GlmDataMembers
         $memberInfoData = new GlmDataMemberInfo( $this->wpdb, $this->config );
         $memberInfo     = $memberInfoData->getActiveInfoForMember( $memberId );
         // get settings
-        $settings    = $this->config['settings'];
+        $settings    = $this->config['email_notifications'];
         $notify_from = $settings['from_email'];
+        $message     = $settings['approved_message'];
 
         // Setup the Smarty Engine
         $smarty   = new smartyTemplateSupport();
-        $viewPath = GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/views';
+        $viewPath = GLM_MEMBERS_PLUGIN_PATH . '/views';
         $smarty->template->setTemplateDir( $viewPath );
 
         // Add standard parameters
         require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php';
-        $viewFile   = 'admin/events/memberEmail.html';
+        $viewFile   = 'admin/notifications/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 );
+        $memberList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-members-list";
+        $smarty->templateAssign( 'message', $message );
+        // $smarty->templateAssign( 'name', $event['fieldData']['name'] );
+        $smarty->templateAssign( 'pendingMembers', $memberList );
 
         // Generate output from model data and view
         $htmlMessage = $smarty->template->fetch( $viewFile );
@@ -148,13 +149,13 @@ class GlmMembersAdmin_member_notification extends GlmDataMembers
      *
      * Sending email notice to the Admin user setting form Event Management.
      */
-    public function sendAdminNotice( $memberId, $event )
+    public function sendAdminNotice( $memberId, $profile )
     {
         $member         = $this->getEntry( $memberId );
-        $settings       = $this->config['settings'];
+        $settings       = $this->config['email_notifications'];
         $notify_to      = $settings['to_email'];
         $notify_from    = $settings['from_email'];
-        $notify_message = $settings['email_notification'];
+        $notify_message = $settings['notification_message'];
         if ( !$notify_to ) {
             return false;
         }
@@ -169,19 +170,16 @@ class GlmMembersAdmin_member_notification extends GlmDataMembers
 
         // Setup the Smarty Engine
         $smarty   = new smartyTemplateSupport();
-        $viewPath = GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/views';
+        $viewPath = GLM_MEMBERS_PLUGIN_PATH . '/views';
         $smarty->template->setTemplateDir( $viewPath );
 
         // Add standard parameters
         require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php';
-        $viewFile   = 'admin/events/ownerEmail.html';
+        $viewFile   = 'admin/notifications/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 );
+        $smarty->templateAssign( 'name', $profile['reference_name'] );
 
         // Generate output from model data and view
         $htmlMessage = $smarty->template->fetch( $viewFile );
@@ -199,8 +197,8 @@ class GlmMembersAdmin_member_notification extends GlmDataMembers
         add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
 
         // Set the Reply-To to use Admin Contact E-Mail
-        $replyTo  = ( $event['fieldData']['admin_email'] ) ? $event['fieldData']['admin_email']: $notify_from;
-        $subject  = 'Event Form Submission';
+        $replyTo  = $notify_from;//( $event['fieldData']['admin_email'] ) ? $event['fieldData']['admin_email']: $notify_from;
+        $subject  = $this->config['terms']['term_member_cap'] . ' Update Request';
         $message  = $htmlMessage;
         $header[] = 'From:' . $notify_from;
         $header[] = 'Reply-To:' . $replyTo;
index 38d05d1..fa24a01 100644 (file)
@@ -26,13 +26,21 @@ $config['countries'] = $countryData['countries'];
 
 // if we have the database setup already (activated) - Read in Settings and Terms from database
 if ($glmMembersDatabaseDbVersion) {
+    // Setup for settings
     $settings = $wpdb->get_row("SELECT * FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX . "settings_general WHERE id = 1;", ARRAY_A);
     unset($settings['id']);
     $config['settings'] = $settings;
+
+    // Setup for terms
     $terms = $wpdb->get_row("SELECT * FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX . "settings_terms WHERE id = 1;", ARRAY_A);
     unset($terms['id']);
     $config['terms'] = $terms;
 
+    // Setup for email_notifications
+    $email_notifications = $wpdb->get_row( "SELECT * FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX . "email_notifications WHERE id = 1", ARRAY_A );
+    unset($email_notifications['id']);
+    $config['email_notifications'] = $email_notifications;
+
     // Add Debug defines - These can't go into the defines.php file - Guess why.
     define('GLM_MEMBERS_PLUGIN_ADMIN_DEBUG', $settings['admin_debug']);
     define('GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE', $settings['admin_debug_verbose']);
index 61a1320..27c76cc 100644 (file)
@@ -56,8 +56,9 @@ status[20] = 'Pending Review'
 status[30] = 'Draft'
 status[90] = 'Archived'
 
-status_numb['Active'] = 10
-status_numb['Pending'] = 20
+status_numb['Active']   = 10
+status_numb['Pending']  = 20
+status_numb['Draft']    = 30
 status_numb['Inactive'] = 30
 status_numb['Archived'] = 90
 
index d6cee00..4dcd9b9 100644 (file)
  * @version  0.1
  */
 
-// Load Members data abstract
-require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMemberInfo.php';
+// Load Members data abstracts
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMembers.php';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMemberInfo.php';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataCategories.php';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataCategoryMemberInfo.php';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataCities.php';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataImages.php';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataFiles.php';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataAmenities.php';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/glmMemberInfoClone.php';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/helper/notification.php';
 
 /**
  * This class performs the work for the default action of the "Members" menu
@@ -277,7 +286,6 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo
         }
 
         // Get member base data
-        require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php';
         $Members = new GlmDataMembers($this->wpdb, $this->config);
         $this->memberData = $Members->getEntry($this->memberID);
         $this->fields['logo']['i_prefix'] = 'memb_'.$this->memberID.'_';
@@ -295,7 +303,6 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo
          * These will be sorted so sub-categories fall under their
          * respective category.
          */
-        require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php';
         $Categories = new GlmDataCategories($this->wpdb, $this->config);
         $categories = $Categories->getListSortedParentChild();
         $categories2 = $Categories->getListSortedParentChild(false);
@@ -328,8 +335,34 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo
             // Process submission of a member information record update
             case 'submit':
 
+                // Get the old status for this entry
+                $old_entry = $this->getEntry( $this->memberInfoID );
+                // echo '<pre>$old_entry: ' . print_r( $old_entry, true ) . '</pre>';
+                $old_status = $old_entry['status']['value'];
+                // echo '<pre>$old_status: ' . print_r( $old_status, true ) . '</pre>';
+                $new_status = isset( $_REQUEST['status'] ) ? $_REQUEST['status'] : null;
+                // echo '<pre>$new_status: ' . print_r( $new_status, true ) . '</pre>';
                 // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
 
+                // echo '<pre>$this->config: ' . print_r( $this->config, true ) . '</pre>';
+                // If a moderated user is going from Draft to Pending then send the admin notification
+                if ( $lockedToMember && apply_filters( 'glm_user_is_moderated', $lockedToMember ) ) {
+                    $draft   = $this->config['status_numb']['Draft'];
+                    // echo '<pre>$draft: ' . print_r( $draft, true ) . '</pre>';
+                    $pending = $this->config['status_numb']['Pending'];
+                    // echo '<pre>$pending: ' . print_r( $pending, true ) . '</pre>';
+                    if ( $new_status == $pending && $old_status == $draft ) {
+                        // TODO: Code to send admin notification here
+                        $Notifications = new GlmMembersAdmin_member_notification( $this->wpdb, $this->config );
+                        $settings      = $this->config['email_notifications'];
+                        // Get the profile reference name
+                        $profile = array();
+                        $profile['reference_name'] = filter_var( $_REQUEST['reference_name'], FILTER_SANITIZE_STRING );
+                        $Notifications->sendAdminNotice( $this->memberID, $profile );
+                        echo '<pre>$settings: ' . print_r( $settings, true ) . '</pre>';
+                    }
+                }
+
 
                 // Check for new cities being submitted
                 $this->checkNewCities();
@@ -341,11 +374,9 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo
                 $this->updateAmenities();
 
                 // Load Image data class
-                require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.php';
                 $Images = new GlmDataImages($this->wpdb, $this->config);
 
                 // Load File data class
-                require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataFiles.php';
                 $Files = new GlmDataFiles( $this->wpdb, $this->config );
 
                 // Update image gallery titles, descriptions, and image positions then return current image gallery
@@ -379,7 +410,8 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo
                 } else {
 
                 }
-//                print_r($customFieldResults);
+
+                // Clear out shortcode cache for members
                 glmClearShortcodeCache();
 
                 break;
@@ -427,7 +459,6 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo
             case 'clone':
 
                 // Load Member Info Clone Class
-                require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/glmMemberInfoClone.php';
                 $CloneMemberInfo = new GlmMemberInfoClone($this->wpdb, $this->config);
 
                 $oldId = $this->memberInfoID;
@@ -462,7 +493,6 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo
         }
 
         // Get list of Available Member Amenities to use for picklists
-        require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataAmenities.php';
         $Amenities = new GlmDataAmenities($this->wpdb, $this->config);
         $this->amenities = $Amenities->getList("T.ref_type = ".$this->config['ref_type_numb']['MemberInfo']);
 
@@ -500,13 +530,11 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo
 
             if ($this->memberInfoID) {
                 // Also, if this is not a create, get any image gallery images
-                require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.php';
                 $Images = new GlmDataImages($this->wpdb, $this->config);
                 $this->imageGallery = $Images->getGallery($this->config['ref_type_numb']['MemberInfo'], $this->memberInfoID);
                 $this->haveImageGallery = ($this->imageGallery != false);
 
                 // Also, if this is not a create, get any files
-                require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataFiles.php';
                 $Files           = new GlmDataFiles( $this->wpdb, $this->config );
                 $this->files     = $Files->getFiles( $this->config['ref_type_numb']['MemberInfo'], $this->memberInfoID );
                 $this->haveFiles = ($this->files != false);
@@ -577,7 +605,6 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo
             $cName = trim(filter_var($_REQUEST['newCityName']));
 
             // Try to add the city
-            require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCities.php';
             $Cities = new GlmDataCities($this->wpdb, $this->config);
             $cID = $Cities->addCity($cName);
 
@@ -604,7 +631,6 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo
             $cName = trim(filter_var($_REQUEST['newMailingCityName']));
 
             // Try to add the mailing_city
-            require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCities.php';
             $Cities = new GlmDataCities($this->wpdb, $this->config);
             $cID = $Cities->addCity($cName);
 
@@ -635,11 +661,9 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo
     {
 
         // Instatiate the dataCategories class
-        require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php';
         $Categories = new GlmDataCategories($this->wpdb, $this->config);
 
         // Instatiate categoryMemberInfo class
-        require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategoryMemberInfo.php';
         $CategoryMemberInfo = new GlmDataCategoryMemberInfo($this->wpdb, $this->config);
 
         // Get any selected categories
@@ -785,7 +809,6 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo
     {
 
         // Instantiate Amenities data class
-        require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataAmenities.php';
         $Amenities = new GlmDataAmenities($this->wpdb, $this->config);
 
         $selectedAmenities = array();
index 7bd477a..c35a675 100644 (file)
@@ -88,7 +88,9 @@
                         <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=index&member={$m.id}">{$m.name}</a>
                     </td>
                     <td style="width: 120px;">
+                        {if $m.active_id}
                         <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=memberInfo&member={$m.id}&memberInfo={$m.active_id}" class="button button-secondary glm-button-small glm-admin-edit-active-profile" style="margin: 0 .2em 0 .2em;">Edit Active Profile</a>
+                        {/if}
                     </td>
                     <td style="width: 120px;">
                         <a href="{$siteBaseUrl}{$settings.canonical_member_page}/{$m.member_slug}/" target="_blank">View Profile</a>
diff --git a/views/admin/notifications/memberEmail.html b/views/admin/notifications/memberEmail.html
new file mode 100644 (file)
index 0000000..7d22eff
--- /dev/null
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta http-equiv="content-type" content="text/html;charset=utf-8">
+    </head>
+    <body>
+        <h1 id="title"> {$terms.term_member_cap} Approval Notification</h1>
+
+        {if $message}
+        <div style="width: 500px">
+            <p> {$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;">{$terms.term_member_cap} Name:</td>
+                <td style="width:200px;padding:5px;border:1px solid #ccc;">{$name}</td>
+            </tr>
+        </table>
+
+        <div id="emailFooter">
+            <p style="margin-bottom: 0px;">A {$terms.term_member_cap} has been approved.</p>
+            <p style="margin-top: 0px;">To view it, please go to the <a style="color: rgb(5, 104, 179);" href="{$pendingMembers}"> {$terms.term_member} </a> page in your admin.</p>
+        </div>
+    </body>
+</html>
diff --git a/views/admin/notifications/ownerEmail.html b/views/admin/notifications/ownerEmail.html
new file mode 100644 (file)
index 0000000..8526f27
--- /dev/null
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta http-equiv="content-type" content="text/html;charset=utf-8">
+    </head>
+    <body>
+        <h1 id="title"> {$terms.term_member_cap} 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;">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;">Profile Name:</td>
+                <td style="width:200px;padding:5px;border:1px solid #ccc;">{$name}</td>
+            </tr>
+        </table>
+
+        <div id="emailFooter">
+            <p style="margin-top: 0px;"></p>
+        </div>
+    </body>
+</html>