<?php
	error_reporting(0);
	define('SITE_PATH',str_replace('\\', '/', substr(dirname(__FILE__), 0, -7)));
	require '../Source/class/install.class.php';
	$AnYue_Install = new AnYue_Install();

	$itemarray = array ('mysql_connect','file_get_contents','curl_init','fsockopen');
	$entryarray = array ('index.php');

	if (!empty($_GET['agree'])){
		$nt=$_GET['agree']=='on' ? $AnYue_Install->Print_Code (7) : '';
		if ($nt!=Null){die($nt);}
	}
?>
<!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>暗月挂Q系统 安装向导</title>
<link rel="stylesheet" href="images/style.css" type="text/css" media="all" />
<script type="text/javascript">
    function $(id){
        return document.getElementById(id);
    }

    function showmessage(message){
        document.getElementById('notice').innerHTML += message + '<br />';
    }

	function nex_1(){
		var ids = "dbhost,dbname,dbuser,dbpw,tablepre,weburl,template,username,password,password2,email";
		array = ids.split(",");
		err = "No";
		for (var i=0; i<11; i++){
			Cget = document.getElementById(array[i]);
			if (Cget.value == ""){
				err = "Yes";
			}
		}

		Cget = document.getElementById("nex1");
		if (err != "Yes"){
			Cget.disabled = "";
		}else{
			Cget.disabled = "disabled";
		}
	}
</script>
<meta content="Comsenz Inc." name="Copyright" />
</head>
<body>
<div class="container">
		<div class="header">
		<h1>暗月挂Q系统 安装向导</h1>
		<span>暗月挂Q系统 V1.3.5 简体中文 UTF8 正式版</span>
<?

@$step = $_GET['step'];

//判断标记文件是否存在，存在就退出，防止重复运行
if (file_exists(SITE_PATH.'Install/install.lock') and $step != 5){
	die ('</div><div class="main" style="margin-top: -123px;">暗月挂Q系统提示您：重新安装失败<hr>解决方案：手动删除 <b><font color="red">Install</font></b> 文件夹下的 <b><font color="red">install.lock</font></b> 文件</div><br />');
}



if (!empty ($_GET['agree'])){

	@$step = $_GET['step'];
    $agree = $_GET['agree'];

}

if ($agree == "yes") {

	switch ($step){

		Case 1;
			if (PHP_VERSION < 5.1){
				define ('Install_Error','End');
				$PHP_VERSION = '<td class="nw pdleft1">'. PHP_VERSION .' (版本过低)</td>';
			}else{
				$PHP_VERSION = '<td class="w pdleft1">'. PHP_VERSION .'</td>';
			}
			$n = array (PHP_OS,$PHP_VERSION,$AnYue_Install->GetGdVersion(),$AnYue_Install->GetFreeDisk(SITE_PATH),$AnYue_Install->is_files($entryarray),$AnYue_Install->is_functions($itemarray),defined ('Install_Error') ? 'disabled="disabled"' : '');
			$AnYue_Install -> Print_Code (1);
			echo AnYue_Install_Case_1;
		break;

		Case 2;
			$n = 'AYGQ_'.substr(MD5(time()+rand(100000000,900000000)),3,9).'_';
			$AnYue_Install -> Print_Code (2);
			echo AnYue_Install_Case_2;
		break;

		Case 3;
			@$conn = mysql_connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpw']);
			@mysql_query("set names 'utf8'");
			@$select = mysql_select_db($_POST['dbname'],$conn);

			if ($conn and $select){

$websitekey = time().rand (10000,99999);
$websitejob = substr (MD5 (rand (10000,99999)),2,10);

@$webtxt = "<?php
#header('Content-Type: text/html; charset=utf-8');
#数据库地址
\$sqlhost = '{$_POST['dbhost']}';
#数据库用户
\$sqluser = '{$_POST['dbuser']}';
#数据库密码
\$sqlpass = '{$_POST['dbpw']}';
#数据库名字
\$sqldata = '{$_POST['dbname']}';
#数据库前缀
\$sqlprefix = '{$_POST['tablepre']}';
#网站标识符
\$websitekey = '{$websitekey}';
#网站工作码
\$websitejob = '{$websitejob}';

#网站名称
\$sitename = '暗月挂Q';
#网站副标题
\$sitekouhao = '高端大气上档次，低调奢华有内涵';
#SEO关键词
\$SEOC = '挂Q,暗月挂Q,暗月挂Q系统,24小时挂Q,全天挂Q,免费挂Q,挂Q平台,晴天挂Q,云在线,挂Q软件,批量挂Q,无限挂Q,永久挂Q,全天在线,挂Q源码,挂Q网站,双协议挂Q,手机协议挂Q,离线挂Q,自动打码挂Q';
#SEO描述
\$SEOM = '暗月挂Q平台，高端大气上档次，低调奢华有内涵，为广大Q友搭建了一个24小时全天在线免费挂Q平台，随时随地云在线，无忧无虑过太阳冲皇冠！暗月挂Q欢迎您的加入！';

#模板名称
\$Template_Root = 'default';
#网站地址
\$WebSite_Url = '{$_POST['weburl']}';";


				@$webwrite = file_put_contents ('../siteinfo.php',$webtxt);

				if ($webwrite!=Null){
					$n[0] .= '<div class="w pdleft1"><div class="desc "><b class="">数据库配置文件成功</b></div></div>';
				}else{
					$error_array['write_config'] = false;
					$n[0] .= '<div class="nw pdleft1"><div class="desc"><b>保存配置失败！请开启目录0777权限。无法进一步安装安装</b></div></div>';
				}

			}else{
				$error_array['connect_db'] = false;
				$n[0] .= '<div class="nw pdleft1"><div class="desc"><b>链接数据库失败！无法进一步安装</b></div></div>';
			}

			if (strlen($_POST['username']) < 3 || strlen($_POST['username']) > 15){
				$error_array['username_length'] = false;
				$n[0] .= '<div class="nw pdleft1"><div class="desc "><b class="">用户名需3-15位</b></div></div>';
			}

			if (!preg_match('/^[0-9a-zA-Z\_]*$/', $_POST['username'])) {
				$error_array['username_layout'] = false;
				$n[0] .= '<div class="nw pdleft1"><div class="desc "><b class="">用户名不能为中文</b></div></div>';
			}

			if (!preg_match('/^[0-9a-zA-Z\_]*$/', $_POST['password'])) {
				$error_array['password_layout'] = false;
				$n[0] .= '<div class="nw pdleft1"><div class="desc "><b class="">密码必须为数字或者英文字符</b></div></div>';
			}

			if (strlen($_POST['password']) < 1 || strlen($_POST['password']) > 15) {
				$error_array['password_length'] = false;
				$n[0] .= '<div class="nw pdleft1"><div class="desc "><b class="">密码长度必须在1到15位之间</b></div></div>';
			}

			if ($_POST['password'] != $_POST['password2']) {
				$error_array['password_same'] = false;
				$n[0] .= '<div class="nw pdleft1"><div class="desc "><b class="">密码不一致</b></div></div>';
			}

			if (strlen($_POST['username']) > 2 and strlen($_POST['username']) < 16 and preg_match('/^[0-9a-zA-Z\_]*$/', $_POST['username']) and preg_match('/^[0-9a-zA-Z\_]*$/', $_POST['password']) and strlen($_POST['password']) > 0 and strlen($_POST['password']) < 16 and ($_POST['password'] = $_POST['password2'])){

@$admintxt = "<?php
\$username = '{$_POST['username']}';
\$password = '{$_POST['password']}';
\$adminmail = '{$_POST['email']}';";

				/* 保存后台配置信息 */
				$fp = fopen('../Admin/user.php','w');
				flock($fp,LOCK_EX);
				$adminwrite = fputs($fp,$admintxt);
				flock($fp,LOCK_UN);
				fclose($fp);

				if ($adminwrite){
					$n[0] .= '<div class="w pdleft1"><div class="desc "><b class="">管理员信息设置成功</b></div></div>';
				}else{
					$error_array['write_AdminConfig'] = false;
					$n[0] .= '<div class="nw pdleft1"><div class="desc "><b class="">管理员信息设置失败</b></div></div>';
				}
			}

			$n[1] = isset($error_array) ? 'disabled="disabled"' : '';
			$AnYue_Install -> Print_Code (3);
			echo AnYue_Install_Case_3;
		break;

		Case 4;
			include_once '../siteinfo.php';
			function do_sql(){

				global $sqlhost,$sqluser,$sqlpass,$sqldata;
				if (!mysql_select_db ($sqldata,mysql_connect($sqlhost,$sqluser,$sqlpass))){
					return '无法连接数据库！';
				}
				$sql_txt = file_get_contents('aygq.html');
				$array = explode(';',$sql_txt);
				foreach ($array as $value){
					mysql_query($value);
				}
				unset ($sqlhost,$sqluser,$sqlpass,$sqldata);

				$file = fopen('../Install/install.lock','w');
				flock($file,LOCK_EX);
				fputs($file,'I\'m Xhao~! Thank you!');
				flock($file,LOCK_UN);
				fclose($file);

				return '
				<div id="notice">'.$sql_txt.'</div>
					<div class="btnbox margintop marginbot">
						<form action="index.php" method="get"><input type="hidden" name="step" value="5" /><input type="hidden" name="agree" value="yes" /><input type="submit" value="下一步"></form>
					</div>
				</div>';

			}

			$n = do_sql();
			$AnYue_Install -> Print_Code (4);
			echo AnYue_Install_Case_4;
		break;

		Case 5;
			$AnYue_Install -> Print_Code (5);
			echo AnYue_Install_Case_5;
		break;

	}

}


if (empty($_GET['step'])){

	$AnYue_Install -> Print_Code (6);
	echo AnYue_Install_Case_6;

}



?>



<div class="footer">&copy;2011-<?=date('Y')?> <a href="http://aygq.cc/" target="_blank">暗月挂Q系统</a> Inc.</div>

		</div>
</div>

</body>

</html>