<?php
class InstallAction extends Action{
	function _initialize(){
		header("Content-Type:text/html; charset=utf-8");
    }
	public function index()
	{
		$tb=C('DB_PREFIX');
		$m=M();
		$rs=$m->query("select * from ".$tb."user limit 1");
		if($rs)
		{
			echo '程序已经安装成功';
			exit;
		}
		$this->display();
	}
	public function start()
	{
		$msg="";
		$tb=C('DB_PREFIX');
		$sql="CREATE TABLE IF NOT EXISTS `".$tb."attention` (`id` int(10) NOT NULL AUTO_INCREMENT, `userid` int(10) NOT NULL,`objuser` int(10) NOT NULL,`time` int(10) NOT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
		$msg.=$this->exesql($sql,'attention表创建操作');
		$sql2="CREATE TABLE IF NOT EXISTS `".$tb."invite` (`id` int(10) NOT NULL AUTO_INCREMENT,`userid` int(10) NOT NULL,`time` int(10) NOT NULL,`code` varchar(17) NOT NULL,`is_use` tinyint(1) NOT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
		$msg.=$this->exesql($sql2,'invite表创建操作');
		$sql3="CREATE TABLE IF NOT EXISTS `".$tb."score` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT, `userid` int(10) unsigned NOT NULL,`types` tinyint(1) NOT NULL,`num` int(10) NOT NULL,`memo` varchar(255) NOT NULL, `time` int(10) NOT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
		$msg.=$this->exesql($sql3,'score表创建操作');
		$sql4="CREATE TABLE IF NOT EXISTS `".$tb."site` (`id` int(5) NOT NULL AUTO_INCREMENT,`title` varchar(255) NOT NULL,`description` varchar(255) NOT NULL,`keyword` varchar(255) NOT NULL,`domain` varchar(50) NOT NULL,`app_path` varchar(20) DEFAULT NULL,`is_reg` tinyint(1) DEFAULT NULL,`is_rewrite` tinyint(1) DEFAULT NULL,`no_user` text,`no_tag` text,`is_invite` tinyint(1) DEFAULT NULL,`is_invite_free` int(10) DEFAULT NULL,`user_socre` int(10) DEFAULT NULL,`copyright` text NOT NULL,`icp` varchar(20) DEFAULT NULL, `user_check` tinyint(1) DEFAULT NULL,`http_check` tinyint(1) DEFAULT NULL,`mail_check` tinyint(1) DEFAULT NULL,`ip_check` int(4) DEFAULT NULL,`send_check` int(4) DEFAULT NULL,`login_check` tinyint(1) DEFAULT NULL,`mail_type` tinyint(1) DEFAULT NULL,`smtp` varchar(30) DEFAULT NULL,`smtp_user` varchar(20) DEFAULT NULL,`smtp_pwd` varchar(20) DEFAULT NULL,`receive` varchar(40) DEFAULT NULL,`mailtext` text,`score_ok` tinyint(1) DEFAULT NULL,`login_score` int(5) DEFAULT NULL,`create_get` int(5) DEFAULT NULL,`replay_get` int(5) DEFAULT NULL,`create_del` int(5) DEFAULT NULL,`replay_del` int(5) DEFAULT NULL,`show_score` tinyint(1) DEFAULT NULL,`hot_time` int(10) DEFAULT NULL,`hot_score` int(5) DEFAULT NULL,`catch_time` int(5) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
		$msg.=$this->exesql($sql4,'site表创建操作');
		$sql5="INSERT INTO `".$tb."site` (`id`, `title`, `description`, `keyword`, `domain`, `app_path`, `is_reg`, `is_rewrite`, `no_user`, `no_tag`, `is_invite`, `is_invite_free`, `user_socre`, `copyright`, `icp`, `user_check`, `http_check`, `mail_check`, `ip_check`, `send_check`, `login_check`, `mail_type`, `smtp`, `smtp_user`, `smtp_pwd`, `receive`, `mailtext`, `score_ok`, `login_score`, `create_get`, `replay_get`, `create_del`, `replay_del`, `show_score`, `hot_time`, `hot_score`, `catch_time`) VALUES
(1, '大嶝开源微博', '大嶝开源微博', '大嶝开源微博 ', 'http://www.dadeng.org', '', 0, 0, 'admin|大嶝|vip|管理员', '发票|充值', 1, 10, 200, 'copy版权所有 <script src=\"http://s4.cnzz.com/stat.php?id=2145590&web_id=2145590\" language=\"JavaScript\"></script>', 'icpbei', 0, 0, 0, 10, 0, 1, 1, 'smtp.163.com', '', '', 'services@dadeng.org', '您好：@userid@欢迎注册@site@，这是来自系统的激活邮件！\r\n点击下面的连接可以激活！', 1, 2, 2, 1, 4, 2, 1, 48, 30, 20);";
		$msg.=$this->exesql($sql5,'site表初始数据操作');
		$sql6="CREATE TABLE IF NOT EXISTS `".$tb."topic` (`id` int(10) NOT NULL AUTO_INCREMENT,`title` varchar(160) NOT NULL,`userid` int(10) NOT NULL,`time` int(10) NOT NULL,`groupid` int(10) NOT NULL,`parentid` int(10) NOT NULL,`ding` int(10) NOT NULL,`cai` int(10) NOT NULL,`pass` int(10) NOT NULL,`tagid` varchar(30) DEFAULT NULL,`status` tinyint(1) NOT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
		$msg.=$this->exesql($sql6,'topic表创建操作');
		$sql11="insert into ".$tb."topic(id,title,userid,time,groupid,parentid,ding,cai,pass,tagid,status) values(1, '欢迎使用大嶝开源微博',1,".time().",1, 0, 0, 0, 0, '0',1)";
		$msg.=$this->exesql($sql11,'topic初始数据写入操作');
		$sql7="CREATE TABLE IF NOT EXISTS `".$tb."topic_group` ( `id` int(10) NOT NULL AUTO_INCREMENT,`groupname` varchar(100) NOT NULL,`parentid` int(10) DEFAULT NULL,`create_user` int(10) NOT NULL,`sort` int(10) NOT NULL DEFAULT '0',`icon` varchar(30) DEFAULT NULL,`time` int(10) NOT NULL,`is_default` tinyint(1) NOT NULL DEFAULT '0',PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
		$msg.=$this->exesql($sql7,'topic_group表创建操作');
		$sql12="INSERT INTO `".$tb."topic_group` (`id`,`groupname`,`parentid`,`create_user`,`sort`,`icon`,`time`,`is_default`)VALUES(1, '今日广播',0,1, 0,'', ".time().", 1)";
		$msg.=$this->exesql($sql12,'topic_group初始数据写入操作');
		$sql8="CREATE TABLE IF NOT EXISTS `".$tb."topic_tag` (`id` int(10) NOT NULL AUTO_INCREMENT,`title` varchar(100) NOT NULL,`create_user` int(10) NOT NULL,`create_time` int(10) NOT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
		$msg.=$this->exesql($sql8,'topic_tag表创建操作');
		$sql9="CREATE TABLE IF NOT EXISTS `".$tb."user` (`id` int(10) NOT NULL AUTO_INCREMENT,`userid` varchar(20) NOT NULL,`mail` varchar(50) DEFAULT NULL,`passwd` varchar(32) NOT NULL,`homepage` varchar(30) NOT NULL,`icon` varchar(17) DEFAULT NULL,`create_time` int(10) NOT NULL,`create_ip` varchar(16) NOT NULL,`groupid` int(10) DEFAULT NULL,`roleid` int(10) NOT NULL,`login_time` int(10) DEFAULT NULL,`login_ip` varchar(16) DEFAULT NULL,`score` int(10) NOT NULL,`is_top` tinyint(1) DEFAULT NULL,`top_time` int(10) DEFAULT NULL,`nickname` varchar(10) DEFAULT NULL,`sex` tinyint(1) DEFAULT NULL,`memo` varchar(140) DEFAULT NULL,`status` tinyint(1) NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
		$msg.=$this->exesql($sql9,'user表创建操作');
		$sql10="INSERT INTO `".$tb."user` (`id`, `userid`, `mail`, `passwd`, `homepage`, `icon`, `create_time`, `create_ip`, `groupid`, `roleid`, `login_time`, `login_ip`, `score`, `is_top`, `top_time`, `nickname`, `sex`, `memo`, `status`) VALUES(1, 'admin', NULL, '".md5('admin')."', 'admin', '', 1278156714, '127.0.0.1', 9, 9, 1279252802, '127.0.0.1', 0, 0, 0, '', 2, '大嶝开源微博', 1);";
		$msg.=$this->exesql($sql10,'user表初始数据写入操作');
		$msg.="程序安装完成<a href='/'>访问首页</a>";
		$this->assign('msg',$msg);
		$this->display();
	}
	private function exesql($sql,$info)
	{
		$m=M();
		$m->execute($sql);
		return $info.'成功<br/>';
	}
}
?>