<?php
error_reporting(0);
	@header('Content-Type: text/html; charset=UTF-8');
	if(file_exists('install.lock')){
		exit('已经安装完成！如需重新安装，请删除install目录下的install.lock!');
	}
	$step=is_numeric($_GET['step'])?$_GET['step']:'1';
?>
<!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"/>
<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no,minimal-ui">
<meta name="MobileOptimized" content="320">
<meta http-equiv="cleartype" content="on">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<title>快速安装-快乐离线秒赞网-最快最稳定的秒评系统</title>
<meta name="Keywords" content="快乐离线秒赞网,秒赞网,24h秒赞,离线秒赞"/>
<meta name="Description" content="Q快乐离线秒赞网，最快最稳定的秒赞系统。24小时不间断离线秒赞QQ空间说说！"/>
<link href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="/css/style.css" rel="stylesheet" type="text/css"/>

</head>
<body>
<div class="container">	
	
		<div class="header">
		<div class="logo">
			<span>快乐离线秒赞</span>
		</div>
		<div>
			<ul class="nav nav-pills pull-right" role="tablist">
				<li role="presentation" ><a >快速安装导航</a></li>
			</ul>
		</div>
	</div>
<?php if($step=='1'){?>
<div class="panel panel-primary">
	<div class="panel-heading" style="background: #15A638;">
		<h3 class="panel-title" align="center">安装协议</h3>
	</div>
	<div style="padding: 10px;">
		<ul class='list-group'>
			<li class='list-group-item active'>欢迎使用快乐离线秒赞程序</li>
			<li class='list-group-item'>1、解密所有加密的源码。</li>
			<li class='list-group-item'>2、去除授权机制。</li>
			<li class='list-group-item'>3、去除后门代码。</li>
			<li class='list-group-item'>4、本源码版权属于快乐是福，作者QQ815856515！</li>
			<li class='list-group-item'><a href="?step=<?php if(defined("SAE_ACCESSKEY"))echo '3';else echo '2';?>" class="btn btn-block btn-warning">同意以上协议，进行下一步</a></li>
		</ul>
	</div>
</div>
<?php }elseif($step=='2'){?>

<div class="panel panel-primary">
	<div class="panel-heading" style="background: #15A638;">
		<h3 class="panel-title" align="center">数据库配置</h3>
	</div>
	<div style="padding: 10px;
text-align: center;">
		<form action="?step=3" class="form-sign" method="post">
		<label for="name">数据库地址:</label>
		<input type="text" class="form-control" name="DB_HOST" value="localhost">
		<label for="name">数据库端口:</label>
		<input type="text" class="form-control" name="DB_PORT" value="3306">
		<label for="name">数据库库名:</label>
		<input type="text" class="form-control" name="DB_NAME" placeholder="输入数据库库名">
		<label for="name">数据库用户名:</label>
		<input type="text" class="form-control" name="DB_USER" placeholder="输入数据库用户名">
		<label for="name">数据库密码:</label>
		<input type="password" class="form-control" name="DB_PWD" placeholder="输入数据库密码">
		<br><input type="submit" class="btn btn-primary btn-block" name="submit" value="确认，下一步">
		</form>
	</div>
</div>
<?php }elseif($step=='3'){
			if(defined("SAE_ACCESSKEY"))
			$_POST=require("../Application/Common/Conf/saedb.php");
		if(!$_POST['DB_HOST'] || !$_POST['DB_PORT'] || !$_POST['DB_NAME'] || !$_POST['DB_USER'] || !$_POST['DB_PWD']){
			echo'<script language=\'javascript\'>alert(\'所有项都不能为空\');history.go(-1);</script>';
		}else{
			if(!$con=mysql_connect($_POST['DB_HOST'].':'.$_POST['DB_PORT'],$_POST['DB_USER'],$_POST['DB_PWD'])){
				echo'<script language=\'javascript\'>alert("连接数据库失败，'.mysql_error().'");history.go(-1);</script>';
			}elseif(!mysql_select_db($_POST['DB_NAME'],$con)){
				echo'<script language=\'javascript\'>alert("选择的数据库不存在，'.mysql_error().'");history.go(-1);</script>';
			}else{
				mysql_query("set names utf8",$con);
				$data="<?php
return array(
	'DB_HOST'               =>  '{$_POST['DB_HOST']}',
    'DB_NAME'               =>  '{$_POST['DB_NAME']}',
    'DB_USER'               =>  '{$_POST['DB_USER']}',
    'DB_PWD'                =>  '{$_POST['DB_PWD']}',
    'DB_PORT'               =>  '{$_POST['DB_PORT']}',
    'DB_PREFIX'             =>  'klmz_',
);";
				@file_put_contents('../Application/Common/Conf/db.php',$data);
					$sqls=file_get_contents("install.sql");
					$explode = explode(";",$sqls);
					$num = count($explode);
					foreach($explode as $sql){
						if($sql=trim($sql)){
							mysql_query($sql);
						}
					}
					if(mysql_error()){
						echo'<script language=\'javascript\'>alert("导入数据表时错误，'.mysql_error().'");history.go(-1);</script>';
					}else{
						@file_put_contents('install.lock','');
				?>
<div class="panel panel-primary">
	<div class="panel-heading" style="background: #15A638;">
		<h3 class="panel-title" align="center">网站安装成功</h3>
	</div>
	<div style="padding: 10px;">
		<ul class='list-group'>
			<li class='list-group-item active'>共导入<?php echo $num;?>条数据，网站安装成功</li>
			<li class='list-group-item'>1、网站已经安装完成！</li>
			<li class='list-group-item'>2、网站后台地址:域名/admin.php</li>
			<li class='list-group-item'>3、后台默认密码123456，请尽快修改。</li>
			<li class='list-group-item'>4、如果是SAE请务必在/install/ 目录下自行建立 install.lock 文件，以免重复安装。</li>
			<li class='list-group-item'><a href="/index.php" class="btn btn-warning">网站首页</a>&nbsp;<a href="/index.php/Home/Admin" class="btn btn-warning">网站后台</a></li>
		</ul>
	</div>
</div>
				<?php
					}
			}
		}
}elseif($step=='4'){


?>


<?php }?>
<div align="center">快速安装©<a href="/">快乐离线秒赞</a></div>
</div>
</body>
</html>