Change way error is returned to validate email/username, fixes problem with lack of language support for error output and subsequent doubled username, etc. issues + remove get_userdata_from_id and use get_userdata instead + other minor changes

git-svn-id: file:///svn/phpbb/trunk@2113 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2002-02-12 17:14:39 +00:00
parent 19928f6a48
commit be3f1941e1

View file

@ -74,29 +74,14 @@ function get_db_stat($mode)
return 'ERROR'; return 'ERROR';
} }
function get_userdata_from_id($user_id) function get_userdata($user)
{ {
global $db; global $db;
$sql = "SELECT * $sql = "SELECT *
FROM " . USERS_TABLE . " FROM " . USERS_TABLE . "
WHERE user_id = $user_id"; WHERE ";
if ( !($result = $db->sql_query($sql)) ) $sql .= ( ( is_integer($user) ) ? "user_id = $user" : "username = '" . str_replace("\'", "''", $user) . "'" ) . " AND user_id <> " . ANONYMOUS;
{
message_die(GENERAL_ERROR, "Couldn't obtain userdata for id", "", __LINE__, __FILE__, $sql);
}
return ( $row = $db->sql_fetchrow($result) ) ? $row : false;
}
function get_userdata($username)
{
global $db;
$sql = "SELECT *
FROM " . USERS_TABLE . "
WHERE username = '" . str_replace("\'", "''", $username) . "'
AND user_id <> " . ANONYMOUS;
if ( !($result = $db->sql_query($sql)) ) if ( !($result = $db->sql_query($sql)) )
{ {
message_die(GENERAL_ERROR, "Tried obtaining data for a non-existent user", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Tried obtaining data for a non-existent user", "", __LINE__, __FILE__, $sql);
@ -107,37 +92,43 @@ function get_userdata($username)
function make_jumpbox($match_forum_id = 0) function make_jumpbox($match_forum_id = 0)
{ {
global $lang, $db, $SID; global $lang, $db, $SID, $nav_links, $phpEx;
global $nav_links, $phpEx;
$sql = "SELECT c.cat_id, c.cat_title, c.cat_order $sql = "SELECT c.cat_id, c.cat_title, c.cat_order
FROM " . CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f FROM " . CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f
WHERE f.cat_id = c.cat_id WHERE f.cat_id = c.cat_id
GROUP BY c.cat_id, c.cat_title, c.cat_order GROUP BY c.cat_id, c.cat_title, c.cat_order
ORDER BY c.cat_order"; ORDER BY c.cat_order";
if(!$q_categories = $db->sql_query($sql)) if ( !($result = $db->sql_query($sql)) )
{ {
message_die(GENERAL_ERROR, "Couldn't obtain category list.", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't obtain category list.", "", __LINE__, __FILE__, $sql);
} }
if( $total_categories = $db->sql_numrows() ) $category_rows = array();
while ( $row = $db->sql_fetchrow($result) )
{ {
$category_rows = $db->sql_fetchrowset($q_categories); $category_rows[] = $row;
}
if ( $total_categories = count($category_rows) )
{
$sql = "SELECT * $sql = "SELECT *
FROM " . FORUMS_TABLE . " FROM " . FORUMS_TABLE . "
ORDER BY cat_id, forum_order"; ORDER BY cat_id, forum_order";
if(!$q_forums = $db->sql_query($sql)) if ( !($result = $db->sql_query($sql)) )
{ {
message_die(GENERAL_ERROR, "Couldn't obtain forums information.", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't obtain forums information.", "", __LINE__, __FILE__, $sql);
} }
$total_forums = $db->sql_numrows($q_forums);
$forum_rows = $db->sql_fetchrowset($q_forums);
$boxstring = '<select name="' . POST_FORUM_URL . '" onChange="if(this.options[this.selectedIndex].value != -1){ forms[\'jumpbox\'].submit() }"><option value="-1">' . $lang['Select_forum'] . '</option>'; $boxstring = '<select name="' . POST_FORUM_URL . '" onChange="if(this.options[this.selectedIndex].value != -1){ forms[\'jumpbox\'].submit() }"><option value="-1">' . $lang['Select_forum'] . '</option>';
if( $total_forums ) $forum_rows = array();
while ( $row = $db->sql_fetchrow($result) )
{
$forum_rows[] = $row;
}
if ( $total_forums = count($forum_rows) )
{ {
for($i = 0; $i < $total_categories; $i++) for($i = 0; $i < $total_categories; $i++)
{ {
@ -146,7 +137,7 @@ function make_jumpbox($match_forum_id = 0)
{ {
if ( $forum_rows[$j]['cat_id'] == $category_rows[$i]['cat_id'] && $forum_rows[$j]['auth_view'] <= AUTH_REG ) if ( $forum_rows[$j]['cat_id'] == $category_rows[$i]['cat_id'] && $forum_rows[$j]['auth_view'] <= AUTH_REG )
{ {
$selected = ( $forum_rows[$j]['forum_id'] == $match_forum_id ) ? "selected=\"selected\"" : ""; $selected = ( $forum_rows[$j]['forum_id'] == $match_forum_id ) ? 'selected="selected"' : '';
$boxstring_forums .= '<option value="' . $forum_rows[$j]['forum_id'] . '"' . $selected . '>' . $forum_rows[$j]['forum_name'] . '</option>'; $boxstring_forums .= '<option value="' . $forum_rows[$j]['forum_id'] . '"' . $selected . '>' . $forum_rows[$j]['forum_name'] . '</option>';
// //
@ -183,7 +174,7 @@ function make_jumpbox($match_forum_id = 0)
$boxstring .= '<input type="hidden" name="sid" value="' . $SID . '" />'; $boxstring .= '<input type="hidden" name="sid" value="' . $SID . '" />';
} }
return($boxstring); return $boxstring;
} }
// //
@ -198,30 +189,23 @@ function make_forum_select($box_name, $ignore_forum = false)
$sql = "SELECT forum_id, forum_name $sql = "SELECT forum_id, forum_name
FROM " . FORUMS_TABLE . " FROM " . FORUMS_TABLE . "
ORDER BY cat_id, forum_order"; ORDER BY cat_id, forum_order";
if( !$q_forums = $db->sql_query($sql) ) if ( !($result = $db->sql_query($sql)) )
{ {
message_die(GENERAL_ERROR, "Couldn't obtain forums information.", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't obtain forums information.", "", __LINE__, __FILE__, $sql);
} }
$forum_list = ""; $forum_list = "";
while( $row = $db->sql_fetchrow($q_forums) ) while( $row = $db->sql_fetchrow($result) )
{ {
if ( $is_auth_ary[$row['forum_id']]['auth_read'] && $ignore_forum != $row['forum_id'] ) if ( $is_auth_ary[$row['forum_id']]['auth_read'] && $ignore_forum != $row['forum_id'] )
{ {
$forum_list .= "<option value=\"" . $row['forum_id'] . "\">" . $row['forum_name'] . "</option>"; $forum_list .= '<option value="' . $row['forum_id'] . '">' . $row['forum_name'] . '</option>';
} }
} }
if( $forum_list == "" ) $forum_list .= ( $forum_list == "" ) ? '<option value="-1">-- ! No Forums ! --</option>' : '<select name="' . $box_name . '">' . $forum_list . '</select>';
{
$forum_list .= "<option value=\"-1\">-- ! No Forums ! --</option>\n";
}
else
{
$forum_list = '<select name="' . $box_name . '">' . $forum_list . '</select>';
}
return($forum_list); return $forum_list;
} }
// //
@ -243,13 +227,13 @@ function init_userprefs($userdata)
$board_config['default_dateformat'] = $userdata['user_dateformat']; $board_config['default_dateformat'] = $userdata['user_dateformat'];
} }
if( isset($userdata['user_timezone']) ) if ( !empty($userdata['user_timezone']) )
{ {
$board_config['board_timezone'] = $userdata['user_timezone']; $board_config['board_timezone'] = $userdata['user_timezone'];
} }
} }
if( !@file_exists($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/lang_main.".$phpEx) ) if ( !file_exists($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/lang_main.".$phpEx) )
{ {
$board_config['default_lang'] = "english"; $board_config['default_lang'] = "english";
} }
@ -258,7 +242,7 @@ function init_userprefs($userdata)
if ( defined("IN_ADMIN") ) if ( defined("IN_ADMIN") )
{ {
if( !@file_exists($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/lang_admin.".$phpEx) ) if( !file_exists($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/lang_admin.".$phpEx) )
{ {
$board_config['default_lang'] = "english"; $board_config['default_lang'] = "english";
} }
@ -273,7 +257,7 @@ function init_userprefs($userdata)
{ {
if ( $userdata['user_id'] != ANONYMOUS && isset($userdata['user_style']) ) if ( $userdata['user_id'] != ANONYMOUS && isset($userdata['user_style']) )
{ {
if( ($theme = setup_style($userdata['user_style'])) ) if ( $theme = setup_style($userdata['user_style']) )
{ {
return; return;
} }
@ -354,7 +338,7 @@ function generate_activation_key()
function encode_ip($dotquad_ip) function encode_ip($dotquad_ip)
{ {
$ip_sep = explode(".", $dotquad_ip); $ip_sep = explode(".", $dotquad_ip);
return (sprintf("%02x%02x%02x%02x", $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3])); return sprintf("%02x%02x%02x%02x", $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]);
} }
function decode_ip($int_ip) function decode_ip($int_ip)
@ -368,7 +352,7 @@ function decode_ip($int_ip)
// //
function create_date($format, $gmepoch, $tz) function create_date($format, $gmepoch, $tz)
{ {
return (@gmdate($format, $gmepoch + (3600 * $tz))); return gmdate($format, $gmepoch + (3600 * $tz));
} }
// //
@ -487,7 +471,7 @@ function validate_username($username)
{ {
if ( $row = $db->sql_fetchrow($result) ) if ( $row = $db->sql_fetchrow($result) )
{ {
return ( $userdata['session_logged_in'] ) ? ( ( $row['username'] != $userdata['username'] ) ? array('error' => $lang['Username_taken']) : array('error' => '') ) : array('error' => $lang['Username_taken']); return ( $userdata['session_logged_in'] ) ? ( ( $row['username'] != $userdata['username'] ) ? array('error' => true, 'error_msg' => $lang['Username_taken']) : array('error' => false, 'error_msg' => '') ) : array('error' => true, 'error_msg' => $lang['Username_taken']);
} }
} }
@ -498,7 +482,7 @@ function validate_username($username)
{ {
if ( $row = $db->sql_fetchrow($result) ) if ( $row = $db->sql_fetchrow($result) )
{ {
return array('error' => $lang['Username_taken']); return array('error' => true, 'error_msg' => $lang['Username_taken']);
} }
} }
@ -509,7 +493,7 @@ function validate_username($username)
{ {
if ( $db->sql_fetchrow($result) ) if ( $db->sql_fetchrow($result) )
{ {
return array('error' => $lang['Username_disallowed']); return array('error' => true, 'error_msg' => $lang['Username_disallowed']);
} }
} }
@ -521,7 +505,7 @@ function validate_username($username)
{ {
if ( preg_match("/\b(" . str_replace("\*", "\w*?", preg_quote($row['word'])) . ")\b/i", $username) ) if ( preg_match("/\b(" . str_replace("\*", "\w*?", preg_quote($row['word'])) . ")\b/i", $username) )
{ {
return array('error' => $lang['Username_disallowed']); return array('error' => true, 'error_msg' => $lang['Username_disallowed']);
} }
} }
} }
@ -529,10 +513,10 @@ function validate_username($username)
// Don't allow " in username. // Don't allow " in username.
if ( strstr($username, '"') ) if ( strstr($username, '"') )
{ {
return array('error' => $lang['Username_invalid']); return array('error' => true, 'error_msg' => $lang['Username_invalid']);
} }
return array('error' => ''); return array('error' => false, 'error_msg' => '');
} }
@ -574,11 +558,9 @@ function sync($type, $id)
break; break;
case 'forum': case 'forum':
$sql = "SELECT MAX(p.post_id) AS last_post $sql = "SELECT MAX(post_id) AS last_post, COUNT(post_id) AS total
FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t FROM " . POSTS_TABLE . "
WHERE p.forum_id = $id WHERE forum_id = $id";
AND p.topic_id = t.topic_id
AND t.topic_status <> " . TOPIC_MOVED;
if ( !$result = $db->sql_query($sql) ) if ( !$result = $db->sql_query($sql) )
{ {
message_die(GENERAL_ERROR, "Could not get post ID", "Error", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Could not get post ID", "Error", __LINE__, __FILE__, $sql);
@ -587,26 +569,11 @@ function sync($type, $id)
if ( $row = $db->sql_fetchrow($result) ) if ( $row = $db->sql_fetchrow($result) )
{ {
$last_post = ($row['last_post']) ? $row['last_post'] : 0; $last_post = ($row['last_post']) ? $row['last_post'] : 0;
}
else
{
$last_post = 0;
}
$sql = "SELECT COUNT(post_id) AS total
FROM " . POSTS_TABLE . "
WHERE forum_id = $id";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Could not get post count", "Error", __LINE__, __FILE__, $sql);
}
if( $row = $db->sql_fetchrow($result) )
{
$total_posts = ($row['total']) ? $row['total'] : 0; $total_posts = ($row['total']) ? $row['total'] : 0;
} }
else else
{ {
$last_post = 0;
$total_posts = 0; $total_posts = 0;
} }
@ -709,19 +676,17 @@ function style_select($default_style, $select_name = "style", $dirname = "templa
$sql = "SELECT themes_id, style_name $sql = "SELECT themes_id, style_name
FROM " . THEMES_TABLE . " FROM " . THEMES_TABLE . "
ORDER BY template_name, themes_id"; ORDER BY template_name, themes_id";
if( !$result = $db->sql_query($sql) ) if ( !($result = $db->sql_query($sql)) )
{ {
message_die(GENERAL_ERROR, "Couldn't query themes table", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't query themes table", "", __LINE__, __FILE__, $sql);
} }
$template_style = $db->sql_fetchrowset($result);
$style_select = '<select name="' . $select_name . '">'; $style_select = '<select name="' . $select_name . '">';
for($i = 0; $i < count($template_style); $i++) while ( $row = $db->sql_fetchrow($result) )
{ {
$selected = ( $template_style[$i]['themes_id'] == $default_style ) ? ' selected="selected"' : ''; $selected = ( $row['themes_id'] == $default_style ) ? ' selected="selected"' : '';
$style_select .= '<option value="' . $template_style[$i]['themes_id'] . '"' . $selected . '>' . $template_style[$i]['style_name'] . '</option>'; $style_select .= '<option value="' . $row['themes_id'] . '"' . $selected . '>' . $row['style_name'] . '</option>';
} }
$style_select .= "</select>"; $style_select .= "</select>";
@ -823,7 +788,6 @@ function username_search($search_match, $is_inline_review = 0, $default_list = "
if ( !$is_inline_review ) if ( !$is_inline_review )
{ {
$gen_simple_header = TRUE; $gen_simple_header = TRUE;
$page_title = $lang['Search']; $page_title = $lang['Search'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx); include($phpbb_root_path . 'includes/page_header.'.$phpEx);
@ -1065,7 +1029,6 @@ function message_die($msg_code, $msg_text = "", $msg_title = "", $err_line = "",
} }
exit; exit;
} }
// //