<?php
require_once( dirname(__FILE__) . '/common.php');
header('Content-Type: text/html; charset=UTF-8;'); 

if ($_POST['add']!="") {
	
	if (!is_writable(dirname(__FILE__) . '/config/')) {
		die( 'config/  - 目录必须设置为可写！');
	}


$db = $_POST['db'];
$m = mysql_connect($db['host'], $db['user'], $db['pass']);

if (!is_writable(dirname(__FILE__) . '/db/') ) {
	die('db/ - 目录必须设置为可写！');
}

if (!$m ) {
	echo "<script language='javascript'>alert('错误的数据库配置');window.parent.location.replace('install.php');</script>";

}

if ( !mysql_select_db($db['name'], $m) 
		&& !mysql_query("CREATE database `{$db['name']}`;", $m) ) {
	Session::Set('error', "选择数据库 {$db['name']} 错误，可能不存在？");
	echo "<script language='javascript'>alert('选择数据库错误，可能不存在？');window.parent.location.replace('install.php');</script>";

}
mysql_select_db($db['name'], $m);

$dir = dirname(__FILE__);
$sql = '';
$f = file('db/auction_db.sql');
foreach($f AS $l) {
	if ( strpos(trim($l), '--')===0 || strpos(trim($l), '/*') === 0 || !trim($l)) {
		continue;
	}
	$sql .= $l;
}

mysql_query("SET names UTF8;");
$sqls = explode(';', $sql);

foreach($sqls AS $sql) {
	mysql_query($sql, $m);
}

$PHP = array(
	'db' => $db,
);


if ( write_php_file($PHP, 'config/config.inc.php') ) {
	echo "<script language='javascript'>alert('拍客软件安装成功，请及时删除 install.php');window.parent.location.replace('index.php');</script>";
}
//redirect('index.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>
<title>拍客（piikee.com）秒杀竞拍系统安装</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DedeCMS V5.3" />
<meta name="author" content="desdev.cn" />
<link href="css/dedecms.css" rel="stylesheet" media="screen" type="text/css" />
<link href="css/table.css" rel="stylesheet" media="screen" type="text/css" />
<link href="css/page.css" rel="stylesheet" media="screen" type="text/css" />
</head>
<body class="buycarpage" >

<div class="header">
	<div class="top w960 center">
		<div id="logo"><img src="style/images/logo.gif" /></div>
	</div><!-- /top -->
</div><!-- /header -->

<div class="w960 clear center mt1 cmt-box">
	<div class="sp-title"><h2>程序安装</h2></div>
	<div class="buycar">
		<form id="login-user-form" method="post" action="install.php">
					<input type="hidden" name="id" value="100027" />
     
        <table cellpadding="0" cellspacing="0" class="flow">
			<tr>
				<td class="thisclass">欢迎您选用拍客（piikee.com）秒杀竞拍系统</td>
				
			</tr>
		</table>
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="dede_table">
		
			<tbody>
				<tr>
				<div class="wholetip clear"><h3>1、数据库信息</h3></div>
                        <div class="field">
                            <label>主机名</label>
                            <input type="text" size="30" name="db[host]" id="partner-create-username" class="f-input" value="localhost:3306" />
                        </div>
                        <div class="field">
                            <label>用户名</label>
                            <input type="text" size="30" name="db[user]" id="settings-password" class="f-input" value="root" />
                        </div>
                        <div class="field password">
                            <label>密码</label>
                            <input type="text" size="30" name="db[pass]" id="settings-password" class="f-input" value=" " />
                        </div>
                        <div class="field password">
                            <label>数据库名</label>
                            <input type="text" size="30" name="db[name]" id="settings-password-confirm" class="f-input" value="auction_db" />
                        </div>
						<div class="field password">
                            <label>网站名</label>
                            <input type="text" size="30" name="db[sitename]" id="settings-password-confirm" class="f-input" value="拍客秒杀竞拍系统" />
                        </div>
						<div class="field password">
                            <label>网站地址</label>
                            <input type="text" size="30" name="db[siteurl]" id="settings-password-confirm" class="f-input" value="http://demo.piikee.com/" />
                        </div>
						<div class="field password">
                            <label>网站描述</label>
                            <input type="text" size="30" name="db[pagetitle]" id="settings-password-confirm" class="f-input" value=" 拍客（piikee.com）秒杀竞拍系统" />
                        </div>
				</tr>
			</tbody>
		</table>
        
        
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="dede_table">
			
			<tbody>
				
<tr>
				<div class="wholetip clear"><h3>2、目录设置</h3></div>
						<div style="margin:20px; line-height:20px;">
							<h4>确保下列目录或文件可写</h4>
							<ul>
							<li>目录：db/ ---------------- <b><? if(!is_writable(dirname(__FILE__) . '/db/')) echo  "<font color=\"red\">不可写</font>";
							else echo "<font color=\"green\">可写</font>";?></b></li>
							<li>目录：config/ ---------------- <b><? if(!is_writable(dirname(__FILE__) . '/config/')) echo  "<font color=\"red\">不可写</font>";
							else echo "<font color=\"green\">可写</font>";?></b></li>
							
							</ul>
						</div></tr>
				
			</tbody>
			<tfoot>
				<tr>
					<td colspan="2">
					<button type="submit" class="btn-2" name='add'>安装</button>
					</td>
				</tr>
			</tfoot>
		</table>		
		</form>
	</div>
	
</div>


</body>
</html>


