Update event dashboard.
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 21 Aug 2019 18:40:25 +0000 (14:40 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 21 Aug 2019 18:40:25 +0000 (14:40 -0400)
Using same columns as the main dashboard for events.
Adding bulk approve and decline to this dashboard.

classes/helper/notification.php
models/admin/dashboard/events.php
models/admin/events/index.php
models/admin/events/list.php
views/admin/dashboard/events.html
views/admin/events/index.html

index ec638c9..4a4e442 100644 (file)
@@ -155,6 +155,59 @@ class GlmMembersAdmin_event_notification extends GlmDataMembers
         remove_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
     }
 
+    public function sendEventNotice( $event, $status )
+    {
+        $email_notifications = $this->config['settings'];
+        $from_email = $email_notifications ? $email_notifications['from_email'] : false;
+
+        $to_email    = (isset($event['fieldData']['admin_email']) ? $event['fieldData']['admin_email'] : '' );
+        $event_title = (isset($event['fieldData']['name']) ? $event['fieldData']['name'] : '' );
+        $admin_name  = (isset($event['fieldData']['admin_name']) ? $event['fieldData']['admin_name'] : '' );
+        $event_intro = (isset($event['fieldData']['intro']) ? $event['fieldData']['intro'] : '' );
+        $site_name   = get_bloginfo( 'name' );
+
+        // Email Headers
+        $header[] = "From: $site_name <$from_email>";
+        $header[] = 'Reply-To: ' . $from_email;
+        $header[] = "Return-Path: $from_email";
+
+        // change the default wordpress from name when sending mail
+        function set_content_type(){
+            return "text/html";
+        }
+
+        // Send confirmation email, set the content type to allow html by using this filter
+        add_filter( 'wp_mail_content_type', 'set_content_type' );
+
+        $declined  = '';
+        $current_status = $event['fieldData']['status']['value'];
+
+        if ( $to_email ) {
+            $message  = $site_name . " Events<br><br>";
+            $message .= "Event Name: " . $event_title . "<br>";
+            $message .= "Event Description: $event_intro<br>";
+            $message .= "Contact Name: $admin_name<br><br>";
+
+            switch ( $status ) {
+            case $this->config['event_status_numb']['Active']:
+                $subject  = 'Event Approved';
+                $message  .= $email_notifications['approved_message'];
+                // This is done using helper class notifications
+                wp_mail( $to_email, $subject, $message, $header );
+                break;
+            case $this->config['event_status_numb']['Declined']:
+                $declined = $email_notifications['declined_message'];
+                $subject  = 'Event Declined';
+                $message  .= "Your event has been declined for the following reason(s):<br> $declined";
+                // This is done using helper class notifications
+                wp_mail( $to_email, $subject, $message, $header );
+                break;
+            }
+
+        }
+        remove_filter( 'wp_mail_content_type', 'set_content_type' );
+    }
+
     /**
      * Send the admin user a notice.
      *
index 31c24e3..983ddef 100644 (file)
@@ -119,12 +119,18 @@ class GlmMembersAdmin_dashboard_events extends GlmDataEvents
                     if ( $member_id ) {
                         $notification->sendMemberNotice( $member_id, $event, $this->config['event_status_numb']['Active'] );
                     }
+                    if ( $event['fieldData']['admin_email'] ) {
+                        $notification->sendEventNotice( $event, $this->config['event_status_numb']['Active'] );
+                    }
                     break;
                 case 'Decline':
                     $this->updateStatus( $eventId, $this->config['event_status_numb']['Declined'] );
                     if ( $member_id ) {
                         $notification->sendMemberNotice( $member_id, $event, $this->config['event_status_numb']['Declined'] );
                     }
+                    if ( $event['fieldData']['admin_email'] ) {
+                        $notification->sendEventNotice( $event, $this->config['event_status_numb']['Declined'] );
+                    }
                     break;
                 default:
                     break;
index 3b67d78..b2705f7 100644 (file)
@@ -98,6 +98,43 @@ class GlmMembersAdmin_events_index extends GlmDataEvents
         $haveCategories = false;
 //        $haveAmenities  = false;
 
+        if ( isset( $_REQUEST['bulkAction'] ) && isset( $_REQUEST['bulkEdit'] ) && !empty( $_REQUEST['bulkEdit'] ) ) {
+            // Load Notifications from the helper classes
+            include_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/helper/notification.php';
+            $notification = new GlmMembersAdmin_event_notification( $this->wpdb, $this->config );
+            $members = array();
+            // Process the bulk edit events.
+            $bulkAction = filter_var( $_REQUEST['bulkAction'], FILTER_SANITIZE_STRING );
+            $bulkEdit   = filter_var( $_REQUEST['bulkEdit'], FILTER_VALIDATE_INT, [ 'flags' => FILTER_FORCE_ARRAY ] );
+            foreach ( $bulkEdit as $eventId ) {
+                $event     = $this->editEntry( $eventId );
+                $member_id = $event['fieldData']['ref_dest_id'];
+                switch ( $bulkAction ) {
+                case 'Approve':
+                    $this->updateTimestamp( 'approved', $eventId );
+                    $this->updateStatus( $eventId, $this->config['event_status_numb']['Active'] );
+                    if ( $member_id ) {
+                        $notification->sendMemberNotice( $member_id, $event, $this->config['event_status_numb']['Active'] );
+                    }
+                    if ( $event['fieldData']['admin_email'] ) {
+                        $notification->sendEventNotice( $event, $this->config['event_status_numb']['Active'] );
+                    }
+                    break;
+                case 'Decline':
+                    $this->updateStatus( $eventId, $this->config['event_status_numb']['Declined'] );
+                    if ( $member_id ) {
+                        $notification->sendMemberNotice( $member_id, $event, $this->config['event_status_numb']['Declined'] );
+                    }
+                    if ( $event['fieldData']['admin_email'] ) {
+                        $notification->sendEventNotice( $event, $this->config['event_status_numb']['Declined'] );
+                    }
+                    break;
+                default:
+                    break;
+                }
+            }
+        }
+
         // Check if there's a logged in user who is locked to their own entity
         $lockedToMember = apply_filters('glm_members_locked_to_member_id', false);
         if ($lockedToMember) {
@@ -115,8 +152,8 @@ class GlmMembersAdmin_events_index extends GlmDataEvents
             $haveCategories = true;
         }
 
-//        
-//                
+//
+//
 //        // 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);
@@ -167,7 +204,44 @@ class GlmMembersAdmin_events_index extends GlmDataEvents
         $numbPending = $this->getStats($lockedWhere.' status = '.$this->config['status_numb']['Pending']);
 
         // Get list of Pending Events
-        $pending = $this->getIdName($lockedWhereT.' T.status = '.$this->config['status_numb']['Pending']);
+
+        if ( $lockedToMember ) {
+            $pending = $this->getIdName($lockedWhereT.' T.status = '.$this->config['status_numb']['Pending']);
+        } else {
+            $pending = $this->wpdb->get_results(
+                "SELECT E.id,E.name,E.ref_dest,T1.start_time as start,T2.end_time as end,
+                        E.admin_org, E.created
+                   FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events E,
+                        " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times T1,
+                        " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times T2
+                  WHERE E.status = " . $this->config['status_numb']['Pending'] . "
+                    AND T1.event = E.id AND T1.start_time IN (
+                        SELECT MIN(start_time)
+                          FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
+                         WHERE event = E.id)
+                    AND T2.event = E.id AND T2.end_time IN (
+                        SELECT MAX(end_time)
+                          FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
+                         WHERE event = E.id)
+               ORDER BY E.status DESC,end DESC,start DESC",
+                ARRAY_A
+            );
+
+            foreach ( $pending as &$event ) {
+                // Set the Member Name
+                if ( $memberId = filter_var( $event['ref_dest'], FILTER_VALIDATE_INT) ) {
+                    $memberName = $this->wpdb->get_var(
+                        $this->wpdb->prepare(
+                            "SELECT name
+                               FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+                              WHERE id = %d",
+                            $memberId
+                        )
+                    );
+                    $event['member_name'] = $memberName;
+                }
+            }
+        }
 
 
         // Compile template data
index 8e7545e..3b0446e 100644 (file)
@@ -967,14 +967,14 @@ class GlmMembersAdmin_events_list extends GlmDataEvents
                     $subject  = 'Event Approved';
                     $message  .= $email_notifications['approved_message'];
                     // This is done using helper class notifications
-                    // wp_mail( $to_email, $subject, $message, $header );
+                    wp_mail( $to_email, $subject, $message, $header );
 
                 } else if( $old_event_status === '20' && $current_status === '40' ){
                     $declined = $email_notifications['declined_message'];
                     $subject  = 'Event Declined';
                     $message  .= "Your event has been declined for the following reason(s):<br> $declined";
                     // This is done using helper class notifications
-                    // wp_mail( $to_email, $subject, $message, $header );
+                    wp_mail( $to_email, $subject, $message, $header );
                 }
             }
             remove_filter( 'wp_mail_content_type', 'set_content_type' );
index 77be6ac..7366f2c 100644 (file)
@@ -31,7 +31,7 @@
                                 {/if}
                                 <th style="text-align: left;">Name</th>
                                 {if !$memberID}
-                                    <th style="text-align: left;">Member</th>
+                                    <th style="text-align: left;">{$terms.term_member_cap}</th>
                                     <th style="text-align: left;">Organization</th>
                                     <th style="text-align: left;">Created</th>
                                 {/if}
index b1809b0..4488429 100644 (file)
 {if $pending}
     <h3 class="glm-error">&nbsp;<br>Events Pending Review</h3>
 
+    {if !$lockedToMember}
+    <form action="{$thisUrl}?page={$thisPage}" method="post">
+        <input type="hidden" name="glm_action" value="index">
+        <div>
+            <select name="bulkAction">
+                <option value="">Bulk Actions</option>
+                <option value="Approve">Approve</option>
+                <option value="Decline">Decline</option>
+            </select>
+            <input type="submit" value="Apply" class="button">
+        </div>
+    {/if}
     <table class="wp-list-table widefat fixed posts glm-admin-table">
         <thead>
             <tr>
+                {if !$lockedToMember}
+                    <td style="width: 50px;"><label><input id="master-event-bulk" type="checkbox">&nbsp;</label></td>
+                {/if}
                 <th>Event Name</th>
-                {if !$lockedToMember}<th>{$terms.term_member_cap}</th>{/if}
+                {if !$lockedToMember}
+                    <th>{$terms.term_member_cap}</th>
+                    <th>Organization</th>
+                    <th>Created</th>
+                    <th>Start</th>
+                    <th>End</th>
+                {/if}
+
             </tr>
         </thead>
         <tbody>
     {assign var="i" value="0"}
     {foreach $pending as $p}
-        {if $i++ is odd by 1}
-            <tr>
-        {else}
-            <tr class="alternate">
-        {/if}
-                <td>
-                    <a href="{$thisUrl}?page=glm-members-admin-menu-events-list&glm_action=list&option=edit&event={$p.id}">{$p.name}</a>
-                </td>
-                {if !$lockedToMember}<td>{if $p.ref_dest_id}<a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=index&member={$p.ref_dest_id}}">{$p.ref_dest}</a>{/if}</td>{/if}
-            </tr>
+        <tr class="{if $p@iteration is div by 2}alternate{/if}">
+            {if !$lockedToMember}
+                <td><label><input class="slave-event-bulk" type="checkbox" name="bulkEdit[]" value="{$p.id}">&nbsp;</label></td>
+            {/if}
+            <td>
+                <a href="{$thisUrl}?page=glm-members-admin-menu-events-list&glm_action=list&option=edit&event={$p.id}">{$p.name}</a>
+            </td>
+            {if !$lockedToMember}
+                {* <td>{if $p.ref_dest_id}<a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=index&member={$p.ref_dest_id}}">{$p.ref_dest}</a>{/if}</td> *}
+                <td> {if $p.ref_dest} <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=index&member={$p.ref_dest}">{$p.member_name}</a> {/if} </td>
+                <td> {$p.admin_org} </td>
+                <td> {$p.created|date_format:"%m/%d/%Y"} </td>
+                <td>{$p.start|date_format:"%m/%d/%y"}</td>
+                <td>{$p.end|date_format:"%m/%d/%Y"}</td>
+            {/if}
+        </tr>
     {/foreach}
         </tbody>
     </table>
+
+    {if !$lockedToMember}
+    </form>
+    {/if}
+{/if}
+
+{if !$lockedToMember}
+    <script>
+        jQuery(document).ready(function($) {
+            $('#master-event-bulk').on( 'change', function(){
+                if ( $(this).is(':checked') ) {
+                    $('.slave-event-bulk').each(function(){
+                        $(this).prop('checked', true);
+                    });
+                } else {
+                    $('.slave-event-bulk').each(function(){
+                        $(this).prop('checked', false);
+                    });
+                }
+            });
+            $('.slave-event-bulk').on( 'change', function(){
+                updateMasterCheckBox();
+            });
+            // Go through all slave-event-bulk items and see if there checked.
+            // If they are then make the master one checked.
+            // If not then make the master one unchecked
+            function updateMasterCheckBox() {
+                var shouldMasterBeChecked = false;
+                var totalCheckBoxes = $('.slave-event-bulk').length;
+                var numberChecked = 0;
+                $('.slave-event-bulk').each(function(){
+                    if ( $(this).is(':checked') ) {
+                        numberChecked++;
+                    }
+                });
+                if ( numberChecked === totalCheckBoxes ) {
+                    $('#master-event-bulk').prop('checked', true);
+                } else {
+                    $('#master-event-bulk').prop('checked', false);
+                }
+            }
+        });
+    </script>
 {/if}
 
 {if $namesList}