$description .= $tax_deductible ? 'Tax deductible: Yes' : 'Tax deductible: No' . '<br>' . "\n";
    }
    // create a note w/out action
    bbconnect_workqueues_insert_action_item($author_id, $args["payment_method"] . ' Donation', $description, 'donation', $receipt_number);
    // if they where inactive, make active and update communication preferences.
    $active = get_user_meta($author_id, 'active', true);
    if ($active == 'false') {
        update_user_meta($author_id, 'receives_letters', 'true');
        update_user_meta($author_id, 'receives_newsletters', 'true');
    }
    update_user_meta($author_id, 'active', 'true');
}
// condition { action } -- Only offline donations
if ($offline == true && $frequency == 'one-off') {
    $description = 'We need to print receipt number ' . $receipt_number;
    // create a note w/ action
    bbconnect_workqueues_insert_action_item($author_id, 'Printed receipt required', $description, 'receipt-to-print', $receipt_number, true);
}
// condition { action } -- If the donation is large
if ($amount >= 500) {
    // create a note w/ action
    bbconnect_workqueues_insert_action_item($author_id, 'Large Donation', 'Arrange a phone call/email to thank the donor for a $' . $donations . ' AUD donation.', 'large-donation', $receipt_number, true);
}
// condition { action } -- If the donation is recurring
if (!empty($frequency) && preg_replace('/[^a-z0-9]/', '', strtolower($frequency)) != 'oneoff') {
    $regular_donor = get_user_meta($author_id, 'regular_donor', true);
    if ($regular_donor !== 'true') {
        bbconnect_workqueues_insert_action_item($author_id, 'New Recurring Donor', 'Arrange a phone call to thank the donor for initiating a recurring donation of $' . $donations . ' AUD/' . $frequency . '.', 'new-recurring-donor', $receipt_number, true);
        update_user_meta($author_id, 'regular_donor', 'true');
    }
}
/**
 * Get user by email, or create them if they don't exist
 * @param array $args
 * @param string $other
 * @param string $is_new_contact
 * @return boolean|number|unknown
 */
function bbconnect_get_user($args, $other = null, &$is_new_contact = false)
{
    extract($args);
    if (!isset($email)) {
        return false;
    }
    if (empty($country) && !empty($other['country'])) {
        $country = $other['country'];
    }
    if (email_exists($email)) {
        // Existing user
        $user = get_user_by('email', $email);
        $active = get_user_meta($user->ID, 'active', true);
        if ($active == 'false') {
            update_user_meta($user->ID, 'receives_letters', 'true');
            update_user_meta($user->ID, 'receives_newsletters', 'true');
            update_user_meta($user->ID, 'active', 'true');
        }
        if (function_exists('bbconnect_workqueues_insert_action_item')) {
            // Compare address details to those on record
            $dirty = false;
            $note_content = 'Submitted address details were different to those on file - please review' . "\n\n";
            $fields = array('title' => 'title', 'address1' => 'bbconnect_address_one_1', 'address2' => 'bbconnect_address_two_1', 'suburb' => 'bbconnect_address_city_1', 'state' => 'bbconnect_address_state_1', 'postcode' => 'bbconnect_address_postal_code_1');
            foreach ($fields as $varname => $metaname) {
                if (isset(${$varname})) {
                    $val = get_user_meta($user->ID, $metaname, true);
                    if (!bbconnect_address_compare(${$varname}, $val)) {
                        $note_content .= ucfirst($varname) . ':' . "\n";
                        $note_content .= 'Old Value: ' . $val . "\n";
                        $note_content .= 'New Value: ' . ${$varname} . "\n\n";
                        $dirty = true;
                    }
                }
            }
            // Phone and country are a bit special
            if (!empty($phone)) {
                $phone_data = get_user_meta($user->ID, 'telephone');
                foreach ($phone_data as $phone_number) {
                    if ($phone_number['type'] == 'home') {
                        if (!bbconnect_address_compare($phone, $phone_number['value'])) {
                            $note_content .= 'Phone:' . "\n";
                            $note_content .= 'Old Value: ' . $phone_number['value'] . "\n";
                            $note_content .= 'New Value: ' . $phone . "\n\n";
                            $dirty = true;
                        }
                    }
                }
            }
            if (!empty($country)) {
                $country = bbconnect_address_compare($country);
                $val = get_user_meta($user->ID, 'bbconnect_address_country_1', true);
                if (!bbconnect_address_compare($country, $val)) {
                    $note_content .= 'Country:' . "\n";
                    $note_content .= 'Old Value: ' . $val . "\n";
                    $note_content .= 'New Value: ' . $country . "\n\n";
                    $dirty = true;
                }
            }
            if ($dirty) {
                bbconnect_workqueues_insert_action_item($user->ID, 'Address Review', $note_content, 'address-review', '', true);
            }
        }
        return $user->ID;
    } else {
        // New user
        $user_name = wp_generate_password(8, false);
        $random_password = wp_generate_password(12, false);
        if (!isset($firstname) || !isset($lastname)) {
            return false;
        }
        $userdata = array('user_login' => $user_name, 'first_name' => $firstname, 'last_name' => $lastname, 'user_pass' => $random_password, 'user_email' => $email, 'user_nicename' => $firstname);
        $user_id = wp_insert_user($userdata);
        //On fail
        if (is_wp_error($user_id)) {
            return false;
        } else {
            update_user_meta($user_id, 'active', 'true');
            update_user_meta($user_id, 'receives_letters', 'true');
            update_user_meta($user_id, 'receives_newsletters', 'true');
            if (isset($title)) {
                update_user_meta($user_id, 'title', $title);
            }
            if (isset($address1)) {
                update_user_meta($user_id, 'bbconnect_address_one_1', $address1);
            }
            if (isset($address2)) {
                update_user_meta($user_id, 'bbconnect_address_two_1', $address2);
            }
            if (isset($suburb)) {
                update_user_meta($user_id, 'bbconnect_address_city_1', $suburb);
            }
            if (isset($state)) {
                update_user_meta($user_id, 'bbconnect_address_state_1', $state);
            }
            if (isset($postcode)) {
                update_user_meta($user_id, 'bbconnect_address_postal_code_1', $postcode);
            }
            if (!empty($country)) {
                $country = bbconnect_process_country($country);
                update_user_meta($user_id, 'bbconnect_address_country_1', $country);
            }
            update_user_meta($user_id, 'bbconnect_bbc_primary', 'address_1');
            if (!empty($phone)) {
                $phone_data = array(array('value' => $phone, 'type' => 'home'));
                update_user_meta($user_id, 'telephone', $phone_data);
            }
            if (function_exists('bbconnect_workqueues_insert_action_item')) {
                bbconnect_workqueues_insert_action_item($user_id, 'New Contact', 'New contact - please check and clean up data as needed', 'new-contact', '', true);
            }
            $is_new_contact = true;
            return $user_id;
        }
    }
    return false;
}
Example #3
0
function bbconnect_workqueues_add_to_work_queue($entry, $form)
{
    if (!empty($form['work_queue'])) {
        $args = array();
        foreach ($form['fields'] as $field) {
            $inputs = $field['inputs'];
            switch ($field['type']) {
                case 'email':
                    if (!empty($entry[$field['id']])) {
                        $args['email'] = $entry[$field['id']];
                    }
                    break;
                case 'name':
                    if (!empty($entry[(string) $inputs[0]['id']])) {
                        $args['firstname'] = $entry[(string) $inputs[0]['id']];
                    }
                    if (!empty($entry[(string) $inputs[1]['id']])) {
                        $args['lastname'] = $entry[(string) $inputs[1]['id']];
                    }
                    break;
                case 'address':
                    if (!empty($entry[(string) $inputs[0]['id']])) {
                        $args['address1'] = $entry[(string) $inputs[0]['id']];
                    }
                    if (!empty($entry[(string) $inputs[1]['id']])) {
                        $args['address2'] = $entry[(string) $inputs[1]['id']];
                    }
                    if (!empty($entry[(string) $inputs[2]['id']])) {
                        $args['suburb'] = $entry[(string) $inputs[2]['id']];
                    }
                    if (!empty($entry[(string) $inputs[3]['id']])) {
                        $args['state'] = $entry[(string) $inputs[3]['id']];
                    }
                    if (!empty($entry[(string) $inputs[4]['id']])) {
                        $args['postcode'] = $entry[(string) $inputs[4]['id']];
                    }
                    if (!empty($entry[(string) $inputs[5]['id']])) {
                        $args['country'] = $entry[(string) $inputs[5]['id']];
                    }
                    break;
            }
            if (!empty($entry[$field['id']])) {
                switch ($field['uniquenameField']) {
                    case 'title':
                        $args['title'] = $entry[$field['id']];
                        break;
                    case 'firstname':
                        $args['firstname'] = $entry[$field['id']];
                        break;
                    case 'lastname':
                        $args['lastname'] = $entry[$field['id']];
                        break;
                    case 'address':
                        $args['address1'] = $entry[$field['id']];
                        break;
                    case 'address2':
                        $args['address2'] = $entry[$field['id']];
                        break;
                    case 'suburb':
                        $args['suburb'] = $entry[$field['id']];
                        break;
                    case 'state':
                        $args['state'] = $entry[$field['id']];
                        break;
                    case 'countries':
                        $args['country'] = $entry[$field['id']];
                        break;
                    case 'postcode':
                        $args['postcode'] = $entry[$field['id']];
                        break;
                }
                if ($field['inputName'] == 'phone') {
                    $args['phone'] = $entry[$field['id']];
                }
            }
        }
        $user_id = bbconnect_get_user($args, null, $is_new_contact);
        if ($user_id) {
            $work_queue = get_term($form['work_queue'], 'bb_note_type');
            $title = 'E-Booklet requested';
            $action_required = false;
            if (!empty($args['country']) && ($args['country'] == 'AU' || $args['country'] == 'Australia')) {
                $title = 'Action Required';
                $action_required = true;
            }
            bbconnect_workqueues_insert_action_item($user_id, $title . ' - ' . $work_queue->name, 'Automatically added from form submission.', $form['work_queue'], '', $action_required);
        }
    }
}