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; }
$page_title = get_opendb_lang_var('user_profile_for_user_name', array('user_id' => $user_r['user_id'], 'fullname' => $user_r['fullname'])); echo _theme_header($page_title); echo '<h2>' . $page_title . '</h2>'; if ($user_r['active_ind'] != 'Y') { echo "<p class=\"userDeactivatedNotice\">" . get_opendb_lang_var('user_deactivated') . "</p>"; } echo "<table>"; echo format_field(get_opendb_lang_var('userid'), $user_r['user_id']); echo format_field(get_opendb_lang_var('user_role'), $user_r['role_description']); echo format_field(get_opendb_lang_var('fullname'), $user_r['fullname']); if ($user_r['user_id'] === get_opendb_session_var('user_id') || is_user_granted_permission(PERM_ADMIN_USER_PROFILE)) { echo format_field(get_opendb_lang_var('email'), $user_r['email_addr']); } 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) {