<!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>phpweb安装过程</title>
</head>
<style type="text/css">
.normal{ font-size:12px}
</style>
<body>
<?
error_reporting(0);
include("../include/common.php");
$step=$_GET["step"];
if($step=="" || $step==1)
{
print<<<EOT
<form id="form1" name="form1" method="post" action="index.php?step=test">
  <table width="100%" border="1" cellspacing="1" cellpadding="0">
    <tr>
      <td height="57" colspan="2" align="center"><h3>PHPWEB管理系统安装向导第一步:基本信息的获取</h3></td>
    </tr>
    <tr>
      <td width="29%" height="30" align="center" class="normal">主机地址:</td>
      <td width="71%"><label>
        <input type="text" name="dbhost" id="dbhost" />
      </label></td>
    </tr>
    <tr>
      <td height="30" align="center" class="normal">数据库名称:</td>
      <td><label>
        <input type="text" name="dbname" id="dbname" />
      </label></td>
    </tr>
    <tr>
      <td height="30" align="center" class="normal">数据库用户名:</td>
      <td><label>
        <input type="text" name="dbuser" id="dbuser" />
      </label></td>
    </tr>
    <tr>
      <td height="30" align="center" class="normal">数据库登录密码:</td>
      <td><label>
        <input type="text" name="dbpassword" id="dbpassword" />
      </label></td>
    </tr>
    <tr>
      <td height="30" colspan="2" align="center" class="normal"><label>
        <input type="submit" name="button" id="button" value="点击进入下一步" />
      </label></td>
    </tr>
  </table>
</form>
EOT;
}

if($step=="test")
{
	$dbhost=$_POST["dbhost"];
	
	$dbname=$_POST["dbname"];
	
	$dbuser=$_POST["dbuser"];
	
	$dbpassword=$_POST["dbpassword"];
	
	if($dbhost=="")
	{
		die("填写好主机地址");
	}
	elseif($dbname=="")
	{
		die("填写好数据库名称");
	}
	elseif($dbuser=="")
	{
		die("填写好数据库用户名");
	}
	elseif($dbpassword=="")
	{
		die("填写好数据库登录密码");
	}
	
	if(!$conn=mysql_connect($dbhost,$dbuser,$dbpassword))
	{
		die("无法连接数据库");
	}
	if(!mysql_select_db($dbname,$conn))
	{
		die("数据库名错误,您必须创建好数据库");
	}
	else
	{
	$conn=1;
	
	$str="<?\n\$dbhost='".$dbhost."';\n\$dbname='".$dbname."';\n\$dbuser='".$dbuser."';\n\$dbpassword='".$dbpassword."';\n?>";
	
	$fp=fopen("../config.php","w");
	
	fwrite($fp,$str);
	
	fclose($fp);
	
	$state="写入配置文件完毕";

print<<<EOT
<form id="form1" name="form1" method="post" action="index.php?step=3">
  <table width="95%" border="1" cellspacing="1" cellpadding="0">
    <tr>
      <td height="43" colspan="2" align="center"><h3>PHP管理系统安装第二步:配置文件的创建</h3></td>
    </tr>
    <tr>
      <td width="35%" height="37">配置文件写入情况:</td>
      <td width="65%"><font color="red">{$state}</font></td>
    </tr>
    <tr>
      <td height="33" colspan="2" align="center"><label>
        <input type="submit" name="button" id="button" value="点击进入下一步"  />
      </label></td>
    </tr>
  </table>
</form>
EOT;
	}

}

if($step==3)
{
	$filename="../sql/install.txt";
	$str="";
	$str=file_get_contents($filename);
	$arr=explode(";",$str);
	foreach($arr as $value)
	{
		$mysql->query($value);
				
				//echo $value;
	}
			
	$state="数据库导入完毕,为了安全起见,请删除install文件夹,后台访问地址:http://域名/root,用户名:admin 密码:admin";
	
print<<<EOT
<form id="form1" name="form1" method="post" action="../">
  <table width="95%" border="1" cellspacing="1" cellpadding="0">
    <tr>
      <td height="43" colspan="2" align="center"><h3>PHP管理系统安装第三步:数据库安装</h3></td>
    </tr>
    <tr>

      <td width="35%" height="37">数据库导入情况:</td>
      <td width="65%"><font color="red">{$state}</font></td>
    </tr>
    <tr>
      <td height="33" colspan="2" align="center"><label>
        <input type="submit" name="button" id="button" value="完成安装,转入主页"/>
      </label></td>
    </tr>
  </table>
</form>
EOT;
unlink("lock.php");
}
?>
</body>
</html>