<?php
require_once 'Config.php';
/**
 * 留言类
 *
 * @author Wzb
 *        
 */
class USL_GuestBook extends USL_Base {
	/**
	 * 翻页对象
	 * 
	 * @var obj
	 */
	private $_pdObj;
	
	/**
	 * 构造类
	 */
	function __construct() {
		parent::__construct ();
		$this->AddGuestBook ();
		$this->_weizhi = "GuestBook";
// 		$this->_weizhi = "zxly";
		$this->_leftNav = USL_LeftNav::_OneNav ( "在线留言", "GuestBook.php" );
		$this->_address [] = array ("title" => "在线留言","url" => "" );
		
		$this->_pdObj = new COM_PagingDevice ( 10 );
		$this->_pdObj->_setDataList ( BLL_GuestBook::getList ( false, "*", $this->_pdObj->_getLimitArr () ) );
	}
	
	/**
	 * 设置变量值
	 */
	function _assignContent() {
		parent::_showComm ();
		$this->_tpl->assign ( "webName", COM_OftenFunction::setWebName ( "在线留言" ) );
		$this->_tpl->assign ( "theKeyWords", "在线留言" );
		$this->_tpl->assign ( "leftNav", $this->_leftNav ); // 左侧导航
		$this->_tpl->assign ( "thisName", "在线留言" ); // 栏目名称
		$this->_tpl->assign ( "address", $this->_address ); // 当前位置
		$this->_tpl->assign ( "tag", 'GuestBook' ); // 标签
		$this->_tpl->assign ( "dataList", $this->_pdObj->_getDataList () ); // 数据列表
		$this->_tpl->assign ( "pageInfo", $this->_pdObj->_getPageInfo () ); // 设置翻页信息
	}
	
	/**
	 * 添加留言
	 */
	private function AddGuestBook() {
		if (! array_key_exists ( 'action', $_POST ) || $_POST ['action'] != "add") {
			return;
		}
		$code = $_POST ['ImgCode'];
		if (empty ( $code ) || strtolower ( $_SESSION ['randcode'] ) != strtolower ( $code )) {
			die ( COM_OftenJavaScript::alertGoBack ( "验证码错误，请仔细输入！" ) );
		}
		
		if (BLL_GuestBook::guestAdd ( $_POST ) > 0) {
			die ( COM_OftenJavaScript::alertGoToUrl ( "恭喜您，留言添加成功！", "GuestBook.php" ) );
		} else {
			die ( COM_OftenJavaScript::alertGoBack ( "留言失败！" ) );
		}
	}
}

// 实例化
$configObj = BLL_WebSet::getOne ();
$thisPage = new USL_GuestBook ();
$thisPage->_assignContent ();
$thisPage->_tpl->display ( "Tpl/GuestBook.tpl" );

?>