<?php
class index extends db{	
	function __construct(){
		parent::__construct();
		assign('menu',get_menu(0,1));
	}
	
	public function init(){ 
		template("guestbook/guestbook_list");
	}
	
	public function add(){
		$guest_arr=base::load_cache('cache_set_guestbook','_guestbook');
		$member_user=Cookie::_getcookie('member_user');
		if(!empty($guest_arr)){
			if($guest_arr['isopen']==1){
				showmsg($guest_arr['openc'],'-1');
			}
			
			if($guest_arr['ismember']==1 && empty($member_user)){
				showmsg(C('admin_not_exist'),'index.php?m=member&f=login');
			}
		}
		
		assign('member_user',$member_user);
		template("guestbook/guestbook_add");
	}
	
	public function add_save(){
		$guest_arr=base::load_cache('cache_set_guestbook','_guestbook');
		$title=safe_html($_POST['title']);
		$username=safe_html($_POST['username']);
		$qq=safe_html($_POST['qq']);
		$email=safe_html($_POST['email']);
		$content=safe_html($_POST['content']);
		$inputtime=datetime();
		$member_userid=intval(Cookie::_getcookie('member_userid'));
		if(empty($member_userid)){
			$member_userid=0;
		}
		
		if(empty($title)){
			showmsg(C('material_not_complete'),'-1');
		}
		
		if(!empty($guest_arr)){
			if($guest_arr['isaudit']==1){
				$state=0;
			}else{
				$state=1;
			}
		}else{
			$state=1;
		}
		
		$sql="insert into ".DB_PRE."guestbook(title,userid,email,qq,username,content,inputtime,state) values('{$title}','{$member_userid}','{$email}','{$qq}','{$username}','{$content}','{$inputtime}','{$state}')";
		$this->mysql->query($sql);
		
		showmsg(C('success'),'-1');
	}

}
?>