From 2d30e880899d7a15c0cac5c1f03c951fb0ceb5be Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sat, 13 Jun 2009 14:23:04 +0000 Subject: use same method to update custom profile fields in UCP and ACP (and then i am able to debug what is wrong with the oracle code) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9582 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_profile_fields.php | 61 ++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_profile_fields.php') diff --git a/phpBB/includes/functions_profile_fields.php b/phpBB/includes/functions_profile_fields.php index 26a1feb126..d9b6b25477 100644 --- a/phpBB/includes/functions_profile_fields.php +++ b/phpBB/includes/functions_profile_fields.php @@ -259,7 +259,7 @@ class custom_profile } /** - * Submit profile field + * Submit profile field for validation * @access public */ function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error) @@ -349,6 +349,65 @@ class custom_profile $db->sql_freeresult($result); } + /** + * Update profile field data directly + */ + function update_profile_field_data($user_id, &$cp_data) + { + global $db; + + if (!sizeof($cp_data)) + { + return; + } + + switch ($db->sql_layer) + { + case 'oracle': + case 'firebird': + case 'postgres': + $right_delim = $left_delim = '"'; + break; + + case 'sqlite': + case 'mssql': + case 'mssql_odbc': + $right_delim = ']'; + $left_delim = '['; + break; + + case 'mysql': + case 'mysql4': + case 'mysqli': + $right_delim = $left_delim = '`'; + break; + } + + foreach ($cp_data as $key => $value) + { + // Firebird is case sensitive with delimiter + $cp_data[$left_delim . (($db->sql_layer == 'firebird') ? strtoupper($key) : $key) . $right_delim] = $value; + unset($cp_data[$key]); + } + + $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $cp_data) . " + WHERE user_id = $user_id"; + $db->sql_query($sql); + + if (!$db->sql_affectedrows()) + { + $cp_data['user_id'] = (int) $user_id; + + $db->sql_return_on_error(true); + + $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data); + $db->sql_query($sql); + + $db->sql_return_on_error(false); + } + } + /** * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled) * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template -- cgit v1.2.1 From d8e78c766b0f14f5d53e1916c341cbaccb012b4f Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sat, 13 Jun 2009 15:00:33 +0000 Subject: like firebird, oracle uses uppercase column names if delimiter used (Fixes Bug #46015) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9585 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_profile_fields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_profile_fields.php') diff --git a/phpBB/includes/functions_profile_fields.php b/phpBB/includes/functions_profile_fields.php index d9b6b25477..bb54e0de5b 100644 --- a/phpBB/includes/functions_profile_fields.php +++ b/phpBB/includes/functions_profile_fields.php @@ -386,7 +386,7 @@ class custom_profile foreach ($cp_data as $key => $value) { // Firebird is case sensitive with delimiter - $cp_data[$left_delim . (($db->sql_layer == 'firebird') ? strtoupper($key) : $key) . $right_delim] = $value; + $cp_data[$left_delim . (($db->sql_layer == 'firebird' || $db->sql_layer == 'oracle') ? strtoupper($key) : $key) . $right_delim] = $value; unset($cp_data[$key]); } -- cgit v1.2.1 From 1d655f2f3e61a673573e5ea3cc863e34a1bb8eaa Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Mon, 6 Jul 2009 13:42:15 +0000 Subject: Fix an endless loop; don't return the sql array by reference git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9716 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_profile_fields.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_profile_fields.php') diff --git a/phpBB/includes/functions_profile_fields.php b/phpBB/includes/functions_profile_fields.php index bb54e0de5b..abdae926bd 100644 --- a/phpBB/includes/functions_profile_fields.php +++ b/phpBB/includes/functions_profile_fields.php @@ -383,15 +383,16 @@ class custom_profile break; } + // use new array for the UPDATE; changes in the key do not affect the original array + $cp_data_sql = array(); foreach ($cp_data as $key => $value) { // Firebird is case sensitive with delimiter - $cp_data[$left_delim . (($db->sql_layer == 'firebird' || $db->sql_layer == 'oracle') ? strtoupper($key) : $key) . $right_delim] = $value; - unset($cp_data[$key]); + $cp_data_sql[$left_delim . (($db->sql_layer == 'firebird' || $db->sql_layer == 'oracle') ? strtoupper($key) : $key) . $right_delim] = $value; } $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $cp_data) . " + SET ' . $db->sql_build_array('UPDATE', $cp_data_sql) . " WHERE user_id = $user_id"; $db->sql_query($sql); @@ -401,7 +402,7 @@ class custom_profile $db->sql_return_on_error(true); - $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data); + $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data_sql); $db->sql_query($sql); $db->sql_return_on_error(false); -- cgit v1.2.1 From 62471fe5813329ebcee8de7d0e93c492ea1f8635 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Mon, 6 Jul 2009 13:42:43 +0000 Subject: Fix an endless loop; don't return the sql array by reference git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9717 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_profile_fields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_profile_fields.php') diff --git a/phpBB/includes/functions_profile_fields.php b/phpBB/includes/functions_profile_fields.php index abdae926bd..bb1ec476c4 100644 --- a/phpBB/includes/functions_profile_fields.php +++ b/phpBB/includes/functions_profile_fields.php @@ -398,7 +398,7 @@ class custom_profile if (!$db->sql_affectedrows()) { - $cp_data['user_id'] = (int) $user_id; + $cp_data_sql['user_id'] = (int) $user_id; $db->sql_return_on_error(true); -- cgit v1.2.1 From 4f6f9c424d124ec3839809828bbe45ae7a17436a Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sun, 19 Jul 2009 00:20:03 +0000 Subject: Permit null values for non-required integer custom profile fields and ensure zero complies with the range limits. #40925 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9788 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_profile_fields.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'phpBB/includes/functions_profile_fields.php') diff --git a/phpBB/includes/functions_profile_fields.php b/phpBB/includes/functions_profile_fields.php index bb1ec476c4..9e356414a9 100644 --- a/phpBB/includes/functions_profile_fields.php +++ b/phpBB/includes/functions_profile_fields.php @@ -90,18 +90,6 @@ class custom_profile */ function validate_profile_field($field_type, &$field_value, $field_data) { - switch ($field_type) - { - case FIELD_INT: - case FIELD_DROPDOWN: - $field_value = (int) $field_value; - break; - - case FIELD_BOOL: - $field_value = (bool) $field_value; - break; - } - switch ($field_type) { case FIELD_DATE: @@ -133,6 +121,8 @@ class custom_profile break; case FIELD_BOOL: + $field_value = (bool) $field_value; + if (!$field_value && $field_data['field_required']) { return 'FIELD_REQUIRED'; @@ -140,10 +130,12 @@ class custom_profile break; case FIELD_INT: - if (empty($field_value) && !$field_data['field_required']) + if (trim($field_value) === '' && !$field_data['field_required']) { return false; } + + $field_value = (int) $field_value; if ($field_value < $field_data['field_minlen']) { @@ -156,6 +148,8 @@ class custom_profile break; case FIELD_DROPDOWN: + $field_value = (int) $field_value; + if ($field_value == $field_data['field_novalue'] && $field_data['field_required']) { return 'FIELD_REQUIRED'; @@ -514,7 +508,7 @@ class custom_profile switch ($this->profile_types[$field_type]) { case 'int': - if ($value == '') + if ($value === '') { return NULL; } @@ -644,7 +638,7 @@ class custom_profile } } - return (is_null($value)) ? '' : (int) $value; + return (is_null($value) || $value === '') ? '' : (int) $value; } else { -- cgit v1.2.1