Beispiel #1
0
function update_user_addresses($user_r, $address_provided_r, $HTTP_VARS, &$errors)
{
    // No errors recorded at this stage.
    $errors = NULL;
    $address_creation_success = TRUE;
    $address_type_sequence_number_r = NULL;
    $addr_results = fetch_user_address_type_rs($user_r['user_id'], TRUE);
    if ($addr_results) {
        while ($address_type_r = db_fetch_assoc($addr_results)) {
            $v_address_type = strtolower($address_type_r['s_address_type']);
            $address_creation_success = TRUE;
            // address does not currently exist, so create it.
            if ($address_type_r['sequence_number'] === NULL) {
                if ($address_provided_r[$v_address_type] !== FALSE) {
                    $new_sequence_number = insert_user_address($user_r['user_id'], $address_type_r['s_address_type'], $HTTP_VARS[$v_address_type]['public_address_ind'], $HTTP_VARS[$v_address_type]['borrow_address_ind']);
                    if ($new_sequence_number !== FALSE) {
                        $address_type_r['sequence_number'] = $new_sequence_number;
                    } else {
                        $address_creation_success = FALSE;
                    }
                }
            } else {
                $new_sequence_number = update_user_address($address_type_r['sequence_number'], $HTTP_VARS[$v_address_type]['public_address_ind'], $HTTP_VARS[$v_address_type]['borrow_address_ind']);
            }
            if ($address_creation_success !== FALSE) {
                if ($address_provided_r[$v_address_type] !== FALSE) {
                    $attr_results = fetch_address_type_attribute_type_rs($address_type_r['s_address_type'], 'update', TRUE);
                    if ($attr_results) {
                        while ($addr_attribute_type_r = db_fetch_assoc($attr_results)) {
                            $fieldname = get_field_name($addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no']);
                            if (is_lookup_attribute_type($addr_attribute_type_r['s_attribute_type'])) {
                                $lookup_value_r = NULL;
                                if (is_array($HTTP_VARS[$v_address_type][$fieldname])) {
                                    $lookup_value_r =& $HTTP_VARS[$v_address_type][$fieldname];
                                } else {
                                    if (strlen(trim($HTTP_VARS[$v_address_type][$fieldname])) > 0) {
                                        $lookup_value_r[] = $HTTP_VARS[$v_address_type][$fieldname];
                                    }
                                }
                                $user_addr_attr_lookup_val_r = fetch_user_address_lookup_attribute_val($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no']);
                                if ($user_addr_attr_lookup_val_r !== FALSE) {
                                    if (is_not_empty_array($lookup_value_r)) {
                                        // insert/update mode
                                        if (!update_user_address_attributes($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no'], $lookup_value_r)) {
                                            $db_error = db_error();
                                            $errors[] = array('error' => get_opendb_lang_var('user_address_not_updated'), 'detail' => $db_error);
                                            $address_creation_success = FALSE;
                                        }
                                    } else {
                                        if (!delete_user_address_attributes($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no'])) {
                                            $db_error = db_error();
                                            $errors[] = array('error' => get_opendb_lang_var('user_address_not_updated'), 'detail' => $db_error);
                                            $address_creation_success = FALSE;
                                        }
                                    }
                                } else {
                                    if (is_not_empty_array($lookup_value_r)) {
                                        if (!insert_user_address_attributes($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no'], $lookup_value_r)) {
                                            $db_error = db_error();
                                            $errors[] = array('error' => get_opendb_lang_var('user_address_not_updated'), 'detail' => $db_error);
                                            $address_creation_success = FALSE;
                                        }
                                    }
                                }
                            } else {
                                $attribute_val = fetch_user_address_attribute_val($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no']);
                                if ($attribute_val !== FALSE) {
                                    if (strlen($HTTP_VARS[$v_address_type][$fieldname]) > 0) {
                                        if (!update_user_address_attributes($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no'], $HTTP_VARS[$v_address_type][$fieldname])) {
                                            $db_error = db_error();
                                            $errors[] = array('error' => get_opendb_lang_var('user_address_not_updated'), 'detail' => $db_error);
                                            $address_creation_success = FALSE;
                                        }
                                    } else {
                                        if (!delete_user_address_attributes($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no'])) {
                                            $db_error = db_error();
                                            $errors[] = array('error' => get_opendb_lang_var('user_address_not_updated'), 'detail' => $db_error);
                                            $address_creation_success = FALSE;
                                        }
                                    }
                                } else {
                                    if (strlen($HTTP_VARS[$v_address_type][$fieldname]) > 0) {
                                        if (!insert_user_address_attributes($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no'], $HTTP_VARS[$v_address_type][$fieldname])) {
                                            $db_error = db_error();
                                            $errors[] = array('error' => get_opendb_lang_var('user_address_not_updated'), 'detail' => $db_error);
                                            $address_creation_success = FALSE;
                                        }
                                    }
                                }
                            }
                        }
                        db_free_result($attr_results);
                    }
                } else {
                    // existing address, we want to get rid of it here
                    if ($address_type_r['sequence_number'] !== NULL) {
                        if (delete_user_address_attributes($address_type_r['sequence_number'])) {
                            delete_user_address($address_type_r['sequence_number']);
                        }
                    }
                }
            }
        }
        db_free_result($addr_results);
    }
    return $address_creation_success;
}
Beispiel #2
0
 echo "\n</table>";
 $address_header_displayed = FALSE;
 $addr_results = fetch_user_address_type_rs($user_r['user_id'], TRUE);
 if ($addr_results) {
     while ($address_type_r = db_fetch_assoc($addr_results)) {
         if (is_user_address_visible($HTTP_VARS, $address_type_r)) {
             $attr_results = fetch_address_type_attribute_type_rs($address_type_r['s_address_type'], 'query', TRUE);
             if ($attr_results) {
                 echo '<h3>' . $address_type_r['description'] . '</h3>';
                 echo "<table>";
                 while ($addr_attribute_type_r = db_fetch_assoc($attr_results)) {
                     $value = NULL;
                     if (is_lookup_attribute_type($addr_attribute_type_r['s_attribute_type'])) {
                         $value = fetch_user_address_lookup_attribute_val($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no']);
                     } else {
                         $value = fetch_user_address_attribute_val($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no']);
                     }
                     if (strlen($value) > 0) {
                         echo get_item_display_field(NULL, $addr_attribute_type_r, $value);
                     }
                 }
                 db_free_result($attr_results);
                 echo "\n</table>";
             }
         }
     }
     db_free_result($addr_results);
 }
 if (is_valid_opendb_mailer() && strlen($user_r['email_addr']) > 0 && is_user_granted_permission(PERM_SEND_EMAIL) && is_user_permitted_to_receive_email($user_r['user_id'])) {
     $url = 'email.php?' . get_url_string(array('op' => 'send_to_uid', 'uid' => $user_r['user_id'], 'inc_menu' => 'N', 'subject' => ifempty($HTTP_VARS['subject'], get_opendb_lang_var('no_subject'))));
     $footer_links_r[] = array(url => $url, target => 'popup(640,480)', text => get_opendb_lang_var('send_email'));