<?php
class MessagesAction extends PublicAction{
	// 首页
		public function index(){
		 $Messages	= M("Messages");
		//导入分页类
         import("@.ORG.Page");
        //取得满足条件的记录数
         $count = $Messages->where('hidden=1')->count();
         $p = new Page($count, 5);
         //分页查询数据
         $list = $Messages->where('hidden=1')->order('id desc')->limit($p->firstRow.','.$p->listRows)->select();
         //分页显示
         $page = $p->show();
         //模板赋值显示
         $this->assign('list',$list);
         $this->assign("count", $count);
         $this->assign("page", $page);
 
		 $this->display();
	}
	

	// 处理表单数据
	public function insert() {
		$Messages	=	M("Messages");
		if($Messages->create()) {
		    if($_SESSION['verify'] != md5($_POST['verify'])) {
			$this->error('验证码错误！');
		     }
			if(false !==$Messages->add()) {
    			$this->success('留言添加成功，请等待管理员审核！');
            }else{
                $this->error('数据写入错误');
            }
		}else{
			header("Content-Type:text/html; charset=utf-8");
			exit($Messages->getError('数据写入错误').' [ <A HREF="javascript:history.back()">返 回</A> ]');
		}
	}

	
     public function _before_add() {
                $verify = build_verify(8);
                $_SESSION['attach_verify'] = $verify;
                $this->assign('verify',$verify);
        }
	

}
?>