WIP setup for member notification when update as moderated member.
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 25 Jun 2018 20:47:57 +0000 (16:47 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 25 Jun 2018 20:47:57 +0000 (16:47 -0400)
setup button for save as draft and pending update.

classes/helper/notification.php [new file with mode: 0644]
models/admin/member/memberInfo.php
views/admin/member/memberInfo.html
views/admin/member/memberInfo/editMediaImages.html
views/admin/member/memberInfo/editProfileStatus.html

diff --git a/classes/helper/notification.php b/classes/helper/notification.php
new file mode 100644 (file)
index 0000000..ecd2e66
--- /dev/null
@@ -0,0 +1,223 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Event Member Notification
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Steve Sutton <steve@gaslightmedia.com>
+ * @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';
+
+
+// Extend the member class
+class GlmMembersAdmin_member_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;
+        }
+        $validEmail = filter_var( $notify_to, FILTER_VALIDATE_EMAIL );
+        if ( !$validEmail ) {
+            return false;
+        }
+
+        $memberInfoData = new GlmDataMemberInfo( $this->wpdb, $this->config );
+        $memberInfo     = $memberInfoData->getActiveInfoForMember( $memberId );
+        // get settings
+        $settings    = $this->config['settings'];
+        $notify_from = $settings['from_email'];
+
+        // 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['to_email'];
+        $notify_from    = $settings['from_email'];
+        $notify_message = $settings['email_notification'];
+        if ( !$notify_to ) {
+            return false;
+        }
+        // Double check the email for valid address
+        $emails = explode( ',', $notify_to );
+        foreach ( $emails as $email ) {
+            $validEmail = filter_var( trim( $email ), FILTER_VALIDATE_EMAIL );
+            if ( !$validEmail ) {
+                return false;
+            }
+        }
+
+        // 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' ) );
+
+        // 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';
+        $message  = $htmlMessage;
+        $header[] = 'From:' . $notify_from;
+        $header[] = 'Reply-To:' . $replyTo;
+
+        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";
+    }
+}
index 7e745dd..d6cee00 100644 (file)
@@ -328,6 +328,9 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo
             // Process submission of a member information record update
             case 'submit':
 
+                // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+
+
                 // Check for new cities being submitted
                 $this->checkNewCities();
 
index b7f91a9..0e19631 100644 (file)
@@ -71,7 +71,7 @@
   {/if}
 
 
-    <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+    <form id="glm-member-profile-edit-form" action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
         <input type="hidden" name="glm_action" value="memberInfo">
         <input type="hidden" name="member" value="{$member.id}">
       {if $memberInfoID && $memberInfo}
         {if $errorMessage}<span class="glm-error glm-flash-updated glm-right">{$errorMessage}</span>{/if}
     </h2>
 
+        {* If moderated member is editing give them save draft or request update *}
         {if $lockedToMember && apply_filters( 'glm_user_is_moderated', $lockedToMember )}
-            <input class="updateMemberProfile button-secondary glm-right" type="submit" style="margin-left: 10px;"
+            <input id="saveAsDraft" class="updateMemberProfile button-secondary glm-right" type="submit" style="margin-left: 10px;"
                 value="Save as Draft">
-            <input class="updateMemberProfile button-primary glm-right" type="submit"
+            <input id="pendingMemberUpdate" class="updateMemberProfile button-primary glm-right" type="submit"
                 value="Request Update">
+        {* Else they can edit normally *}
         {else}
             <input class="updateMemberProfile button-primary glm-right" type="submit" value="{if $memberInfoID && $memberInfo}Update {$terms.term_member} profile{else}Add new {$terms.term_member} profile{/if}">
         {/if}
                 glmPageUpdateRequired();
             });
 
+    {* If member is moderated *}
+    {if $memberInfo && $lockedToMember && apply_filters( 'glm_user_is_moderated', $lockedToMember)}
+        // If they click the request update
+        $('#pendingMemberUpdate').click(function(e){
+            e.preventDefault();
+            $('input[name=status]').val('20');
+            $('#glm-member-profile-edit-form').submit();
+        });
+        // If they click the save as draft
+        $('#saveAsDraft').click(function(e){
+            e.preventDefault();
+            $('input[name=status]').val('30');
+            $('#glm-member-profile-edit-form').submit();
+        });
+    {/if}
+
     {if $memberInfoID && $memberInfo}
             // Delete Member Info dialog
             $("#deleteMemberInfoDialog").dialog({
index e0a5d32..faed1a8 100644 (file)
@@ -16,7 +16,7 @@
                 <h4 {if $memberInfo.fieldRequired.logo}class="glm-required"{/if}>Profile Image:</h4>
                 <div {if $memberInfo.fieldFail.logo}class="glm-form-bad-input" data-tabid="glm-member-info-images"{/if}>
                     <div class="glm-admin-image-edit-table">
-        {if $memberInfo.fieldData.logo}
+                    {if $memberInfo.fieldData.logo}
                         <div class="glm-row">
                             <div class="glm-small-12 glm-medium-6">
                                 <div class="glm-galleryImage" data-id="logo">
                                 <br>
                             </div>
                         </div>
-        {/if}
+                    {/if}
                         <div class="glm-center"><b>New image:</b> <input type="file" name="logo_new"></div>
                     </div>
+                    {if $memberInfo.fieldData.logo}
                     <div id="glm-galleryImageLarger_logo" class="glm-imageDialog"><img src="{$glmPluginMediaUrl}/images/large/{$memberInfo.fieldData.logo}"></div>
+                    {/if}
                     {if $memberInfo.fieldFail.logo}<p>{$memberInfo.fieldFail.logo}</p>{/if}
                 </div>
             </div>
index a31ed58..cc8e31b 100644 (file)
@@ -1,6 +1,7 @@
         <div class="glm-admin-table glm-admin-table-inner">
             {if $lockedToMember && apply_filters( 'glm_user_is_moderated', $lockedToMember )}
-                <input type="hidden" name="status" value="{$memberInfo.fieldData.status.value}" />
+                <input type="hidden" name="status" value="30" />
+                {* 30 is the Draft *}
             {else}
                 <div class="glm-row">
                     <h2>Profile Status:</h2>