}
// 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[] = '<span style="color:red;">An error occurred! invoice_type_data</span>';
+ }
+ echo '<pre>$invoice_type_data: ' . print_r( $invoice_type_data, true ) . '</pre>';
+ $member_type = $invoice_type_data['member_type'];
+ if ( !$member_type ) {
+ $error = true;
+ $messages[] = '<span style="color:red;">An error occurred! member_type</span>';
+ }
+ echo '<pre>$member_type: ' . print_r( $member_type, true ) . '</pre>';
+ // 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 '<pre>$member_id: ' . print_r( $member_id, true ) . '</pre>';
+ if ( !$member_id ) {
+ $error = true;
+ $messages[] = '<span style="color:red;">An error occurred! member_id</span>';
+ } else {
+ $member = $this->wpdb->get_row(
+ $this->wpdb->prepare(
+ "SELECT *
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE id = %d",
+ $member_id
+ )
+ );
+ echo '<pre>$member: ' . print_r( $member, true ) . '</pre>';
+ }
// 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 '<pre>$billing_city_id: ' . print_r( $billing_city_id, true ) . '</pre>';
+ $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[] = '<span style="color:red;">An error occurred! member_info_id</span>';
+ } 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 '<pre>$member_info: ' . print_r( $member_info, true ) . '</pre>';
+ }
// 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 '<pre>$new_contact: ' . print_r( $new_contact, true ) . '</pre>';
+ } else {
+ // $this->wpdb->print_error();
+ $error = true;
+ $messages[] = '<span style="color:red;">An error occurred! newContactID</span>';
+ }
+ $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 '<pre>$wpUserID: ' . print_r( $wpUserID, true ) . '</pre>';
+ } else {
+ $error = true;
+ $messages[] = '<span style="color:red;">An error occurred! wpUserID</span>';
+ }
// 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 '<pre>$customFieldId: ' . print_r( $customFieldId, true ) . '</pre>';
+ } else {
+ $error = true;
+ $messages[] = '<span style="color:red;">An error occurred! customFieldId</span>';
+ }
+ }
+ }
+ }
+ // 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:
}
+ 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;
+ }
+
}