Expired users
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 26 Apr 2018 20:39:16 +0000 (16:39 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 26 Apr 2018 20:39:16 +0000 (16:39 -0400)
Deal with wordpress user also when updating the contact_roles.

classes/billingSupport.php
classes/notifications.php
config/plugin.ini
models/admin/ajax/billingFlagExpiredUsers.php
models/admin/member/billing.php
models/front/billing/becomeMember.php
setup/adminHooks.php
setup/commonHooks.php
views/admin/settings/notificationTypes.html

index 821e46a..697ee6d 100644 (file)
@@ -1377,18 +1377,17 @@ class GlmBillingSupport
             // Record the payment.
             $this->recordPayment( $payment_id, $account_id, $amount, $invoice_id );
 
-            // $errors[] = $ccResult['statusText'];
-            // $errors[] = $ccResult['description'];
-
-            // Need to update the members account renewal_date
-            // $this->updateAccountRenewalDate( $account_id );
+            // Set the contact_role for the member contact so they can login now.
+            if ( $account_id ) {
+                $this->setMemberAccountActive( $account_id );
+            }
+            // Set the contact_role (employees) for the member contact so they can login now.
+            if ( isset( $employees ) && is_array( $employees ) && !empty( $employees ) ) {
+                foreach ( $employees as $emp_account_id ) {
+                    $this->setMemberAccountActive( $emp_account_id );
+                }
+            }
 
-            // Need to update any employees renewal dates
-            // if ( isset( $employees ) && is_array( $employees ) && !empty( $employees ) ) {
-            //     foreach ( $employees as $employee ) {
-            //         $this->updateAccountRenewalDate( $employee );
-            //     }
-            // }
 
             $errors = $result['errors'];
 
@@ -1400,6 +1399,40 @@ class GlmBillingSupport
 
     }
 
+    /**
+     * Set the member contact for this account as active user now.
+     * Set member contact to contact_role = 20
+     */
+    public function setMemberAccountActive( $account_id )
+    {
+        $activeRole = $this->config['contact_role_numb']['EntityManager'];
+        $this->wpdb->query(
+            $this->wpdb->prepare(
+                "UPDATE " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts
+                    SET contact_role = " . $activeRole . "
+                  WHERE ref_dest = (
+                        SELECT ref_dest
+                          FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+                         WHERE id = %d
+                    )",
+                $account_id
+            )
+        );
+        // Get the Wordpress user for this account.
+        $account = $this->getAccountById( $account_id );
+        if ( isset( $account['ref_dest'] ) && $account['ref_dest'] ) {
+            $contactID = $this->wpdb->get_var(
+                $this->wpdb->prepare(
+                    "SELECT id
+                       FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts
+                      WHERE ref_dest = %d",
+                    $this->memberID
+                )
+            );
+        }
+
+    }
+
     /**
      * makePayment
      *
index e23be30..129dba2 100644 (file)
@@ -255,14 +255,15 @@ class GlmNotifications
      */
     public function getNotificationsByType( $type )
     {
-        return $this->wpdb->get_var(
+        return $this->wpdb->get_results(
             $this->wpdb->prepare(
                 "SELECT id
                    FROM "  . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX .  "notification_types
                   WHERE send_by_action
                     AND send_action = %d",
                 $this->config['send_action_numb'][$type]
-            )
+            ),
+            ARRAY_A
         );
     }
 
index da0cffa..87ff93a 100644 (file)
@@ -38,10 +38,12 @@ send_date_period[40] = "Year"
 send_action[10] = "Create Invoice"
 send_action[20] = "Received Payment"
 send_action[30] = "New Member"
+send_action[40] = "New Member Admin Notice"
 
-send_action_numb['Create Invoice']   = 10;
-send_action_numb['Received Payment'] = 20;
-send_action_numb['New Member']       = 30;
+send_action_numb['Create Invoice']          = 10;
+send_action_numb['Received Payment']        = 20;
+send_action_numb['New Member']              = 30;
+send_action_numb['New Member Admin Notice'] = 40;
 
 ; Send Date When
 send_date_when[10] = "Before"
index 7593c40..d31eab1 100644 (file)
@@ -71,24 +71,42 @@ class GlmMembersAdmin_ajax_billingFlagExpiredUsers
     {
 
         echo '<pre>$actionData: ' . print_r( $actionData, true ) . '</pre>';
-        return false;
-
         $days_after_expired = $this->config['settings']['days_after_expired'];
         $current_date       = date( 'Y-m-d' );
+        $restrictedRole     = $this->config['contact_role_numb']['LogInContact'];
+        echo '<pre>$restrictedRole: ' . print_r( $restrictedRole, true ) . '</pre>';
 
         // Update All expired accounts so they can only be in members only not admin.
         // Find all member contacts (by ref_dest) with accounts that are expired.
         // With those set their contact_role to 30 (login only)
         if ( $days_after_expired = filter_var( $days_after_expired, FILTER_VALIDATE_INT ) ) {
+            $members = $this->wpdb->get_results(
+                "SELECT ref_dest
+                   FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+                  WHERE renewal_date + INTERVAL 1 YEAR + INTERVAL $days_after_expired DAY <= '$current_date'",
+                   ARRAY_A
+            );
+            if ( isset( $members ) && $members ) {
+                foreach ( $members as $member ) {
+                    echo '<pre>$member: ' . print_r( $member, true ) . '</pre>';
+                    apply_filters(
+                        'glm_contact_update_user_role_by_ref_dest',
+                        '',
+                        $member['ref_dest'],
+                        'glm_members_own_entity_manager',
+                        'glm_members_member_contact'
+                    );
+                }
+            }
             $this->wpdb->query(
                 "UPDATE " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX. "contacts
-                    SET contact_role = 30
+                    SET contact_role = " . $restrictedRole . "
                   WHERE ref_dest IN (
                         SELECT ref_dest
                           FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
                          WHERE renewal_date + INTERVAL 1 YEAR + INTERVAL $days_after_expired DAY <= '$current_date'
                         )
-                    AND contact_role <> 30"
+                    AND contact_role <> " . $restrictedRole
             );
         }
 
index c3de638..3c6ea00 100644 (file)
@@ -348,40 +348,43 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
 
                 // If the member_type is changing then update member
                 // Get current member type
-                // $member_id = filter_var( $_REQUEST['member'], FILTER_VALIDATE_INT );
-                // if ( $member_id ) {
-                //     $current_member_type = $this->wpdb->get_var(
-                //         $this->wpdb->prepare(
-                //             "SELECT member_type
-                //                FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
-                //               WHERE id = %d",
-                //             $member_id
-                //         )
-                //     );
-                //     $new_type = filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT );
-                //     $new_member_type = $this->wpdb->get_var(
-                //         $this->wpdb->prepare(
-                //             "SELECT member_type
-                //                FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types
-                //               WHERE id = %d",
-                //             $new_type
-                //         )
-                //     );
-                //     if ( $current_member_type != $new_member_type ) {
-                //         $this->update(
-                //             GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members',
-                //             array( 'member_type' => $new_member_type ),
-                //             array( 'id' => $member_id ),
-                //             array( '%d' ),
-                //             array( '%d' )
-                //         );
-                //     }
-                // }
+                $member_id = filter_var( $_REQUEST['member'], FILTER_VALIDATE_INT );
+                if ( $member_id ) {
+                    $current_member_type = $this->wpdb->get_var(
+                        $this->wpdb->prepare(
+                            "SELECT member_type
+                               FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+                              WHERE id = %d",
+                            $member_id
+                        )
+                    );
+                    $new_type = filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT );
+                    $new_member_type = $this->wpdb->get_var(
+                        $this->wpdb->prepare(
+                            "SELECT member_type
+                               FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types
+                              WHERE id = %d",
+                            $new_type
+                        )
+                    );
+                    // TODO: Need to reset account invoice_type also
+                    if ( $current_member_type != $new_member_type ) {
+                        $this->update(
+                            GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members',
+                            array( 'member_type' => $new_member_type ),
+                            array( 'id' => $member_id ),
+                            array( '%d' ),
+                            array( '%d' )
+                        );
+                    }
+                }
             }
 
             break;
 
         case 'account':
+
+
             // Need to see if there's an account for this member.
             $accountID = $this->wpdb->get_var(
                 $this->wpdb->prepare(
@@ -391,6 +394,22 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                     $this->memberID
                 )
             );
+
+            // $contactID = $this->wpdb->get_var(
+            //     $this->wpdb->prepare(
+            //         "SELECT id
+            //            FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts
+            //           WHERE ref_dest = %d",
+            //         $this->memberID
+            //     )
+            // );
+            // echo '<pre>$contactID: ' . print_r( $contactID, true ) . '</pre>';
+            // require_once GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH . '/data/dataContacts.php';
+            // $Contact = new GlmDataContacts( $this->wpdb, $this->config );
+            // $user_id = $Contact->getWPUserId( $contactID );
+            // echo '<pre>$user_id: ' . print_r( $user_id, true ) . '</pre>';
+            // $Contact->updateContactRole( $contactID, 'glm_members_member_contact', 'glm_members_own_entity_manager' );
+
             // echo '<pre>$accountID: ' . print_r( $accountID, true ) . '</pre>';
             // Grab the employee data
             if ( $accountID ) {
index b01821f..5c820aa 100644 (file)
@@ -260,7 +260,7 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling
             }
             // 3. Setup the contact (and wpUser)
             // Determine the Worpress Role to be used for contact import - Using Entity Manager right now
-            $contactRoleNumb    = $this->config['contact_role_numb']['EntityManager'];
+            $contactRoleNumb    = $this->config['contact_role_numb']['LogInContact'];
             $wpRole             = $this->config['contact_role_wordpress'][$contactRoleNumb];
             $memberContactEmail = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL );
             $memberLogin        = filter_var( $_REQUEST['username'] );
@@ -463,10 +463,23 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling
 
                     // Check for any notices for new members and send them out for this new member.
                     $Notification = new GlmNotifications( $this->wpdb, $this->config );
-                    $notification = $Notification->getNotificationsByType( 'New Member' );
-                    if ( $notification ) {
-                        $Notification->sendEmailNotification( $notification, $accountID );
+
+                    // Get all new member notifications for the member and if found send them out.
+                    $newMemberNotices = $Notification->getNotificationsByType( 'New Member' );
+                    if ( $newMemberNotices ) {
+                        foreach ( $newMemberNotices as $notification ) {
+                            $Notification->sendEmailNotification( $notification['id'], $accountID );
+                        }
+                    }
+
+                    // Get all new member admin notifications for the member and if found send them out.
+                    $adminNewMemberNotices = $Notification->getNotificationsByType( 'New Member Admin Notice' );
+                    if ( $adminNewMemberNotices ) {
+                        foreach ( $adminNewMemberNotices as $notification ) {
+                            $Notification->sendEmailNotification( $notification['id'], $accountID );
+                        }
                     }
+
                 }
             }
             break;
index 2c6f533..235b394 100644 (file)
@@ -34,22 +34,33 @@ add_filter(
     1
 );
 
-// add_filter(
-//     'glm_associate_cron_request',
-//     function( $cron_task ){
-//         $new_cron = array(
-//             array(
-//                 'menu'       => 'ajax',
-//                 'action'     => 'billingFlagExpiredUsers',
-//                 'daysOfWeek' => range( 1, 7 ),
-//                 'times'      => range( 1, 24 ),
-//                 'params'     => array()
-//             )
-//         );
-//         return array_merge( $cron_task, $new_cron );
-//     }
-// );
-//
+/**
+ * Setup cron task request to run billingFlagExpiredUsers
+ *
+ * Run only once per day. Everyday.
+ */
+add_filter(
+    'glm_associate_cron_request',
+    function( $cron_task ){
+        $new_cron = array(
+            array(
+                'menu'       => 'ajax',
+                'action'     => 'billingFlagExpiredUsers',
+                'daysOfWeek' => range( 1, 7 ),
+                // 'times'      => array( 5 ),
+                'times'      => range( 0, 23 ),
+                'params'     => array()
+            )
+        );
+        return array_merge( $cron_task, $new_cron );
+    }
+);
+
+/**
+ * Setup cron task request to run billingSetupQueue
+ *
+ * Run only once per day. Everyday.
+ */
 // add_filter(
 //     'glm_associate_cron_request',
 //     function( $cron_task ) {
@@ -58,14 +69,19 @@ add_filter(
 //                 'menu'       => 'ajax',
 //                 'action'     => 'billingSetupQueue',
 //                 'daysOfWeek' => range( 1, 7 ),
-//                 'times'      => range( 3 ),
+//                 'times'      => array( 3 ),
 //                 'params'     => array()
 //             )
 //         );
 //         return array_merge( $cron_task, $new_cron );
 //     }
 // );
-//
+
+/**
+ * Setup cron task request to run billingRunQueue
+ *
+ * Run only once per day. Everyday.
+ */
 // add_filter(
 //     'glm_associate_cron_request',
 //     function( $cron_task ) {
@@ -74,7 +90,7 @@ add_filter(
 //                 'menu'       => 'ajax',
 //                 'action'     => 'billingRunQueue',
 //                 'daysOfWeek' => range( 1, 7 ),
-//                 'times'      => range( 4 ),
+//                 'times'      => array( 4 ),
 //                 'params'     => array()
 //             )
 //         );
index a9b4363..95b351b 100644 (file)
@@ -47,6 +47,7 @@ add_filter( 'glm-billing-get-account-status', function( $content, $account_id ){
             return $content;
         }
         // See if this member account has a paid member type
+        require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/billingSupport.php';
         $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
         $paid_mem_type  = $BillingSupport->getMembersInvoiceTypeByRefDest( $account['ref_dest'] );
         if ( !$paid_mem_type ) {
index 38140a6..a84baec 100644 (file)
 <table class="wp-list-table widefat fixed posts glm-admin-table">
     <thead>
         <tr>
-            <th>ID</th>
+            <th style="width:50px;">ID</th>
             <th>Notification</th>
             <th>Subject</th>
             <th>Trigger</th>
                 {else}
                     <tr class="alternate">
                 {/if}
-                    <td>{$t.id}</td>
+                    <td style="width:50px;">{$t.id}</td>
                     <td>
                         <div>
-                            <a
-                                href="{$thisUrl}?page={$thisPage}&glm_action=notificationTypes&option=edit&id={$t.id}"
-                                data-notification-id="{$t.id}"
-                                data-notification-name="{$t.name}"
-                                data-notification-sendbydate="{$t.send_by_date.value}"
-                                data-notification-sendbyaction="{$t.send_by_action.value}"
-                                data-notification-sendaction="{$t.send_action}"
-                                data-notification-fromheader="{$t.from_header}"
-                                data-notification-replyto="{$t.replyto}"
-                                data-notification-subject="{$t.subject}"
-                                data-notification-message="{$t.message}"
-                                data-notification-senddatenumber="{$t.send_date_number}"
-                                data-notification-senddateperiod="{$t.send_date_period}"
-                                data-notification-senddatewhen="{$t.send_date_when}"
-                            >{$t.name}</a>
+                            <a href="{$thisUrl}?page={$thisPage}&glm_action=notificationTypes&option=edit&id={$t.id}" data-notification-id="{$t.id}">{$t.name}</a>
                         </div>
                     </td>
                     <td>{$t.subject}</td>
 <script type="text/javascript">
     jQuery(document).ready(function($) {
 
-        $("#newNotificationTypeDialog").dialog({
-            autoOpen: false,
-            minWidth: 400,
-            dialogClass: "glm-dialog-no-close"
-        });
-        $("#editNotificationTypeDialog").dialog({
-            autoOpen: false,
-            minWidth: 400,
-            dialogClass: "glm-dialog-no-close"
-        });
         $("#deleteNotificationTypeDialog").dialog({
             autoOpen: false,
             minWidth: 400,
             dialogClass: "glm-dialog-no-close"
         });
 
-        // $('#newNotificationTypeButton').click( function() {
-        //     $("#newNotificationTypeDialog").dialog("open");
-        // });
-        $('.editNotificationType').click( function() {
-            $('#editRecurring').prop( 'checked', false );
-
-            var notificationID             = $(this).data('notification-id');
-            var notificationName           = $(this).data('notification-name');
-            var notificationSendByDate     = $(this).data('notification-sendbydate');
-            var notificationSendByAction   = $(this).data('notification-sendbyaction');
-            var notificationSendAction     = $(this).data('notification-sendaction');
-            var notificationFromHeader     = $(this).data('notification-fromheader');
-            var notificationRepyTo         = $(this).data('notification-replyto');
-            var notificationSubject        = $(this).data('notification-subject');
-            var notificationMessage        = $(this).data('notification-message');
-            var notificationSendDateNumber = $(this).data('notification-senddatenumber');
-            var notificationSendDatePeriod = $(this).data('notification-senddateperiod');
-            var notificationSendDateWhen   = $(this).data('notification-senddatewhen');
-
-            // Set the values of the edit form for the selected notificationType
-            $('#edit-id').val( notificationID );
-            $('#edit-name').val( notificationName );
-            $('#edit-senddatenumber').val( notificationSendDateNumber );
-            $('#edit-senddateperiod').val( notificationSendDatePeriod );
-            $('#edit-senddatewhen').val( notificationSendDateWhen );
-            $('#edit-sendaction').val( notificationSendAction );
-            $('#edit-fromheader').val( notificationFromHeader );
-            $('#edit-replyto').val( notificationRepyTo );
-            $('#edit-subject').val( notificationSubject );
-            $('#edit-message').val( notificationMessage );
-            if ( notificationSendByDate ) {
-                $('#edit-sendbydate').prop('checked', true);
-            }
-            if ( notificationSendByAction ) {
-                $('#edit-sendbyaction').prop('checked', true);
-            }
-
-            $("#editNotificationTypeDialog").dialog("open");
-        });
-        $('#editNotificationTypeCancel').click( function() {
-            $("#editNotificationTypeDialog").dialog("close");
-        });
-        $('#newNotificationTypeCancel').click( function() {
-            $("#newNotificationTypeDialog").dialog("close");
-        });
 
         var id = false;
         $('.deleteNotificationTypeButton').click( function() {