<?php
$bt="程序安装";
include("./m/head.php");
header ( 'Content-Type:text/html;charset=utf-8 ');
?>
<body>
<div class="hr1">一线印象 安装</div><br/>
<?php
date_default_timezone_set("Asia/Shanghai");
if($_POST["host"]!=NULL){
$datetime=date("Y.m.d H:i");
$mysql_host=$_POST["host"];
$mysql_user=$_POST["user"];
$mysql_password= $_POST["password"];
$mysql_database= $_POST["database"];
$conn=@mysql_connect("$mysql_host","$mysql_user","$mysql_password");
if($conn && @mysql_select_db("$mysql_database",$conn))
{
    echo "<font color=\"green\">数据库连接成功！</font><br/>";
$t='<?php
date_default_timezone_set("Asia/Shanghai");
//include_once("zone/good.php");
$datetime=date("Y.m.d H:i");
$mysql_host="'.$mysql_host.'";
$mysql_user="'.$mysql_user.'";
$mysql_password="'.$mysql_password.'";
$mysql_database="'.$mysql_database.'";
$conn=mysql_connect("$mysql_host","$mysql_user","$mysql_password");
if(!$conn){ die("连接数据库失败：" . mysql_error());}
mysql_select_db("$mysql_database",$conn);
mysql_query("set character set \'utf-8\'");
mysql_query("set names \'utf-8\'");
?>';
file_put_contents("./m/conn.php",$t);


	//用户表
	if(mysql_query("CREATE TABLE user(id int primary key auto_increment, name varchar(6) not null unique, email varchar(50) not null unique, password varchar(30), sid varchar(40) not null unique,tx varchar(100),qm varchar(40)) DEFAULT CHARSET=utf8"))
    {
        echo "user 建表成功!<br/>";
    }
    else
    {
        if(mysql_query("SELECT * FROM user"))
        {
            echo "user数据表已存在!<br/>";   
        }
        else
        {
            echo "<font color=\"red\">user 建表失败!</font><br/>";    
        }           
    }


	//日记表
	if(mysql_query("CREATE TABLE diary(diaryid int primary key auto_increment,diarytxt text,diarywrite varchar(10),diarywriteid varchar(20),diaryzz varchar(2),diarytime varchar(100)) DEFAULT CHARSET=utf8"))
    {
        echo "diary 建表成功!<br/>";
    }
    else
    {
        if(mysql_query("SELECT * FROM diary"))
        {
            echo "user数据表已存在!<br/>";   
        }
        else
        {
            echo "<font color=\"red\">diary 建表失败!</font><br/>";    
        }           
    }

    
	//文章表
	if(mysql_query("CREATE TABLE wen(wenid int primary key auto_increment,wentxt text,img varchar(100),ding varchar(100),cai varchar(100)) DEFAULT CHARSET=utf8"))
    {
        echo "wen 建表成功!<br/>";
    }
    else
    {
        if(mysql_query("SELECT * FROM wen"))
        {
            echo "wen数据表已存在!<br/>";   
        }
        else
        {
            echo "<font color=\"red\">wen 建表失败!</font><br/>";    
        }           
    }


	//图片表
	if(mysql_query("CREATE TABLE pic(picid int primary key auto_increment,piczz varchar(20),piczzid varchar(20), pictxt text,pic varchar(100),pictime varchar(10)) DEFAULT CHARSET=utf8"))
    {
        echo "pic 建表成功!<br/>";
    }
    else
    {
        if(mysql_query("SELECT * FROM pic"))
        {
            echo "pic数据表已存在!<br/>";   
        }
        else
        {
            echo "<font color=\"red\">pic 建表失败!</font><br/>";    
        }           
    }


	//关注表
	if(mysql_query("CREATE TABLE att(fid varchar(100),bid varchar(100),time varchar(250)) DEFAULT CHARSET=utf8"))
    {
        echo "att 建表成功!<br/>";
    }
    else
    {
        if(mysql_query("SELECT * FROM att"))
        {
            echo "att数据表已存在!<br/>";   
        }
        else
        {
            echo "<font color=\"red\">att 建表失败!</font><br/>";    
        }           
    }


    echo "<p style=\"background:#AADD9A;padding: 5px 2px; \">建表过程结束，若无表单建立失败，就请进入<a href='index.php'>首页</a>看看吧！<br/>*<font color=\"red\">请立即注册账号，id为1的用户为默认管理员！</font><br/>
    请手动删除install.php或将其改名！</p>";

    $ok=1;
}
    else
    {
        echo "<font color=\"red\">数据库连接失败！</font>";
    }
}

if($ok!=1)
{
    echo "<b>感谢使用一线印象日记程序，您正在进行程序安装，请填写相关数据：</b><br/><br/> <form method='POST' action=''>
    数据库地址:<input type='text' name='host' /><br/> 数据库用户名: <input type='text' name='user' /><br/> 数据库密码: <input type='text' name='password' /><br/> 
    数据库名: <input type='text' name='database' /><br/> <br/><input type='submit' value='一键安装' /> </form> ";
}
?>
<br/><br/><div class="hr2">一线印象 日记程序 By 大隐<br/>版本：2014012101_2.0</div>
</body>
</html>