Deal with wordpress user also when updating the contact_roles.
// 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'];
}
+ /**
+ * 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
*
*/
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
);
}
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"
{
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
);
}
// 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(
$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 ) {
}
// 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'] );
// 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;
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 ) {
// '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 ) {
// 'menu' => 'ajax',
// 'action' => 'billingRunQueue',
// 'daysOfWeek' => range( 1, 7 ),
-// 'times' => range( 4 ),
+// 'times' => array( 4 ),
// 'params' => array()
// )
// );
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 ) {
<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() {