<?php
require("rbbs.ini");
if($id){
	echo "<html>";
	echo "<head>";
	echo "<meta http-equiv=\"Content-Type\" CONTENT=\"text/html; charset=EUC-JP\">";
	echo "<body bgcolor=$ini_bodycolor>";
	echo "<center>$ini_header";
	
	$connection = @pg_connect("","",$ini_dbname);
	$sql = "select * from $ini_topic_table where topic_id = $id ";
	$result = @pg_exec($sql);
	if($result == false) {
		@pg_close($connection);
		echo "メッセージを読み込めませんでした。code=-1</body></html>";
		exit;
	}
	$rows = @pg_numrows($result);
	if($rows == 0) {
		@pg_freeresult($result);
		@pg_close($connection);
		echo "<h3>トピックが見つかりません。</h3>";
		exit;
	}
	$age = pg_result($result,0,"age");
	$sex = pg_result($result,0,"sex");
	$occupation = pg_result($result,0,"occupation");
	$title = pg_result($result,0,"title");
	$message = pg_result($result,0,"message");
	@pg_freeresult($result);

	echo "<table width=300 >";
	echo "<tr><td align=\"center\"><h1><font color=\"#FF00FF\">$title</font></h1></tr></td>";
	echo "</table>";
	echo "<table>";
	echo "<tr><td bgcolor=\"FFEEC0\">$message</td></tr>";
	echo "<tr><td><font size=-1>$age&nbsp;才 $sex&nbsp;$occupation</font></td></tr>";
	echo "</table>";
	echo "<p><a href=\"#msgform\"><font size=-2>このメッセージへの返答はこちらから(一番下にあります)</font></a></p>";
	echo "</center>";
	echo "<hr width=\"200\">";

	if(!$offset)$offset = 0;
	echo "<p></p>";
	$nextoffset = $offset + $ini_msgrows;
	$prevoffset = $offset - $ini_msgrows;
	if($prevoffset < 0)$prevoffset = 0;

	$sql = "select count(*) from $ini_message_table where topic_id=$id";
	$result = pg_exec($sql);
	$total_rows = @pg_result($result,0,0);
	@pg_freeresult($result);

	$sql = "select * from $ini_message_table where topic_id = $id order by day desc limit $ini_msgrows offset $offset";

	$result = pg_exec($sql);
	if($result == false) {
		@pg_close($connection);
		echo "メッセージを読み込めませんでした。code=-2</body></html>";
		exit;
	}
	?>

	<center>
	<a href="<?php echo $ini_sitehome; ?>" target="_top">[HOME]</a> &nbsp;
	<?php
	if($offset != 0)echo "<a href=\"rbbsmessage.php3?id=$id&offset=$prevoffset\">[前のページを表示]</a>&nbsp;";
	if($nextoffset <= $total_rows) echo "<a href=\"rbbsmessage.php3?id=$id&offset=$nextoffset\">[次のページを表示]</a>&nbsp;";
	echo "<a href=\"index.php3\">[トピック一覧へ戻る]</a>";
	echo "<p></p>";



	$rows = @pg_numrows($result);
	if($rows == 0) {
		echo "<center><h3>これ以上発言はありません</h3></center>";
	}
	for($i = 0; $i < $rows; $i++) {
		$name = @pg_result($result,$i,"name");
		$message = @pg_result($result,$i,"message");
		$day = @pg_result($result,$i,"day");
		echo"<p><center><table><tr><td valign=\"top\">★</td><td><b>$name</b>さん<font size=-1>($day)</font></td><tr><td></td><td width=500>$message</td></tr></table></center></p>";
	}
	//echo "</center>";
	@pg_freeresult($result);
	@pg_close($connection);

} else {
	header("Location:index.php3");
}
?>
<center>
<hr width="200">
<a name="msgform">
<form method="post" action="rbbspost.php3">
<table>
	<tr>
		<td align="center">
		ここからメッセージを送ることができます。
		</td>
	</tr>
	<tr>
		<td>
		<input type="hidden" name="id" value="<?php echo $id; ?>">
		お名前：<br>
		<input type="text" name="name" size="20"><br>
		メッセージをどうぞ：<br>
		<textarea name="message" rows="10" cols="50"></textarea>
		</td>
	</tr>
	<tr>
		<td>
		●管理者の権限で削除される場合があります
		</td>
	</tr>
	<tr>
		<td>
		<input type="submit" value="投稿する"><input type="reset">
		</td>
	</tr>
</table>
</form>
<p>
<a href="<?php echo $ini_sitehome; ?>" target="_top"><img src="../image/bottan_home.jpg" width="40" height="40" border="0" alt="ホームページ" align="absmiddle"></a>
<?php
if($offset != 0)echo "<a href=\"rbbsmessage.php3?id=$id&offset=$prevoffset\">[前のページを表示]</a>&nbsp;";
if($nextoffset <= $total_rows)echo "<a href=\"rbbsmessage.php3?id=$id&offset=$nextoffset\">[次のページを表示]</a>";
?>
&nbsp;<a href="index.php3">[トピック一覧へ戻る]</a>
</p>
</center>
</body>
</html>





