<?php
define('THIS_SCRIPT', 'dispbbs');

require_once 'global.php';
global $dv,$db;

$id= intval($id);
$bid= intval($bid);
$mode= intval($mode);

if(($id == 0) || ($bid == 0)){
	head(0);
	showmsg("参数错误");
	exit;
}

if(($bid == 444) || ($bid == 777)){
	head(0);
	showmsg("您查找的主题已经被删除<script>document.location.href='dispbbs.php?boardid=".$bid."&id=".$id."';</script>");
	exit;
}

if($mode == 1){
	$nextfid=intval($db->scalar("select max(topicid) from {$dv}topic where topicid<{$id} and boardid={$bid}"));
}
else{
	$nextfid=intval($db->scalar("select min(topicid) from {$dv}topic where topicid>{$id} and boardid={$bid}"));
}

if($nextfid == 0){
	head(0);
	if($mode == 1){
		showmsg("已经到达第一条记录<script>setTimeout(\"document.location.href='dispbbs.php?boardid=".$bid."&id=".$id."'\",1000);</script>");
	}
	else{
		showmsg("已经到达最后一条记录<script>setTimeout(\"document.location.href='dispbbs.php?boardid=".$bid."&id=".$id."'\",1000);</script>");
	}
	exit;
}
else{
	header("location:dispbbs.php?boardid=".$bid."&id=".$nextfid);
}
?>