<?php
	if(empty($_POST['DB_HOST']) || empty($_POST['DB_NAME']) || empty($_POST['DB_USER']) || empty($_POST['DB_PWD']) || empty($_POST['DB_USER']) || empty($_POST['DB_PREFIX']) || empty($_POST['buildTime'])){
		header("Content-type: text/html; charset=utf-8"); 
		exit('所有都必填! <a href="'.$_SERVER['HTTP_REFERER'].'">请点此返回填写!</a>');
	}	
	if(file_exists('../config/db.inc.php')){ 
		header('Location:exist.php');
	}
	
	$conn=@mysql_connect($_POST['DB_HOST'],$_POST['DB_USER'],$_POST['DB_PWD']);
	if(mysql_errno()){
		header('Location:database.php');
	}
	
	$other = "<?php\r\nif (!defined('THINK_PATH')) exit();\r\n return array(\r\n";
	foreach($_POST as $key=>$value){
		$other .= "\t'".$key."'=>'".$value."',\r\n";
	}
	$other .= ");\r\n?>";
	if(!file_put_contents('../config/db.inc.php',$other))  header('Location:error.php');
	if(!mysql_select_db($_POST['DB_NAME'])){
		mysql_query("CREATE DATABASE `".$_POST['DB_NAME']."`");
	}	
	if(mysql_errno()){
		header('Location:database.php');
	}
?>
<!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>YiCms 安装向导</title>
		<link rel="stylesheet" href="images/style.css" type="text/css" media="all" />
	</head>
	<body>
		<div class="container">
			<div class="header">
				<h1>YiCms 安装向导</h1>
				<span>简体中文 UTF8 版</span>
					<div class="setup step3">
						<h2>安装数据库</h2>
						<p>正在执行数据库安装</p>
					</div>
					<div class="stepstat">
						<ul>
							<li>检查安装环境</li>
							<li>创建数据库</li>
							<li class="current">创建管理员</li>
							<li class="unactivated last">安装</li>
						</ul>
						<div class="stepstatbg stepstat1"></div>
					</div>
			</div>
			<div class="main">
				<form method="post" action="step4.php">
					<div><br />
						<div class="desc"><b>填写管理员信息</b></div>
						<table class="tb2">
							<tr>
								<th class="tbopt" align="left">&nbsp;管理员账号:</th>
								<td><input type="text" name="username" value="admin" size="35" class="txt"></td>
								<td></td>
							</tr>
							<tr>
								<th class="tbopt" align="left">&nbsp;管理员密码:</th>
								<td><input type="password" name="password" size="35" class="txt"></td>
								<td>管理员密码不能为空</td>
							</tr>
							<tr>
								<th class="tbopt" align="left">&nbsp;重复密码:</th>
								<td><input type="password" name="repassword" size="35" class="txt"></td>
								<td>重复一次密码!</td>
							</tr>
							<tr>
								<th class="tbopt" align="left">&nbsp;管理员邮箱:</th>
								<td><input type="text" name="email" size="35" class="txt" value="admin@yicms.cn"></td>
								<td>输入管理员的邮箱!</td>
							</tr>
						</table>
					</div>
					<table class="tb2">
						<tr>
							<th class="tbopt" align="left">&nbsp;</th>
							<td><input type="button" onclick="history.back();" value="上一步"/>&nbsp;<input type="submit" value="下一步" class="btn"></td>
							<td></td>
						</tr>
					</table>
				</form>
				<div class="footer">&copy;2012 - 2013 <a href="http://www.yicms.cn/">YiCms</a> Inc.</div>
				<div class="footer">您有任何疑问，可以登录<a href="http://bbs.yicms.cn" target="_blank"><b>YiCms官方论坛</b></a>或加<b>交流QQ群：174069335</b></div>
			</div>
		</div>
	</body>
</html>			