<?php
include "Include/config.php";
include "Include/db.php";
if(isset($_GET['install'])){
$sql1="CREATE TABLE `chat_ad` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(100) NOT NULL,
  `content` text NOT NULL,
  `lasttime` int(11) NOT NULL,
  `sleeptime` int(11) NOT NULL,
  `starttime` datetime NOT NULL,
  `stat` smallint(1) NOT NULL default '1',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;";
$sql2="CREATE TABLE `chat_msg` (
  `Id` int(11) NOT NULL auto_increment,
  `IsPublic` varchar(10) NOT NULL default '0',
  `RoomId` varchar(50) NOT NULL default '0',
  `FromChatId` varchar(50) NOT NULL,
  `ToChatId` varchar(50) default NULL,
  `Content` text,
  `Time` int(11) NOT NULL default '0',
  PRIMARY KEY  (`Id`),
  KEY `Time` (`Time`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;";
$sql3="CREATE TABLE `chat_music` (
  `id` int(11) NOT NULL auto_increment,
  `url` mediumtext NOT NULL,
  `title` varchar(100) NOT NULL,
  `singer` varchar(100) NOT NULL,
  `owner` varchar(100) NOT NULL default 'SYSTEM',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;";
$sql4="CREATE TABLE `chat_room` (
  `Id` int(11) NOT NULL auto_increment,
  `Name` varchar(50) NOT NULL,
  `Image` varchar(200) NOT NULL,
  `Ad` text,
  PRIMARY KEY  (`Id`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;";
$sql5="CREATE TABLE `chat_user` (
  `UserId` int(11) NOT NULL auto_increment,
  `UserSex` int(11) NOT NULL default '0',
  `IsOnLine` int(11) NOT NULL default '0',
  `Point` int(11) NOT NULL default '0',
  `Role` varchar(20) NOT NULL default '0',
  `Enabled` int(11) NOT NULL default '0',
  `UserName` varchar(50) NOT NULL,
  `Age` int(11) NOT NULL,
  `UserPassWord` varchar(50) default NULL,
  `RegIP` varchar(50) default NULL,
  `LastIP` varchar(50) default NULL,
  `FirstTime` datetime NOT NULL default '0000-00-00 00:00:00',
  `EnterTime` datetime NOT NULL default '0000-00-00 00:00:00',
  `LastTime` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`UserId`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;";
$sql6="CREATE TABLE `chat_user_online` (
  `Id` int(11) NOT NULL auto_increment,
  `ChatId` varchar(50) NOT NULL,
  `RoomId` varchar(100) NOT NULL,
  `Name` varchar(100) NOT NULL,
  `Sex` int(11) NOT NULL default '0',
  `Color` varchar(50) NOT NULL,
  `Role` int(11) NOT NULL default '0',
  `IP` varchar(20) NOT NULL,
  `EnterTime` int(11) NOT NULL default '0',
  `LastTime` int(11) NOT NULL default '0',
  PRIMARY KEY  (`Id`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;";
$sql7="CREATE TABLE `chat_admin` (
  `id` int(11) NOT NULL auto_increment,
  `Name` varchar(50) NOT NULL,
  `RoomId` varchar(200) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;";
$db->query($sql1);echo "chat_ad:创建成功<br>";
$db->query($sql2);echo "chat_msg:创建成功<br>";
$db->query($sql3);echo "chat_music:创建成功<br>";
$db->query($sql4);echo "chat_room:创建成功<br>";
$db->query($sql5);echo "chat_user:创建成功<br>";
$db->query($sql6);echo "chat_user_online:创建成功<br>";
$db->query($sql7);echo "chat_admin:创建成功<br>";
rename("install.php","install.txt");
echo "<br><br>请手动install.php文件<a href='/Admin.php'>进入管理后台</a>";
}
else
{
	echo "<h3>数据库安装<h3>该文件只导入数据库结构<br>第一步：请修改config.php文件并建立相应数据库！聊天室设置请修改admin_config.php文件<br>第二步：点击这里安装 <input onclick=\"location.href='?install'\" type='submit' value='安装'>";
}
?>