<?php
/*
'#################################################################
'# 程序名称：中环CMSV2.0
'# 授权方式：免费软件
'# 作者：善
'# 联系QQ:9118847
'# 作者网站:http://www.ps173.com
'# 发布时间：2015-6-10
'# 声明：欢迎广大的PHP爱好者一起共同探讨
'# 声明：各种用途均可免费使用、自由传播，但必须保留程序代码中的版权信息。
'#################################################################
 */

class BookAction extends CommonAction{
	private $book;

	public function __construct(){
		parent::__construct();
		$this->book = new BookModel();
	}

	public function check($post){
		if(!val::check($post['name'])){
			$this->msg('用户名不能为空');
			return false;
		}

		if(!val::check($post['cont'])){
			$this->msg('评论内容不能这空');
		}

		return $post;
	}

	public function fpro(){
		if(isset($_POST['id'])){
			if(isset($_POST['audits'])){
				if($this->book->fpro($_POST['id'], "state='0'")){
					$this->msg('批量审核成功');
				}else{
					$this->msg('批量审核失败');
				}
			}else if(isset($_POST['locks'])){
				if($this->book->fpro($_POST['id'], "state='2'")){
					$this->msg('批量锁定成功');
				}else{
					$this->msg('批量锁定失败');
				}
			}
		}else{
			$this->msg('请选择你要操作的评论');
		}
	}

	public function del(){
		if(isset($_GET['id']) && isset($_GET['aid'])){
			if($this->book->delete($_GET['id'])){
				$art = D("Article");
				$art->setnums($_GET['aid'], 'del');
				$this->msg('删除评论成功');
			}else{
				$this->msg('删除评论失败');
			}
		}
	}

	public function mod(){
		if(isset($_GET['id'])){
			$data = $this->book->viewbook($_GET['id']);
			if(!$data){
				$this->msg('该评论不存在，或已经被删除');
			}
		}

		$this->assign("data", $data);
		$this->display();
	}

	public function update(){
		if(isset($_POST['sub'])){
			if($this->check($_POST)){
				if($this->book->update($_POST)){
					$this->msg('修改评论成功');
				}else{
					$this->msg('数据保持原样');
				}
			}else{
				$this->msg('修改评论失败');
			}
		}
	}

	public function index(){
		if(isset($_GET['id']) && isset($_GET['state'])){
			$post['id'] = $_GET['id'];
			$post['state'] = $_GET['state'];
			$this->book->setstate($post);
		}

		if(isset($_GET['aid'])){
			$where['aid'] = $_GET['aid'];
			$ipage = "aid/{$_GET['aid']}";
		}

		$page = new Page($this->book->book_total(@$where), 15, @$ipage);
		$this->assign("fpage", $page->page);
		$this->assign("book", $this->book->showbook(@$where, $page->limit));
		$this->assign("page", $page->pageinfo());
		$this->display();
	}

}

?>