<?
/*
	[Sueam CMS] (C)2009-2010 ZMRNet Studio
	post.php by 2009-10-16 zmrnet
*/
header('Content-Type:text/html;charset=utf-8');

require_once(dirname(__FILE__).'/../sueam/include/conn.php');
require_once(dirname(__FILE__).'/../sueam/include/function.php');

$bbs_act = trim($_POST['action']);

if($bbs_act=='add'){
	$bbs_name = trim($_POST['name']);
	$bbs_code = trim($_POST['code']);
	$bbs_post = trim($_POST['post']);
	$bbs_post = htmlspecialchars_decode($bbs_post);
	$bbs_type = key($_VDB['bbs']);
	
	if($bbs_name==''){
		die(refresh('post.html').'<script>alert(\'留言标题不能为空！\')</script>');
	}
	if($bbs_post==''){
		die(refresh('post.html').'<script>alert(\'留言内容不能为空！\')</script>');
	}

	if($bbs_code!=$_SESSION['rand_code']){
		die(refresh('post.html').'<script>alert(\'验证码错误！\');</script>');
	}

	$_LST = $vdb->opendir($bbs_type.'/list');
	if(empty($_LST)){
		$_LST = array();
		$bbs_id = 1;
	}else{
		$_MAX = max($_LST);
		$bbs_id = $_MAX['id'] + 1;
		unset($_MAX);
	}
	$bbs_time = date('Y-m-d H:i:s', time()+(time_zone*3600));

	$_BBS = array();
	$_BBS['id']		= $bbs_id;
	$_BBS['name']	= $bbs_name;
	$_BBS['post']	= $bbs_post;
	$_BBS['time']	= $bbs_time;
	$_BBS['reply']	= '';
	$_BBS['rtime']	= '';
	array_unshift($_LST, $_BBS);
	$vdb->writedir($bbs_type.'/list', $_LST);
	unset($_BBS);
	unset($_LST);
	
	die(refresh('list/1.html').'<script>alert(\'留言发表成功！\')</script>');
}
?>