Fix error when view is set to somethng unexpected

git-svn-id: file:///svn/phpbb/trunk@2376 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2002-03-20 15:04:21 +00:00
parent fc966546d7
commit b56667c1dd

View file

@ -58,13 +58,13 @@ if( !isset($topic_id) && !isset($post_id) )
// Find topic id if user requested a newer // Find topic id if user requested a newer
// or older topic // or older topic
// //
if( isset($HTTP_GET_VARS["view"]) && empty($HTTP_GET_VARS[POST_POST_URL]) ) if ( isset($HTTP_GET_VARS['view']) && empty($HTTP_GET_VARS[POST_POST_URL]) )
{ {
if( $HTTP_GET_VARS["view"] == "newest" ) if ( $HTTP_GET_VARS['view'] == 'newest' )
{ {
if( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . "_sid"]) ) if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) )
{ {
$session_id = $HTTP_COOKIE_VARS[$board_config['cookie_name'] . "_sid"]; $session_id = $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid'];
if ( $session_id ) if ( $session_id )
{ {
@ -76,9 +76,9 @@ if( isset($HTTP_GET_VARS["view"]) && empty($HTTP_GET_VARS[POST_POST_URL]) )
AND p.post_time >= u.user_lastvisit AND p.post_time >= u.user_lastvisit
ORDER BY p.post_time ASC ORDER BY p.post_time ASC
LIMIT 1"; LIMIT 1";
if( !$result = $db->sql_query($sql) ) if ( !($result = $db->sql_query($sql)) )
{ {
message_die(GENERAL_ERROR, "Couldn't obtain newer/older topic information", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, 'Could not obtain newer/older topic information', '', __LINE__, __FILE__, $sql);
} }
if ( !($row = $db->sql_fetchrow($result)) ) if ( !($row = $db->sql_fetchrow($result)) )
@ -89,28 +89,25 @@ if( isset($HTTP_GET_VARS["view"]) && empty($HTTP_GET_VARS[POST_POST_URL]) )
{ {
$post_id = $row['post_id']; $post_id = $row['post_id'];
header("Location: " . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id", true)); header("Location: " . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id", true));
exit;
} }
} }
else else
{ {
header("Location: " . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true)); header("Location: " . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true));
exit;
} }
} }
else else
{ {
header("Location: " . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true)); header("Location: " . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true));
exit;
} }
} }
else if( $HTTP_GET_VARS["view"] == "next" ) else if( $HTTP_GET_VARS['view'] == 'next' || $HTTP_GET_VARS['view'] == 'previous' )
{ {
$sql_condition = ">"; $sql_condition = ( $HTTP_GET_VARS['view'] == 'next' ) ? '>' : '<';
$sql_ordering = "ASC"; $sql_ordering = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'ASC' : 'DESC';
}
else if( $HTTP_GET_VARS["view"] == "previous" )
{
$sql_condition = "<";
$sql_ordering = "DESC";
}
$sql = "SELECT t.topic_id $sql = "SELECT t.topic_id
FROM " . TOPICS_TABLE . " t, " . TOPICS_TABLE . " t2, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2 FROM " . TOPICS_TABLE . " t, " . TOPICS_TABLE . " t2, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2
@ -122,14 +119,14 @@ if( isset($HTTP_GET_VARS["view"]) && empty($HTTP_GET_VARS[POST_POST_URL]) )
AND p.topic_id = t.topic_id AND p.topic_id = t.topic_id
ORDER BY p.post_time $sql_ordering ORDER BY p.post_time $sql_ordering
LIMIT 1"; LIMIT 1";
if(!$result = $db->sql_query($sql)) if ( !($result = $db->sql_query($sql)) )
{ {
message_die(GENERAL_ERROR, "Couldn't obtain newer/older topic information", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't obtain newer/older topic information", "", __LINE__, __FILE__, $sql);
} }
if( !$row = $db->sql_fetchrow($result) ) if ( !($row = $db->sql_fetchrow($result)) )
{ {
if( $HTTP_GET_VARS["view"] == "next" ) if( $HTTP_GET_VARS['view'] == 'next' )
{ {
message_die(GENERAL_MESSAGE, 'No_newer_topics'); message_die(GENERAL_MESSAGE, 'No_newer_topics');
} }
@ -143,18 +140,18 @@ if( isset($HTTP_GET_VARS["view"]) && empty($HTTP_GET_VARS[POST_POST_URL]) )
$topic_id = $row['topic_id']; $topic_id = $row['topic_id'];
} }
} }
}
// //
// This rather complex gaggle of code handles querying for topics but // This rather complex gaggle of code handles querying for topics but
// also allows for direct linking to a post (and the calculation of which // also allows for direct linking to a post (and the calculation of which
// page the post is on and the correct display of viewtopic) // page the post is on and the correct display of viewtopic)
// //
$join_sql_table = ( !isset($post_id) ) ? "" : ", " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2 "; $join_sql_table = ( !isset($post_id) ) ? '' : ", " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2 ";
$join_sql = ( !isset($post_id) ) ? "t.topic_id = $topic_id" : "p.post_id = $post_id AND t.topic_id = p.topic_id AND p2.topic_id = p.topic_id AND p2.post_id <= $post_id"; $join_sql = ( !isset($post_id) ) ? "t.topic_id = $topic_id" : "p.post_id = $post_id AND t.topic_id = p.topic_id AND p2.topic_id = p.topic_id AND p2.post_id <= $post_id";
$count_sql = ( !isset($post_id) ) ? "" : ", COUNT(p2.post_id) AS prev_posts"; $count_sql = ( !isset($post_id) ) ? '' : ", COUNT(p2.post_id) AS prev_posts";
$order_sql = ( !isset($post_id) ) ? "" : "GROUP BY p.post_id, t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments ORDER BY p.post_id ASC"; $order_sql = ( !isset($post_id) ) ? '' : "GROUP BY p.post_id, t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments ORDER BY p.post_id ASC";
$sql = "SELECT t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments" . $count_sql . " $sql = "SELECT t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments" . $count_sql . "
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $join_sql_table . " FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $join_sql_table . "