From: Steve Sutton Date: Tue, 24 Apr 2018 18:44:43 +0000 (-0400) Subject: working on the become a member form X-Git-Tag: v1.0.0^2~38 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=8b3e92a0f03df1b4bb867adb249c19f6748b908c;p=WP-Plugins%2Fglm-member-db-billing.git working on the become a member form Have it adding member, contact, custom fields, account,member_info. --- diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index a6df1a3..726c838 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -222,6 +222,10 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; $account = $Accounts->editEntry( $accountID ); + // Need to get the accounts + $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); + $accounts = $Accounts->getSimpleAccountList( "T.boss <> true AND T.boss IS NOT NULL AND T.invoice_type != 0", 'ref_name' ); + break; case 'renewMembership': @@ -468,7 +472,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling // $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); // Need to get the accounts $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); - $accounts = $Accounts->getSimpleAccountList( "T.boss <> true AND T.boss IS NOT NULL", 'ref_name' ); + $accounts = $Accounts->getSimpleAccountList( "T.boss <> true AND T.boss IS NOT NULL AND T.invoice_type != 0", 'ref_name' ); if ( !$account ) { if ( $accountID ) { diff --git a/models/front/billing/becomeMember.php b/models/front/billing/becomeMember.php index 8456b92..84e4116 100644 --- a/models/front/billing/becomeMember.php +++ b/models/front/billing/becomeMember.php @@ -144,43 +144,261 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling } // Process the main form // 1. Setup the member - $memberData = array( - 'access' => $access, - 'member_type' => $memberType, - 'created' => date( 'Y-m-d' ), - 'member_slug' => $memberSlug, + $member_fname = filter_var( $_REQUEST['fname'], FILTER_SANITIZE_STRING ); + $member_lname = filter_var( $_REQUEST['lname'], FILTER_SANITIZE_STRING ); + $member_name = $member_lname . ', ' . $member_fname; + $invoice_type = filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT ); + // Member type is based on the renewing_member field (invoice_types) + $invoice_type_data = $BillingSupport->getInvoiceTypeById( $invoice_type ); + if ( !$invoice_type_data ) { + $error = true; + $messages[] = 'An error occurred! invoice_type_data'; + } + echo '
$invoice_type_data: ' . print_r( $invoice_type_data, true ) . '
'; + $member_type = $invoice_type_data['member_type']; + if ( !$member_type ) { + $error = true; + $messages[] = 'An error occurred! member_type'; + } + echo '
$member_type: ' . print_r( $member_type, true ) . '
'; + // Start database transaction + // $this->wpdb->show_errors(); + $this->wpdb->query('START TRANSACTION'); + // $access = $this->config['access_numb']['Full']; + $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members', + array( + 'access' => 40, // Not Moderated + 'member_type' => $member_type, + 'created' => date( 'Y-m-d' ), + 'name' => $member_name, + 'member_slug' => sanitize_title( $member_name ), + ), + array( + '%d',// access + '%d',// member_type + '%s',// created + '%s',// name + '%s',// member_slug + ) ); + $member_id = $this->wpdb->insert_id; + echo '
$member_id: ' . print_r( $member_id, true ) . '
'; + if ( !$member_id ) { + $error = true; + $messages[] = 'An error occurred! member_id'; + } else { + $member = $this->wpdb->get_row( + $this->wpdb->prepare( + "SELECT * + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members + WHERE id = %d", + $member_id + ) + ); + echo '
$member: ' . print_r( $member, true ) . '
'; + } // 2. Setup the member_info - $memberInfoData = array( - 'member', - 'member_name', - 'status', - 'reference_name', - 'descr', - 'short_descr', - 'addr1', - 'addr2', - 'city', - 'state', - 'country', - 'zip', - 'region', - 'county', - 'phone', - 'toll_free', - 'url', - 'email', - 'mailing_addr1', - 'mailing_addr2', - 'mailing_city', - 'mailing_state', - 'mailing_zip', - 'create_time', + $billing_addr1 = filter_var( $_REQUEST['billing_addr1'] ); + $billing_city = filter_var( $_REQUEST['billing_city'] ); + $billing_city_id = $this->getCityId( $billing_city ); + echo '
$billing_city_id: ' . print_r( $billing_city_id, true ) . '
'; + $billing_state = filter_var( $_REQUEST['billing_state'] ); + $billing_zip = filter_var( $_REQUEST['billing_zip'] ); + $phone = filter_var( $_REQUEST['phone'] ); + $website = filter_var( $_REQUEST['website'] ); + $email_on_website = filter_var( $_REQUEST['email_on_website'] ); + + $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'member_info', + array( + 'member' => $member_id, + 'member_name' => $member_name, + 'status' => 10, + 'reference_name' => 'new member form', + 'addr1' => $billing_addr1, + 'city' => $billing_city_id, + 'state' => $billing_state, + 'zip' => $billing_zip, + 'phone' => $phone, + 'url' => $website, + 'email' => $email_on_website, + 'create_time' => date( 'Y-m-d' ), + ), + array( + '%d', // member + '%s', // member_name + '%d', // status + '%s', // reference_name + '%s', // addr1 + '%d', // city + '%s', // state + '%s', // zip + '%s', // phone + '%s', // url + '%s', // email + '%s', // create_time + ) ); + $member_info_id = $this->wpdb->insert_id; + if ( !$member_info_id ) { + $error = true; + $messages[] = 'An error occurred! member_info_id'; + } else { + $member_info = $this->wpdb->get_row( + $this->wpdb->prepare( + "SELECT * + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info + WHERE id = %d", + $member_info_id + ) + ); + echo '
$member_info: ' . print_r( $member_info, true ) . '
'; + } // 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']; + $wpRole = $this->config['contact_role_wordpress'][$contactRoleNumb]; + $memberContactEmail = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL ); + $memberLogin = filter_var( $_REQUEST['username'] ); + $this->wpdb->insert( + GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . 'contacts', + array( + 'active' => true, + 'primary_contact' => true, + 'access' => $this->config['access_numb']['Full'], + 'fname' => $member_fname, + 'lname' => $member_lname, + 'contact_type' => $this->config['contact_type_numb']['Personal'], + 'contact_role' => $contactRoleNumb, + 'email' => $memberContactEmail, + 'username' => $memberLogin, + 'notes' => 'Become Member Form.', + 'create_time' => date('Y-m-d H:i:s', time()), + 'ref_type' => $this->config['ref_type_numb']['Member'], + 'ref_dest' => $member_id + ), + array( + '%d', // active + '%d', // primary_contact + '%d', // access + '%s', // fname + '%s', // lname + '%d', // contact_type + '%d', // contact_role + '%s', // email + '%s', // username + '%s', // notes + '%s', // create_time + '%d', // ref_type + '%d', // ref_dest + ) + ); + $newContactID = $this->wpdb->insert_id; + if ( $newContactID ) { + $new_contact = $this->wpdb->get_row( + $this->wpdb->prepare( + "SELECT * + FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts + WHERE id = %d", + $newContactID + ) + ); + echo '
$new_contact: ' . print_r( $new_contact, true ) . '
'; + } else { + // $this->wpdb->print_error(); + $error = true; + $messages[] = 'An error occurred! newContactID'; + } + $memberPasswd = filter_var( $_REQUEST['password'] ); + $wpUserID = wp_insert_user( + array( + 'user_email' => $memberContactEmail, + 'user_login' => $memberLogin, + 'user_pass' => $memberPasswd, + 'first_name' => $member_fname, + 'last_name' => $member_lname, + 'role' => $wpRole + ) + ); + if (is_int($wpUserID) && $wpUserID > 0) { + // Store the contact ID and active status into user meta data. + update_user_meta($wpUserID, 'glmMembersContactID', $newContactID); + update_user_meta($wpUserID, 'glmMembersContactActive', true); + echo '
$wpUserID: ' . print_r( $wpUserID, true ) . '
'; + } else { + $error = true; + $messages[] = 'An error occurred! wpUserID'; + } // 4. Setup the custom fields - // Process any custom fields + if ( isset( $_REQUEST['cf'] ) && !empty( $_REQUEST['cf'] ) ) { + foreach ( $_REQUEST['cf'] as $customFieldKey => $customFieldValue ) { + $customFieldKey = filter_var( $customFieldKey, FILTER_VALIDATE_INT ); + $customFieldValue = filter_var( $customFieldValue ); + if ( $customFieldKey && $customFieldValue ) { + $this->wpdb->insert( + GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . 'custom_field_data', + array( + 'entity_id' => $newContactID, + 'field_id' => $customFieldKey, + 'field_data' => $customFieldValue + ), + array( + '%d', + '%d', + '%s' + ) + ); + $customFieldId = $this->wpdb->insert_id; + if ( $customFieldId ) { + echo '
$customFieldId: ' . print_r( $customFieldId, true ) . '
'; + } else { + $error = true; + $messages[] = 'An error occurred! customFieldId'; + } + } + } + } + // Setup billing account + $this->wpdb->insert( + GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts', + array( + 'ref_dest' => $member_id, + 'ref_name' => $member_name, + 'anniversary_date' => date( 'Y-m-d' ), + 'boss' => false, + 'invoice_type' => $invoice_type, + 'billing_fname' => $billing_fname, + 'billing_lname' => $billing_lname, + 'billing_addr1' => $billing_addr1, + 'billing_city' => $billing_city, + 'billing_state' => $billing_state, + 'billing_phone' => $billing_phone, + 'email' => $memberContactEmail, + ), + array( + '%d', // ref_dest + '%s', // ref_name + '%s', // anniversary_date + '%d', // boss + '%d', // invoice_type + '%s', // billing_fname + '%s', // billing_lname + '%s', // billing_addr1 + '%s', // billing_city + '%s', // billing_state + '%s', // billing_phone + '%s', // email + ) + ); + // Save or rollback + if ( $error ) { + $this->wpdb->query('ROLLBACK'); + } else { + $this->wpdb->query('COMMIT'); + $view = 'thankyou'; + } break; default: @@ -217,5 +435,27 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling } + public function getCityId( $city_name ) + { + // First try to get city id + $city_id = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities + WHERE name = %s", + $city_name + ) + ); + if ( $city_id ) { + return $city_id; + } + $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'cities', + array( 'name' => $city_name ), + array( '%s' ) + ); + return $this->wpdb->insert_id; + } + } diff --git a/views/admin/billing/renew.html b/views/admin/billing/renew.html index 8b978a7..5ab1fec 100644 --- a/views/admin/billing/renew.html +++ b/views/admin/billing/renew.html @@ -76,6 +76,7 @@ Associated Members/Employees
+ {foreach $employees as $employee} @@ -127,6 +128,33 @@