コード例 #1
0
ファイル: user_admin.php プロジェクト: horrabin/opendb
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;
}
コード例 #2
0
ファイル: address_type.php プロジェクト: horrabin/opendb
function _insert_or_update_user_address_attributes($ua_sequence_number, $s_attribute_type, $order_no, $attribute_val_r)
{
    if (is_lookup_attribute_type($s_attribute_type)) {
        $insert_cols = "INSERT INTO user_address_attribute (ua_sequence_number, s_attribute_type, order_no, attribute_no, lookup_attribute_val)";
    } else {
        $insert_cols = "INSERT INTO user_address_attribute (ua_sequence_number, s_attribute_type, order_no, attribute_no, attribute_val)";
    }
    if (db_query("LOCK TABLES user_address_attribute WRITE")) {
        if (delete_user_address_attributes($ua_sequence_number, $s_attribute_type, $order_no)) {
            if (!is_array($attribute_val_r)) {
                $value_r[] = addslashes(trim(strip_tags($attribute_val_r)));
            } else {
                $value_r = NULL;
                for ($i = 0; $i < count($attribute_val_r); $i++) {
                    $value = addslashes(trim(strip_tags($attribute_val_r[$i])));
                    // lets make sure this $value does not already exist
                    if (is_array($value_r)) {
                        for ($j = 0; $j < count($value_r); $j++) {
                            if ($value_r[$j] == $value) {
                                $value = NULL;
                                break;
                            }
                        }
                    }
                    if ($value != null) {
                        $value_r[] = $value;
                    }
                }
            }
            for ($i = 0; $i < count($value_r); $i++) {
                $attribute_val = $value_r[$i];
                $query = $insert_cols . "VALUES ('{$ua_sequence_number}','{$s_attribute_type}', {$order_no}, " . ($i + 1) . ", '{$attribute_val}')";
                $insert = db_query($query);
                if ($insert && db_affected_rows() > 0) {
                    opendb_logger(OPENDB_LOG_INFO, __FILE__, __FUNCTION__, NULL, array($ua_sequence_number, $s_attribute_type, $order_no, $attribute_val));
                } else {
                    db_query("UNLOCK TABLES");
                    opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, db_error(), array($ua_sequence_number, $s_attribute_type, $order_no, $attribute_val));
                    return FALSE;
                }
            }
            db_query("UNLOCK TABLES");
            return TRUE;
        } else {
            db_query("UNLOCK TABLES");
            return FALSE;
        }
    } else {
        opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, db_error(), array($ua_sequence_number, $s_attribute_type, $order_no, $attribute_val_r));
        return FALSE;
    }
}