<?php
/**
 * 留言板逻辑层
 *
 * @author Wzb
 *        
 */
class BLL_GuestBook {
	/**
	 * 回复留言
	 *
	 * @param array $theArray
	 * @return int
	 */
	public static function repaly($theArray) {
		$newArray = array ();
		$newArray ['id'] = intval ( $theArray ['id'] );
		$newArray ['repaly'] = COM_OftenFunction::delSpecialChar ( $theArray ['repaly'] );
		return DAL_GuestBook::edit ( $newArray );
	}
	
	/**
	 * 留言审核
	 *
	 * @param array $theArray
	 * @return int
	 */
	public static function checkup($theArray) {
		$newArray = array ();
		$newArray ['id'] = intval ( $theArray ['id'] );
		$newArray ['isSh'] = intval ( $theArray ['isSh'] );
		return DAL_GuestBook::edit ( $newArray );
	}
	
	/**
	 * 留言添加
	 */
	public static function guestAdd($theArray) {
		$newArray = array ();
		$newArray ['subject'] = COM_OftenFunction::delSpecialChar ( $theArray ['subject'] );
		$newArray ['nickname'] = COM_OftenFunction::delSpecialChar ( $theArray ['nickname'] );
		$newArray ['tel'] = COM_OftenFunction::delSpecialChar ( $theArray ['tel'] );
		$newArray ['email'] = COM_OftenFunction::delSpecialChar ( $theArray ['email'] );
		$newArray ['content'] = COM_OftenFunction::delSpecialChar ( $theArray ['content'] );
		$newArray ['ip'] = $_SERVER ["REMOTE_ADDR"];
		$newArray ['addTime'] = date ( "Y-m-d" );
		$newArray ['isDelete'] = 0;
		$newArray ['yzm'] = $theArray ['yzm'];
		if (! isset ( $_SESSION )) {
			session_start ();
		}
		if (strtolower ( $_SESSION ['code'] ) != strtolower ( $theArray ['yzm'] )) {
			echo COM_OftenJavaScript::alertGoBack ( "验证码错误！" );
			exit ();
		}
		return DAL_GuestBook::add ( $newArray );
	}
	
	/**
	 * 删除指定条留言
	 *
	 * @param string $idList 多个必须用-分割开
	 * @return string string error1 id字符串为空|error2 删除失败|ok 删除成功
	 */
	public static function delete($idList) {
		if (empty ( $idList )) {
			return 'error1';
		}
		if (DAL_GuestBook::delete ( $idList )) {
			return 'ok';
		} else {
			return 'error2';
		}
	}
	
	/**
	 * 获取一个留言
	 *
	 * @param int $id
	 * @param string $code 需要的字段 默认值：*
	 * @return array
	 */
	public static function getOne($id, $code = '*') {
		return DAL_GuestBook::getOne ( intval ( $id ), $code );
	}
	
	/**
	 * 获取列表
	 *
	 * @param bool $isSh 是否显示未审核的留言
	 * @param string $code 需要的字段 默认值：*
	 * @param array $limitArr = array('begin'=>0,'num'=>0)
	 * @return array
	 */
	public static function getList($isSh, $code = '*', $limitArr = array('begin'=>0,'num'=>0)) {
		settype ( $isSh, "boolean" );
		return DAL_GuestBook::getList ( $isSh, $code, $limitArr );
	}
}
?>