<?php
/**
 * 前台留言控制器
 *
 * @package Action
 * @subpackage Home
 * @stage 1.0
 * @author billow.wang <admin@ivears.com>
 * @date 2013-05-28
 */
class GuestbookAction extends HomeAction{
    
    public function _initialize() {
        parent::_initialize();
    }
    
	public function post(){
		$ary_post = $this->_post();
		/*
        $verify = session("code");
        if ($verify != md5($ary_post['vcode'])) {
                $this->error('验证码错误');
				exit;
        }
		*/
	
		
				$ip = get_client_ip();
                $ary_data = array(
                    'title'        =>  $ary_post['txtname'],
                    'tel'       =>  trim($ary_post['txtteltwo']),
					'address'=>trim($ary_post['txtaddress']),
					'email'=>trim($ary_post['txtemail']),
					'content'=>trim($ary_post['txtarea']),
					'class'=>trim($ary_post['class']),
                    'addtime'    =>  date("Y-m-d H:i:s"),
                    'ip'      =>  $ip,
                    'visible'         => 0
                );
				//print_r($ary_data);
                $ary_result = D('Message')->add($ary_data);
				//print_r($ary_result);
				//exit;
                if(FALSE !== $ary_result){
                    $this->success("申请成功",'/Guestbook/',2);
                }else{
                    $this->error("申请失败");
                }		
	}
    public function index(){
		if($_POST){
			$this->post();
			exit;
		}else{
       		 $this->display();
		}
    }
}