<?
/*
	[SueamCMS] (C)2009-2010 ZMRNet Studio
	bbs_list.php by 2009-10-16 zmrnet
*/
require_once(dirname(__FILE__).'/include/manage.php');

$page_size = 30;

$type = trim($_GET['type']);
$page = (int) trim($_GET['page']);

if(!$page){$page=1;}
if($type==''){$type='post';}

$bbs = $_VDB['bbs'];
$this_title = $bbs[$type];

// $page_cnt
$_LST = $vdb->opendir($type.'/list');
if(empty($_LST)){
	$_LST = array();
}
$amount = count($_LST);

if($amount){
	if($amount<$page_size){$page_cnt=1;}
	if($amount%$page_size){
		$page_cnt = (int)($amount/$page_size)+1;
	}else{
		$page_cnt = $amount/$page_size;
	}
}else{
	$page_cnt = 0;
}

$page_ended = $page + 5;
$page_start = $page - 5;
if($page_ended>$page_cnt){
	$page_ended=$page_cnt;
	$page_start = $page_ended - 10;
}
if($page_start<0) $page_start=0;

$page_str = '';
if($page==1){
	$page_str .= '首页 上一页 ';
}else{
	$page_str .= '<a href="?type='.$type.'&page=1">首页</a> ';
	$page_str .= '<a href="?type='.$type.'&page='.($page-1).'">上一页</a> ';
}
for($i=$page_start;$i<$page_ended;$i++){
	$page_str .= '<a href="?type='.$type.'&page='.($i+1).'">'.($i+1).'</a> ';
}
if($page_cnt&&($page!=$page_cnt)){
	$page_str .= '<a href="?type='.$type.'&page='.($page+1).'">下一页</a> ';
	$page_str .= '<a href="?type='.$type.'&page='.$page_cnt.'">尾页</a>';
}else{
	$page_str .= '下一页 末页';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><? echo $sys_title; ?></title>
<link href="images/sueam.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div style="margin:20px;">
	<div style="margin:10px;font-size:14px;color:green"><b><? echo $this_title;?></b></div>
	<div class="sec_menu" style="padding:10px;color:green;">
	<div style="text-align:left;">
		<font color="red">[</font>&nbsp;
		<font color="blue">留言操作</font>&nbsp;
		<font color="red">]</font>
		<font color="blue">留言标题</font>
		(留言时间)
	</div>
<?
$plst = array_chunk($_LST, $page_size);
$rs = $plst[$page-1];
$i = 0;
while($row=$rs[$i++]){
	$bbs_id		= $row['id'];
	$bbs_name	= $row['name'];
	$bbs_post	= $row['post'];
	$bbs_time	= $row['time'];
	$bbs_reply	= $row['reply'];
	$bbs_rtime	= $row['rtime'];
?>
	<div style="text-align:left;line-height:20px;">
		<font color="red">[</font>
		<a href="bbs_rep.php?type=<? echo $type; ?>&id=<? echo $bbs_id; ?>">回复</a>
		<a href="bbs_del.php?type=<? echo $type; ?>&id=<? echo $bbs_id; ?>">删除</a>
		<font color="red">]</font>
		<font color="blue"><? echo $bbs_name; ?></font>
		(<? echo $bbs_time; ?>)<br>
		<font color="black"><? echo $bbs_post; ?></font>
<? if($bbs_reply){ ?>
		<div style="margin:10px;padding:10px;color:black;text-align:left;border:red 1px dashed;">
			回复：( <? echo $bbs_rtime; ?> )<br><? echo $bbs_reply; ?>
		</div>
<? } ?>
	</div>
<?
}
unset($rs);
unset($plst);
unset($_LST);

unset($_VDB);
unset($vdb);
?>
	</div>
</div>
<div style="margin:20px;">
	<div class="sec_menu"><? echo $page_str; ?></div>
</div>
</body>
</html>