<?php
error_reporting (0); 

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>天宇采集程序数据库安装向导</title>
<script src="../include/dedeajax2.js" language="javascript" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
<!--
    function $o(tid){
        return document.getElementById(tid);
    }
    function TestDb()
    {
		var dbhost = $o('dbhost').value;
        var dbuser = $o('dbuser').value;
        var dbpwd = $o('dbpwd').value;
		$o('havedbsta').innerHTML='<img src=\'images/ajax-loader.gif\'>';
        var myajax = new DedeAjax($o('dbpwdsta'),false,true,'-','-','...');
        myajax.SendGet2('index.php?step=10&dbhost='+dbhost+'&dbuser='+dbuser+'&dbpwd='+dbpwd);
		DedeXHTTP = null;
		HaveDB();
    }
	
	function HaveDB()
    {
		var dbhost = $o('dbhost').value;
        var dbname = $o('dbname').value;
        var dbuser = $o('dbuser').value;
        var dbpwd = $o('dbpwd').value;
        var myajax = new DedeAjax($o('havedbsta'),false,true,'-','-','...');
        myajax.SendGet2('index.php?step=10&dbhost='+dbhost+'&dbuser='+dbuser+'&dbpwd='+dbpwd+'&dbname='+dbname);
		DedeXHTTP = null;
    }
    
	function GetRemoteDemo()
	{
		
		$o('_remotesta').innerHTML='<img src=\'images/ajax-loader.gif\'>';
		var myajax = new DedeAjax($o('_remotesta'),false,true,'-','-','...');
		myajax.SendGet2('index.php?step=11');
		DedeXHTTP = null;
	}
	
    function DoInstall()
    {
        //$o('postloader').style.display = 'block';
        document.form1.submit();
    }
-->
</script>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id='postloader' class='waitpage'></div>

<div class="top">
    <div class="top-logo">
        
    </div>
    <div class="top-link">
        <ul>
            <li><a href="http://www.ababb.com" target="_blank">官方网站</a></li>
            
        </ul>
    </div>
    <div class="top-version">
        <!-- 版本信息 -->
        <h2>天宇采集程序</h2>
    </div>
</div>

<div class="main">
    <div class="pleft">
        <dl class="setpbox t1">
            <dt>安装步骤</dt>
            <dd>
                <ul>
                    <li class="succeed">许可协议</li>
                    <li class="succeed">环境检测</li>
                    <li class="now">参数配置</li>
                    <li>正在安装</li>
                    <li>安装完成</li>
                </ul>
            </dd>
        </dl>
    </div>
    <div class="pright">
	
	  <?php
error_reporting(0);
//-----------------------------使用说明-------------------------------------
//(一)建立个INC/conn.php  文件放在INC目录 本程序就能用了
//(二)把你程序MYSQL的表+字段   表+字段  放在下面开始安装表中 就OK了  怎么换简单的很   只换表名  和字段内容 看下面的

         //只需要替换 表名 和字段内容 就可以了  其他的不用改........以下是告诉你什么是表 和字段
		 
         //表名  $table1=table1;
		 
		 //字段  
	    //id int(4) NOT NULL auto_increment Primary key,
		//newsname varchar(100) NOT NULL,
		//newsinfo text NOT NULL,
		//newsmenu int(4) NOT NULL,
		//addtime datetime NOT NULL,
		//updatetime datetime NOT NULL	 
?>







<?php
   if($_GET[install]){   
//-----------------------------------------------------------------------------
//获取提交的安装信息
//-----------------------------------------------------------------------------
$host=$_POST['host'];              //获取表单传来的  服务器：$host 
$mysqluser=$_POST['mysqluser'];    //获取表单传来的  用户名：$mysqluser
$mysqlpass=$_POST['mysqlpass'];    //获取表单传来的  密　码：$mysqlpass
$mydb=$_POST['mydb'];         //获取表单传来的  数据库：$mydb
$port=$_POST['port'];    //获取表单传来的  管理员密码：$adminpass
$sqlbiaotou = $_POST[sqlbiaotou];
//-----------------------------------------------------------------------------
//写入信息到文本中inc/conn.php
//-----------------------------------------------------------------------------
$b="<?php\n\n";
$b=$b."error_reporting(0);\n";
$b=$b."date_default_timezone_set('Asia/Shanghai');\n";
$b=$b."@header('Content-Type: text/html; charset=utf-8');\n";
$b=$b."\$Host=\"".$host."\";\n";

$b=$b."\$pwd=\"".$mysqlpass."\";\n";
$b=$b."\$user=\"".$mysqluser."\";\n";
$b=$b."\$port=\"".$port."\";\n";
$b=$b."\$dbname=\"".$mydb."\";\n";
$b=$b."\$BIAOTOU=\"".$sqlbiaotou."\";\n";
$b=$b."include('mysql_class.php');\n";
$b=$b."\$mysql = new MySQL(\$host,\$user,\$pwd,\$dbname,\$port);\n\n";

$a=fopen("../inc/conn.php","w"); 
//-----------------------------------------------------------------------------

if(fwrite($a,$b)){
echo '<div align="center">';
echo "（一）conn.php文件写入成功！<FONT color='RED'>OK</FONT>  <br>\n";
}else{
echo "（一）文件写入失败！请检查权限设置是否正确！<FONT color='RED'>X</FONT><br>";}

if($con=mysql_connect($host,$mysqluser,$mysqlpass)){
echo "（二）检查数据连接成功！<FONT color='RED'>OK</FONT>   正在创建数据库$mydb...<br>\n";
}else{
echo "（二）数据库连接失败！请检察填写是否正确<FONT color='RED'>X</FONT><br>";}

			
@mysql_query("SET NAMES 'gb2312'",$con);
if(@mysql_query("CREATE DATABASE `$mydb`;",$con)){
echo "（三）创建数据库<b><FONT color='RED'>$mydb</FONT></b>成功!<FONT color='RED'>OK</FONT><br> \n";}	
else{
echo "（三）创建数据库<b><FONT color='RED'>$mydb</FONT></b>失败,可能数据库已经存在了<FONT color='RED'>X</FONT><br>";}


//--------------------------------------------------------------------------------------------
//开始安装表单一----只改表名$table2=table2的植    和中间字段内容换为你似的字段内容
//--------------------------------------------------------------------------------------------
$table1=$sqlbiaotou.'content';  //表单一名定义
@mysql_select_db($mydb,$con);
if(@mysql_query("CREATE TABLE `$table1` (

  `id` int(11) NOT NULL auto_increment,
  `title` varchar(99) NOT NULL COMMENT '标题',
  `tags` varchar(99) default NULL COMMENT '标签',
  `content` mediumtext COMMENT '内容',
  `fromurl` varchar(999) default NULL COMMENT '来源',
  `pic` varchar(999) default NULL COMMENT '图片',
  `author` varchar(50) default NULL COMMENT '作者',
  `author_id` varchar(50) default NULL,
  `type` varchar(50) default NULL COMMENT '分类',
  `hot` varchar(10) default NULL COMMENT '热门',
  `rec` varchar(1) default NULL COMMENT '推荐',
  `time` varchar(20) default NULL COMMENT '时间',
  PRIMARY KEY  (`id`)
		
		
		) CHARACTER SET utf8",$con))
{

echo "（四）>创建表<b><FONT color='RED'>$table1</FONT></b>...成功!<FONT color='RED'>OK</FONT>\n";}	
else{
echo "（四）>创建表<b><FONT color='RED'>$table1</FONT></b>...失败,可能表已经存在<FONT color='RED'>X</FONT>\n";
}
	
	
	//表单一安装完-----------------------------------------------------------------------------------------------------------------
	
	
	
	
echo "<br>";

	
	
		
	
//--------------------------------------------------------------------------------------------
//开始安装表单二----只改表名$table2=table2的植    和中间字段内容换为你似的字段内容
//--------------------------------------------------------------------------------------------
$table2=$sqlbiaotou.'caiji';  //表单二名定义
@mysql_select_db($mydb,$con);
if(@mysql_query("CREATE TABLE `$table2` (

  `id` int(11) NOT NULL auto_increment,
  `time` varchar(50) default NULL,
  `no` varchar(50) default NULL,
  `from` varchar(10) default NULL,
  PRIMARY KEY  (`id`)
		

		
		) CHARACTER SET utf8",$con))
{

echo "（五）>创建表<b><FONT color='RED'>$table2</FONT></b>...成功!<FONT color='RED'>OK</FONT><br>";}		
else{
echo "（五）>创建表<b><FONT color='RED'>$table2</FONT></b>...失败,可能表已经存在<FONT color='RED'>X</FONT>新建立一个数据库,表就不会重复<br>";
}

	
//表单二安装完-----------------------------------------------------------------------------------------------------------------	
//--------------------------------------------------------------------------------------------
//开始安装表单三----只改表名$table3=table3的植    和中间字段内容换为你似的字段内容
//--------------------------------------------------------------------------------------------
$table3=$sqlbiaotou.'admin';  //表单三名定义
@mysql_select_db($mydb,$con);
if(@mysql_query("CREATE TABLE `$table3` (

  `id` int(10) NOT NULL auto_increment,
  `adminname` varchar(64) NOT NULL,
  `password` varchar(64) NOT NULL,
  `time` varchar(11) default NULL,
  PRIMARY KEY  (`id`)
		

		
		) CHARACTER SET utf8",$con))
{

echo "（六）>创建表<b><FONT color='RED'>$table3</FONT></b>...成功!<FONT color='RED'>OK</FONT><br>";}		
else{
echo "（六）>创建表<b><FONT color='RED'>$table3</FONT></b>...失败,可能表已经存在<FONT color='RED'>X</FONT>新建立一个数据库,表就不会重复<br>";
}

	
//表单三安装完-----------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
//开始安装表单四----只改表名$table4=table4的植    和中间字段内容换为你似的字段内容
//--------------------------------------------------------------------------------------------
$table4=$sqlbiaotou.'type';  //表单三名定义
@mysql_select_db($mydb,$con);
if(@mysql_query("CREATE TABLE `$table4` (

  `id` int(11) NOT NULL auto_increment,
  `type` varchar(20) default NULL,
  PRIMARY KEY  (`id`)
		

		
		) CHARACTER SET utf8",$con))
{

echo "（七）>创建表<b><FONT color='RED'>$table4</FONT></b>...成功!<FONT color='RED'>OK</FONT><br>\n现在请【删除install/目录】进入<br>\n<a href=\"../admin/\">进入后台</a>&nbsp; &nbsp;&nbsp;<a href=\"../index.php\">进入首页</a><br>";}	
else{
echo "（七）>创建表<b><FONT color='RED'>$table4</FONT></b>...失败,可能表已经存在<FONT color='RED'>X</FONT>新建立一个数据库,表就不会重复<br>";
}

	
//表单四安装完-----------------------------------------------------------------------------------------------------------------
//下面表单  有个提交管理帐号和密码先不管(暂时不用)   到时候数据库安装的时候  可以根据需要把数据库安装表改成修改的
echo '</div>';
include('../inc/mysql_class.php');
$mysql = new MySQL($host,$mysqluser,$mysqlpass,$mydb,$port);
$admin='<?'."\r\n".'$adminname='.'"'.$_POST['adminname'].'"'.";\r\n".'$password='.'"'.md5($_POST['password']).'"'.";\r\n?>";
	if(preg_match("/{|}|fputs|fopen/i", $admin)){   
    echo"<script>alert('含有非法字符！');location.href='?id=edit';</script>";
}   
else{
	$adminname=$_POST['adminname'];$password=md5($_POST['password']);
	$mysql->query("INSERT INTO `".$sqlbiaotou."admin` (`id`, `adminname`, `password`) VALUES(NULL, '$adminname', '$password')");
	}
}
/*--------------------------------后台登录用户名----------------------*/	

$mysql->query("INSERT INTO `".$sqlbiaotou."type` (`id`, `type`) VALUES(NULL, '汽车'), (NULL, '娱乐'), (NULL, '财经')");
$mysql->query("INSERT INTO `".$sqlbiaotou."caiji` (`id`, `time`, `no`, `from`) VALUES(1, '0', '0', '')");

$id=mysql_insert_id();
$backup = "../inc/install.lock";

	$fp = fopen($backup,'w');
	fwrite($fp,'安装成功');
	fclose($fp);
?> 
</div>
<div class="foot">
</div>


</body>
</html>