Update to check for member name match
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 8 Apr 2019 13:13:20 +0000 (09:13 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 8 Apr 2019 13:14:07 +0000 (09:14 -0400)
If the member name already exists then give a error message.

index.php
models/front/billing/becomeMember.php
views/front/billing/becomeMember.html

index 71a72d4..35ececd 100644 (file)
--- a/index.php
+++ b/index.php
@@ -3,7 +3,7 @@
  * Plugin Name: GLM Members Billing
  * Plugin URI: http://www.gaslightmedia.com/
  * Description: This is glmAssociate Billing Module
- * Version: 1.0.25
+ * Version: 1.0.26
  * Author: Gaslight Media
  * Author URI: http://www.gaslightmedia.com/
  * License: GPL2
@@ -19,7 +19,7 @@
  * @package glmMembersBillingAddOn
  * @author Chuck Scott <cscott@gaslightmedia.com>
  * @license http://www.gaslightmedia.com Gaslightmedia
- * @version 1.0.25
+ * @version 1.0.26
  */
 
 /*
@@ -37,7 +37,7 @@
  *  so that we're sure the other add-ons see an up to date
  *  version from this plugin.
  */
-define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.25');
+define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.26');
 define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.26');
 
 // This is the minimum version of the GLM Members DB plugin require for this plugin.
index 5c6eba7..89e59e7 100644 (file)
@@ -173,6 +173,21 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling
             $member_fname = filter_var( $_REQUEST['fname'], FILTER_SANITIZE_STRING );
             $member_lname = filter_var( $_REQUEST['lname'], FILTER_SANITIZE_STRING );
             $member_name  = $member_lname . ', ' . $member_fname;
+            // Check member name. If it matches then give error member already exists
+            $memberAlreadyExist = $this->wpdb->get_var(
+                $this->wpdb->prepare(
+                    "SELECT id
+                       FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info
+                      WHERE member_name = %s",
+                    $member_name
+                )
+            );
+            // echo '<pre>$memberAlreadyExist: ' . print_r( $memberAlreadyExist, true ) . '</pre>';
+            if ( $memberAlreadyExist ) {
+                $error = true;
+                $messages[] = $errors['member_name'] = "<span style='color: red;'>There's a Member with that Name already!</span>";
+            }
+
             $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 );
@@ -186,365 +201,367 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling
                 $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
+            if ( !$error ) { // first error check
+                // 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
                     )
                 );
-                // echo '<pre>$member: ' . print_r( $member, true ) . '</pre>';
-            }
-            // 2. Setup the member_info
-            $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
+                $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
+                $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
                     )
                 );
-                // 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']['LogInContact'];
-            $wpRole             = $this->config['contact_role_wordpress'][$contactRoleNumb];
-            $memberContactEmail = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL );
-            $memberLogin        = filter_var( $_REQUEST['username'] );
-            $org                = filter_var( $_REQUEST['org'] );
-            $title              = filter_var( $_REQUEST['title'] );
-            $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,
-                    'org'              => $org,
-                    'title'            => $title,
-                    'business_fname'   => $member_fname,
-                    'business_lname'   => $member_lname,
-                    'business_addr1'   => $billing_addr1,
-                    'business_city'    => $billing_city_id,
-                    'business_state'   => $billing_state,
-                    'business_zip'     => $billing_zip,
-                    'business_publish' => 1
-                ),
-                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
-                    '%s', // org
-                    '%s', // title
-                    '%s', // business_fname
-                    '%s', // business_lname
-                    '%s', // business_addr1
-                    '%s', // business_city
-                    '%s', // business_state
-                    '%s', // business_zip
-                    '%s', // business_publish
-                )
-            );
-            $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
+                $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']['LogInContact'];
+                $wpRole             = $this->config['contact_role_wordpress'][$contactRoleNumb];
+                $memberContactEmail = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL );
+                $memberLogin        = filter_var( $_REQUEST['username'] );
+                $org                = filter_var( $_REQUEST['org'] );
+                $title              = filter_var( $_REQUEST['title'] );
+                $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,
+                        'org'              => $org,
+                        'title'            => $title,
+                        'business_fname'   => $member_fname,
+                        'business_lname'   => $member_lname,
+                        'business_addr1'   => $billing_addr1,
+                        'business_city'    => $billing_city_id,
+                        'business_state'   => $billing_state,
+                        'business_zip'     => $billing_zip,
+                        'business_publish' => 1
+                    ),
+                    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
+                        '%s', // org
+                        '%s', // title
+                        '%s', // business_fname
+                        '%s', // business_lname
+                        '%s', // business_addr1
+                        '%s', // business_city
+                        '%s', // business_state
+                        '%s', // business_zip
+                        '%s', // business_publish
+                    )
+                );
+                $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
                     )
                 );
-                // 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
-                )
-            );
-            // echo '<pre>$wpUserID: ' . print_r( $wpUserID, true ) . '</pre>';
-            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 if ( is_wp_error( $wpUserID ) ) {
-                $error = true;
-                $messages[''] = $errors['username'] = '<span style="color:red;">An error occurred! ' . $wpUserID->get_error_message() . '</span>';
-            } 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 ) {
-                        if ( in_array( $customFieldKey, array( 2, 3 ) ) ) {
-                            $customFieldValue = 'Yes';
-                        }
-                        $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>';
+                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 if ( is_wp_error( $wpUserID ) ) {
+                    $error = true;
+                    $messages[''] = $errors['username'] = '<span style="color:red;">An error occurred! ' . $wpUserID->get_error_message() . '</span>';
+                } 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 ) {
+                            if ( in_array( $customFieldKey, array( 2, 3 ) ) ) {
+                                $customFieldValue = 'Yes';
+                            }
+                            $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'    => $member_fname,
-                    'billing_lname'    => $member_lname,
-                    'billing_addr1'    => $billing_addr1,
-                    'billing_city'     => $billing_city,
-                    'billing_state'    => $billing_state,
-                    'billing_zip'      => $billing_zip,
-                    '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_zip
-                    '%s', // billing_phone
-                    '%s', // email
-                )
-            );
-            $accountID = $this->wpdb->insert_id;
-            if ( !$accountID ) {
-                $error = true;
-                $messages[] = '<span style="color:red;">An error occurred! accountID</span>';
-            }
-            // Save or rollback
-            if ( $error ) {
-            } else {
-                // $this->wpdb->query('ROLLBACK');
-
-                // Fetch the invoice type chosen by the member.
-                $member_invoice = $BillingSupport->getInvoiceTypeById( $invoice_type );
-                // Here we'll create the invoice for the member.
-                $invoice_data = array(
-                    'account_id'     => $accountID,
-                    'renew_type_id'  => $invoice_type,
-                    'amount'         => $_REQUEST['total_renew_amount'],
-                    'due_date'       => date( 'Y-m-d' ),
-                    'member_invoice' => $member_invoice,
-                    'employee_data'  => array(),
-                    'employees'      => array(),
+                // 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'    => $member_fname,
+                        'billing_lname'    => $member_lname,
+                        'billing_addr1'    => $billing_addr1,
+                        'billing_city'     => $billing_city,
+                        'billing_state'    => $billing_state,
+                        'billing_zip'      => $billing_zip,
+                        '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_zip
+                        '%s', // billing_phone
+                        '%s', // email
+                    )
                 );
-                $invoice_id = $BillingSupport->createMemberInvoiceWithEmployees( $invoice_data );
-                if ( !$invoice_id ) {
-                    $this->wpdb->print_error();
+                $accountID = $this->wpdb->insert_id;
+                if ( !$accountID ) {
                     $error = true;
-                    $messages[] = '<span style="color:red;">An error occurred! invoice_id</span>';
+                    $messages[] = '<span style="color:red;">An error occurred! accountID</span>';
                 }
-                if ( !$error ) {
-
-                    // Get payment type and process.
-                    $payment_option = filter_var( $_REQUEST['payment_option'], FILTER_SANITIZE_STRING );
-                    switch ( $payment_option ) {
-                    case 'pay_by_credit_card':
-                        // Setup $_REQUEST ARRAY for billing
-                        $_REQUEST['billing_fname'] = $member_fname;
-                        $_REQUEST['billing_lname'] = $member_lname;
-                        $_REQUEST['billing_addr1'] = $billing_addr1;
-                        $_REQUEST['billing_city']  = $billing_city;
-                        $_REQUEST['billing_state'] = $billing_state;
-                        $_REQUEST['billing_zip']   = $billing_zip;
-                        $_REQUEST['billing_phone'] = $billing_phone;
-                        $_REQUEST['email']         = $memberContactEmail;
-                        // Do the Payment Processing.
-                        $processErrors = $BillingSupport->processMemberRenewal( $accountID, $invoice_id, $invoice_data['amount'], $invoice_data['employees'] );
-                        if ( $processErrors ) {
-                            // if ( count( $processErrors ) > 0 ) {
-                            //     $error = true;
-                            //     $error_message = ( isset( $processErrors[0] ) && $processErrors[0] ) ? $processErrors[0] : 'There was an error trying to process your card!';
-                            //     $messages[] = '<span style="color:red;">An error occurred! ' . $error_message . '</span>';
-                            // }
-                            if ( isset( $processErrors ) && is_array( $processErrors ) && count( $processErrors ) > 0 ) {
-                                $error = true;
-                                foreach ( $processErrors as $error ) {
-                                    $messages[] = '<span style="color: red;">'.$error.'</span>';
+                // Save or rollback
+                if ( $error ) {
+                } else {
+                    // $this->wpdb->query('ROLLBACK');
+
+                    // Fetch the invoice type chosen by the member.
+                    $member_invoice = $BillingSupport->getInvoiceTypeById( $invoice_type );
+                    // Here we'll create the invoice for the member.
+                    $invoice_data = array(
+                        'account_id'     => $accountID,
+                        'renew_type_id'  => $invoice_type,
+                        'amount'         => $_REQUEST['total_renew_amount'],
+                        'due_date'       => date( 'Y-m-d' ),
+                        'member_invoice' => $member_invoice,
+                        'employee_data'  => array(),
+                        'employees'      => array(),
+                    );
+                    $invoice_id = $BillingSupport->createMemberInvoiceWithEmployees( $invoice_data );
+                    if ( !$invoice_id ) {
+                        $this->wpdb->print_error();
+                        $error = true;
+                        $messages[] = '<span style="color:red;">An error occurred! invoice_id</span>';
+                    }
+                    if ( !$error ) {
+
+                        // Get payment type and process.
+                        $payment_option = filter_var( $_REQUEST['payment_option'], FILTER_SANITIZE_STRING );
+                        switch ( $payment_option ) {
+                        case 'pay_by_credit_card':
+                            // Setup $_REQUEST ARRAY for billing
+                            $_REQUEST['billing_fname'] = $member_fname;
+                            $_REQUEST['billing_lname'] = $member_lname;
+                            $_REQUEST['billing_addr1'] = $billing_addr1;
+                            $_REQUEST['billing_city']  = $billing_city;
+                            $_REQUEST['billing_state'] = $billing_state;
+                            $_REQUEST['billing_zip']   = $billing_zip;
+                            $_REQUEST['billing_phone'] = $billing_phone;
+                            $_REQUEST['email']         = $memberContactEmail;
+                            // Do the Payment Processing.
+                            $processErrors = $BillingSupport->processMemberRenewal( $accountID, $invoice_id, $invoice_data['amount'], $invoice_data['employees'] );
+                            if ( $processErrors ) {
+                                // if ( count( $processErrors ) > 0 ) {
+                                //     $error = true;
+                                //     $error_message = ( isset( $processErrors[0] ) && $processErrors[0] ) ? $processErrors[0] : 'There was an error trying to process your card!';
+                                //     $messages[] = '<span style="color:red;">An error occurred! ' . $error_message . '</span>';
+                                // }
+                                if ( isset( $processErrors ) && is_array( $processErrors ) && count( $processErrors ) > 0 ) {
+                                    $error = true;
+                                    foreach ( $processErrors as $error ) {
+                                        $messages[] = '<span style="color: red;">'.$error.'</span>';
+                                    }
+                                } else if ( isset( $processErrors ) && $processErrors ) {
+                                    $error = true;
+                                    $messages[] = '<span style="color: red;">'.$processErrors.'</span>';
                                 }
-                            } else if ( isset( $processErrors ) && $processErrors ) {
-                                $error = true;
-                                $messages[] = '<span style="color: red;">'.$processErrors.'</span>';
                             }
+
+                            break;
+                        case 'pay_by_check':
+                            break;
                         }
 
-                        break;
-                    case 'pay_by_check':
-                        break;
                     }
 
-                }
-
-                if ( $error ) {
-                    $this->wpdb->query('ROLLBACK');
-                } else {
-                    $this->wpdb->query('COMMIT');
-                    $invoiceHtml = $BillingSupport->viewInvoice( $invoice_id );
-                    $view = 'thankyou';
-                    // Send admin user email notification of new member
-
-                    // Check for any notices for new members and send them out for this new member.
-                    $Notification = new GlmNotifications( $this->wpdb, $this->config );
-
-                    // 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 );
+                    if ( $error ) {
+                        $this->wpdb->query('ROLLBACK');
+                    } else {
+                        $this->wpdb->query('COMMIT');
+                        $invoiceHtml = $BillingSupport->viewInvoice( $invoice_id );
+                        $view = 'thankyou';
+                        // Send admin user email notification of new member
+
+                        // Check for any notices for new members and send them out for this new member.
+                        $Notification = new GlmNotifications( $this->wpdb, $this->config );
+
+                        // 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 );
+                        // 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 );
+                            }
                         }
-                    }
 
+                    }
                 }
-            }
+            } // End of first error check
             break;
 
         default:
index 6d99adf..53bdd25 100644 (file)
@@ -69,6 +69,7 @@
                 required />
             </div>
         </div>
+        {if isset($errors.member_name) && $errors.member_name}<div>{$errors.member_name}</div>{/if}
         <div class="glm-billing-field glm-billing-left-half">
             <div class="glm-billing-label glm-required">
                 Email