<?php
session_start();
include "header.html";
require_once "../MessageBox.php";
include "../datasource.inc.php";
$Message = new MessageBox;
if ( empty($_SESSION["adminuser"]) and $_SESSION["userjs"] != "1") {
    $Message->setMessage("对不起，您没有权限进入后台管理!","index.html");
    $Message->showMessage();
}

?>
<table width="700" border="0" cellspacing="0" cellpadding="0">
        <tr>
         <TD vAlign=top><FONT color=#565656><IMG height=14
      src="../images/closedfold.gif" width=14>&nbsp;&nbsp;您当前的位置<BR><IMG
      height=15 src="../images/bar.gif" width=15><IMG height=14
      src="../images/openfold.gif" width=14>&nbsp;&nbsp;留言管理</FONT></TD>
        </tr>
</table>
<?php
	
	if ($_REQUEST['page']== "delete"){
		$query     = "delete from message where id='$_REQUEST[id]'";
		mysql_query($query);
		$Message->setMessage("删除成功!","message.php");
		$Message->showMessage();
	}
	$sql    = "select * from message order by id asc";
	$result = mysql_query($sql);
	$num    = mysql_num_rows($result);
	if ( $num>0 ){
	$last   = intval(($num-1)/20)+1;
	if ( $page < 1 ) $page=1;
	if ( $page > $last ) $page=$last; 
		mysql_data_seek($result,($page-1)*20);
		echo "<center>";
		echo "<table border=0 cellpadding=0 cellspacing=1 bgcolor=#6795B4 width=98%>";
		echo "<tr>";
		echo "<td height=18 bgColor=#EBF1F5><div align=center><b>标题</b></div></td>";
		echo "<td height=18 bgColor=#EBF1F5><div align=center><b>性别</b></div></td>";
		echo "<td height=18 bgColor=#EBF1F5><div align=center><b>全称</b></div></td>";
		echo "<td height=18 bgColor=#EBF1F5><div align=center><b>电话</b></div></td>";
		echo "<td height=18 bgColor=#EBF1F5><div align=center><b>传真</b></div></td>";
		echo "<td height=18 bgColor=#EBF1F5><div align=center><b>E_mail</b></div></td>";
		echo "<td height=18 bgColor=#EBF1F5><div align=center><b>留言内容</b></div></td>";
		echo "<td width=40 height=18 bgColor=#EBF1F5><div align=center><b>删除</b></div></td>";
		echo "</tr>";
		for ( $i=0;$i<20;$i++ ) {
			$row     = mysql_fetch_array($result);
			$id      = $row['id'];
			$body    = substr($row['body'],0,30);
			if ( $id ) {
				echo "<tr bgColor=#ffffff>";
				echo "<td height=18 bgColor=#ffffff><div align=center>$row[title]</td>";
				echo "<td height=18 bgColor=#ffffff><div align=center>$row[gender]</td>";
				echo "<td height=18 bgColor=#ffffff><div align=center>$row[name]</td>";
				echo "<td height=18 bgColor=#ffffff><div align=center>$row[tel]</td>";
				echo "<td height=18 bgColor=#ffffff><div align=center>$row[fax]</td>";
				echo "<td height=18 bgColor=#ffffff><div align=center>$row[email]</td>";
				echo "<td height=18 bgColor=#ffffff><div align=center>$row[message]</td>";
				
				echo "<td width=40 height=18 bgColor=#ffffff><div align=center><a title=点击删除本条记录 href=message.php?page=delete&id=$row[id] onclick=\"return confirm('确定要删除吗？')\"><img src=../images/clearicon.gif border=0></a></div></td>";
				echo "</tr>";
			}
		}
		echo "</table><br>";
		echo "<table width=500 border=0 cellspacing=0 cellpadding=0 height=24>";
		echo "<tbody>";
		echo "<tr><td colspan=4><center>";
		echo "总共找到<font color=red>$num</font>条记录,第<font color=red>$page</font>页,共<font color=red>$last</font>页。";
		echo "</center></td></tr><tr>";
		if ( $page <> 1 ) {
			echo "<td align=center>&nbsp;&nbsp;&nbsp;<a href=message.php?page=1>第一页</a></td>";
			echo "<td align=center><a href=message.php?page=".($page-1).">上一页</a></td>";
		}
		if ( $page <> $last ) {
			echo "<td align=center><a href=message.php?page=".($page+1).">下一页</a></td>";
			echo "<td align=center><a href=message.php?page=$last>最后一页</a></td>";
		}
		echo "</tbody>";
		echo "</tr>";
		echo "</table><br>";
		echo "</center>";
	} else {
		echo "<center>对不起，您还没有添加记录,<a href=message.php?page=add>我要添加</a>!</center>";
	}
?>
