<?php
class install extends Checklogin{	
	
	public function init(){ 
		$this->mysql->query("CREATE TABLE IF NOT EXISTS `".DB_PRE."guestbook` (
  `id` int(8) unsigned NOT NULL auto_increment,
  `title` char(80) NOT NULL,
  `userid` int(8) unsigned NOT NULL default '0',
  `email` char(80) NOT NULL,
  `qq` int(15) unsigned NOT NULL,
  `username` char(20) NOT NULL,
  `content` text NOT NULL,
  `inputtime` int(10) unsigned NOT NULL default '0',
  `state` tinyint(1) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=gbk;");

		$this->mysql->query("CREATE TABLE IF NOT EXISTS `".DB_PRE."guestbook_reply` (
  `gid` int(8) unsigned NOT NULL default '0',
  `reply_content` text NOT NULL,
  `replytime` int(10) unsigned NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=gbk;");
		
		$this->mysql->query("INSERT INTO `".DB_PRE."config` (`id`, `config_array`, `config_tag`) VALUES(5, 'array (\n  ''isaudit'' => ''1'',\n  ''ismember'' => ''2'',\n  ''openc'' => NULL,\n)', 'guestbook');");

		$this->mysql->db_insert("menu","`parentid`=4,`title`='留言板管理',`url`='###',`sort`=0,`is_show`=1");
		$pid=$this->mysql->insert_id();
		$this->mysql->db_insert("menu","`parentid`=".$pid.",`title`='留言管理',`url`='index.php?m=guestbook&c=admin',`sort`=0,`is_show`=1");
		$this->mysql->db_insert("menu","`parentid`=".$pid.",`title`='留言配置',`url`='index.php?m=guestbook&c=admin&f=setting',`sort`=0,`is_show`=1");
		
		$text="ok";
		$file=MOD_PATH."guestbook/install_ok.txt";
		creat_inc($file,$text);
		showmsg(C('success_update_cache'),'-1');
	}
	
	public function uninstall(){
		$this->mysql->del_table("guestbook");  //删除数据表
		$this->mysql->db_delete("menu","`title`='留言板管理'");
		$this->mysql->db_delete("menu","`title`='留言管理'");
		$this->mysql->db_delete("menu","`title`='留言配置'");
		$this->mysql->db_delete("config","`id`='5'");
		
		$ok=MOD_PATH."guestbook/install_ok.txt";
		if(file_exists($ok)){   //删除install_ok
			unlink($ok);
		}
		showmsg(C('success_update_cache'),'-1');
	}
}
?>