<?php
/***
*
*@package binzcms
*@version $id:ModFrontGuestbookClass.php, v 1.0
*@author 斌子
*@Tue Sep 07 16:14:47 GMT 2010
*@copyright (c) 2009-2010 binzcms
*
*/
if(!defined("BINZCMS")) {
	die("hacking");
}
/**
 *
 * ModFrontGuestbookClass
 * 留言板应用类
 * 
 */
class ModFrontGuestbookClass extends BaseClass {
	/**
	 * __construct
	 *
	 * 构造函数
	 * @access  public（权限）
	 */
	public function __construct($act) {
		parent::__construct($act);
	}
	/**
	 * mod_front_leave_list
	 *
	 * 留言列表
	 * @access  public（权限）
	 * 
	 * @return  array
	 */
	public function mod_front_leave_list($binz_page,$page_num) {
		$leave_array			= array();
		$leave_sql				= '';
		$limit_sql				=  "LIMIT ".(intval($binz_page)-(intval($binz_page)>=1 ? 1 : 0))*$page_num.",$page_num";

		$where					= "WHERE 1=1";
		if ($_GET['search_type'] == 'content') {
			$where				.= " AND leave_body LIKE '%".$_GET['keywords']."%'";
		} elseif ($_GET['search_type'] == 'member') {
			$where				.= " AND leave_writer='".$_GET['keywords']."'";
		}

		$leave_sql				= "SELECT * FROM #binz#leave
									$where
									ORDER BY leave_id DESC ".$limit_sql;
		$leave_array['list']	= $this->binz_db->set_select_sql($leave_sql);
		$leave_array['count']	= $this->binz_db->set_select_sql("SELECT COUNT(leave_id) AS leave_num FROM #binz#leave ".$where,0);

		return $leave_array;
	}
	/**
	 * mod_front_gusetbook_save
	 *
	 * 留言保存
	 * @access  public（权限）
	 * @return  bool
	 */
	public function mod_front_gusetbook_save() {
		if(LEAVE_LOGIN == '1' and $_SESSION['member_name'] == '') {
			return 2;		//登录后才可以留言
		}
		if(LEAVE_CODE == '1') {
			/*验证码判断*/
			if(strtolower(trim($_POST['post_code'])) != $_SESSION['binz_code']) {
				return 4;		//验证码错误返回信息
			}
		}
		$book_array					= array();
		$insert_state				= false;

		$book_array['leave_id']		= 'NULL';
		$book_array['leave_writer']	= $_SESSION['member_name'] == '' ? 'guest' : $_SESSION['member_name'];
		$book_array['leave_body']	= htmlspecialchars(trim($_POST['comment']),ENT_QUOTES);
		$book_array['leave_time']	= time();
		$book_array['leave_ip']		= $this->binz_common->get_true_ip();
		
		$not_allow_word			= explode('|',NOT_ALLOW_WORD);
		if(is_array($not_allow_word) and !empty($not_allow_word)) {
			$book_array['leave_body']	= @str_replace($not_allow_word,'***',$book_array['leave_body']);
		}
		
		$insert_state	= $this->binz_db->set_insert_sql_value('#binz#leave',$book_array);
		if($insert_state) {
			return true;
		} else {
			return false;
		}
	}
	/**
	 * __destruct
	 *
	 * 析构函数
	 * @access  public（权限）
	 */
	public function __destruct() {

	}
}
?>