<?php
	if(file_exists('../config/install.lock')){
		header('Location:exist.php');
	}
	$username = trim($_POST['username']);
	$password = trim($_POST['password']);
	$repassword = trim($_POST['repassword']);
	$email = trim($_POST['email']);
	if(empty($username) || empty($password))  exit('输入为空?你想进不了网站后台吗????<a href="'.$_SERVER['HTTP_REFERER'].'">请点此返回填写!</a>');
	if( $password != $repassword)  exit('两次密码不一致!!<a href="/Install">请点此返回填写!</a>');
	define(THINK_PATH,'THINK_PATH');
	$config = include '../config/db.inc.php';
	$conn=mysql_connect($config['DB_HOST'],$config['DB_USER'],$config['DB_PWD']);
	if(mysql_errno()){
		header('Location:database.php');
	}
	if(!mysql_select_db($config['DB_NAME'])){
		if(mysql_errno()){
			header('Location:database.php');
		}
	}
	mysql_set_charset('UTF8');
	$file=file_get_contents('yicms.sql');
	$file=str_replace('yi_',$config['DB_PREFIX'],$file);
	$arr=explode('&^;$&',$file);
	$table = array('yi_about',
					'yi_ad',
					'yi_admin',
					'yi_buy',
					'yi_config',
					'yi_flash',
					'yi_flink',
					'yi_nav',
					'yi_news',
					'yi_page',
					'yi_product',
					'yi_product_field',
					'yi_product_spec',
					'yi_reply',
					'yi_serve',
					'yi_user',
					'yi_user_account',
					'yi_user_detail',
					'yi_user_msg',
					'yi_vote_ip',
					'yi_vote_option',
					'yi_vote_subject',
				);
	$flag = true;			
?>
<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">
		<script type="text/javascript">
			function showmessage(message) {
				document.getElementById('notice').innerHTML+= message;
			}
			function jump(){
				 var t=setTimeout("window.location='success.php'",1000);
			}
		</script>
		<meta content="Comsenz Inc." name="Copyright">
	</head>
	<body>
		<div class="container">
			<div class="header">
				<h1>YiCms 安装向导</h1>
				<span>简体中文 UTF8 版</span>
				<div class="setup step4">
					<h2>安装数据库</h2>
					<p>正在执行数据库安装</p>
				</div>
				<div class="stepstat">
					<ul>
						<li>检查安装环境</li>
						<li>创建数据库</li>
						<li>创建管理员</li>
						<li class="current last">安装</li>
					</ul>
					<div class="stepstatbg stepstat1"></div>
				</div>
			</div>
			<div class="main">
				<div id="notice"></div>
				<div class="btnbox margintop marginbot">
					<input type="button" name="submit" value="正在安装..." disabled="disabled" id="laststep" onclick="initinput()">
				</div>
				<?php 	
					foreach($arr as $key=>$value){
						if($flag===false) exit;
						$result=mysql_query($value);
						if($result){
							$flag = true;
					?>
					<script type="text/javascript">
						showmessage("建立数据表&nbsp;<?php  echo $table[$key] ?>&nbsp;...&nbsp;成功<br/>");
					</script>
					<?php }else{
							$flag = false;
					?>
						<script type="text/javascript">
							showmessage("建立数据表&nbsp;<?php  echo $table[$key] ?>&nbsp;...&nbsp;失败<br/>原因:<?php echo (htmlspecialchars(mysql_error())); ?><br/>请检查数据库并.<a href='index.php'>返回重新安装</a>");
						</script>
					<?php
						}
					}
					$password = md5($password);
					$result = mysql_query("INSERT INTO `".$config['DB_PREFIX']."admin` (`username`,`password`,`email`,`lastip`,`lasttime`,`level`,`state`,`admin`) VALUES ('$username','$password','$email','".ip2long($_SERVER['REMOTE_ADDR'])."','".time()."','1_0,1_1_1,1_1_2,1_2_1,1_2_2,1_9_1,1_3_1,1_3_2,1_4_1,1_4_2,1_5_1,1_5_2,1_6_1,1_6_2,1_8_1,1_8_2,3_0,3_1_1,3_1_2,3_2_1,3_2_2,3_3_1,3_3_2,4_0,4_1_1,4_1_2,4_1_3,4_1_4,5_0,5_1_1,5_1_2,5_2_1,5_2_2,5_2_3,6_0,6_1_1,6_1_2,6_1_3,6_1_5,6_2_1,6_2_2,6_2_3,7_0,7_1_1,7_1_2,7_2_1,7_2_2,7_3_1,8_0,8_1_1,8_1_2','1','1')");
					echo '<script>jump()</script>';
				?>
			</div>
		</div>
	</body>
</html>