<?php
/*******************************************************************************************
' Software name: DJCMS Content Management System
' Version:3.0
' Web: http://www.djcms.net
' Author: 心情(qq:1130731)
' Copyright (C) 2009-2010 DJCMS官方 版权所有
' 法律申明：DJCMS程序所有代码100%原创、未引入任何网上代码,对一切抄袭行为、坚决严肃追究法律责任
'*******************************************************************************************/
define('DJ_ROOT', str_replace("\\", '/', dirname(__FILE__)).'/');
define('SCHEME', $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://');
$siteUrl = SCHEME.dirname($_SERVER['HTTP_HOST'].$_SERVER["SCRIPT_NAME"]);

header("Content-Type: text/html; charset=gb2312");
$action = getForm("action", "get");
switch ($action){
	case "install":install();break;
	case "stepOne":stepOne();break;
	case "stepTwo":stepTwo();break;
	case "stepThr":stepThr();break;
	case "stepFour":stepFour();break;
	case "chkdata":chkDatabase();break;
	case "main":main();break;
	default:Compacta();break;
}
function Compacta(){
?>
<html><head>
<title>站点安装-许可协议</title>
<style>body{text-align:center}#installbox{background-color:white;border:1px solid #1B76B7;margin:0 auto;width:600px;text-align:left;margin-top:2em}.msgtitle{padding:3px 3px;color:white;font-weight:700;line-height:21px;height:25px;font-size:12px;border-bottom:1px solid #1B76B7; text-indent:3px; background-color:#1B76B7}#msgbody{font-size:12px;line-height:25px;}#msgbottom{text-align:center;height:20px;line-height:20px;font-size:12px;background-color:#1b76b7;color:#FFFFFF}label{cursor:pointer;height:15px;line-height:15px;width:80px;}label:hover{background-color:#f5f5f5}h3{font-size:18px;font-family:"黑体";font-weight:300;border-bottom:1px solid #C4E1FF;padding:2px 0 2px 30px;color:#333}input{border-width:0;}
textarea, input{padding:2px;border:1px solid;border-color:#666 #ccc #ccc #666;background:#F9F9F9;color:#333}
.btn{margin:3px 0;padding:2px 5px;*padding:4px 5px 1px;border-color:#ddd #666 #666 #ddd;background:#DDD;color:#000;cursor:pointer;vertical-align:middle}
</style>
<script>
function $(id){
	return document.getElementById(id)	
}

function chkCompact(){
	if(!$('Compact').checked){
		alert('你没有接受许可协议\n不能安装');
		return false;
	}
}
</script>
</head>
<body>
<form action="?action=main" method="post" onSubmit="return chkCompact();">
<div id='installbox'><div class='msgtitle'>DjCms3.0安装向导 >> 基本设置</div>
<table style="width:598px;text-align:center;font-size:10pt;"><tr><td align="center"><span style="display:block;float:left;background-color:#eeeeee;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>1.</b></font>基本设置</span><span style="display:block;float:left;background-color:#eeeeee;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>2.</b></font>数据库设置</span><span style="display:block;float:left;background-color:#eeeeee;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>3.</b></font>管理员设置</span><span style="display:block;float:left;background-color:#eeeeee;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>4.</b></font>运行模式设置</span></td></tr></table>
<div id='msgbody'>
<h3 style="clear:both;">DjCms使用许可协议</h3>
<div style="text-align:center;">
<textarea style="width:570px;border:4px solid #C8E9FF;font-size:12px;" rows="15">
一、协议许可的权利 

1、您可以在协议规定的约束和限制范围内修改 djcms 源代码或界面风格以适应您的网站要求。 

2、您拥有使用本软件构建的网站全部内容所有权，并独立承担与这些内容的相关法律义务。 


二、协议规定的约束和限制 

1、未经官方许可，不得对本软件或与之关联的商业授权进行出租、出售、抵押或发放子许可证。

2、未经官方许可，禁止在 djcms 的整体或任何部分基础上以发展任何派生版本、修改版本或第三方版本用于重新分发。

5、如果您未能遵守本协议的条款，您的授权将被终止，所被许可的权利将被收回，并承担相应法律责任。
 

三、有限担保和免责声明 

1、本软件及所附带的文件是作为不提供任何明确的或隐含的赔偿或担保的形式提供的。 

2、用户出于自愿而使用本软件，您必须了解使用本软件的风险，我们不承诺对免费用户提供任何形式的技术支持、使用担保，也不承担任何因使用本软件而产生问题的相关责任。 

3、电子文本形式的授权协议如同双方书面签署的协议一样，具有完全的和等同的法律效力。您一旦开始确认本协议并安装 djcms，即被视为完全理解并接受本协议的各项条款，在享有上述条款授予的权力的同时，受到相关的约束和限制。协议许可范围以外的行为，将直接违反本授权协议并构成侵权，我们有权随时终止授权，责令停止损害，并保留追究相关责任的权力。



    </textarea></div>
<br />
<div style="text-align:center;"><input type="checkbox" id="Compact" onClick="javascript:if(this.checked){$('xy').disabled=''}else{$('xy').disabled='disabled'}"><label for="Compact">接受许可协议</label><h5><input id="xy" type="submit" class="btn" style=" width:120px;height:30px;"  value="开始安装" disabled="disabled"></h5></div>
</div>
<div id='msgbottom'>Powered By DJCMS3.0</div></div>
</form>
</body>
</html>
<?php
}

function main(){
  if(!empty($_SERVER['REQUEST_URI']))
  {
  	$scriptName = $_SERVER['REQUEST_URI'];
  }
  else
  {
  	$scriptName = $_SERVER['PHP_SELF'];
  }

  $basepath = ltrim($scriptName,'/');

  if(empty($_SERVER['HTTP_HOST']))
  {
  	$baseurl = $_SERVER['HTTP_HOST'];
  }
  else
  {
  	$baseurl = $_SERVER['SERVER_NAME'];
  }
  $strInstallDir = str_replace("/install.php", "", $_SERVER["SCRIPT_NAME"]);
?>
<html><head>
<title>站点安装-基本设置</title>
<style>body{text-align:center}#installbox{background-color:white;border:1px solid #1B76B7;margin:0 auto;width:600px;text-align:left;margin-top:2em}.msgtitle{padding:3px 3px;color:white;font-weight:700;line-height:21px;height:25px;font-size:12px;border-bottom:1px solid #1B76B7; text-indent:3px; background-color:#1B76B7}#msgbody{font-size:12px;line-height:25px;height:260px;padding-top:2em;}#msgbottom{text-align:center;height:20px;line-height:20px;font-size:12px;background-color:#1b76b7;color:#FFFFFF}label{cursor:pointer;display:block;padding-left:50px;height:30px;line-height:30px}label:hover{background-color:#f5f5f5}h3{font-size:18px;font-family:"黑体";font-weight:300;border-bottom:1px solid #C4E1FF;padding:2px 0 2px 30px;color:#333}input{border-width:0;}textarea, input{padding:2px;border:1px solid;border-color:#666 #ccc #ccc #666;background:#F9F9F9;color:#333}
.btn{margin:3px 0;padding:2px 5px;*padding:4px 5px 1px;border-color:#ddd #666 #666 #ddd;background:#DDD;color:#000;cursor:pointer;vertical-align:middle}
.inpt{border:1px solid;border-color:#CCCCCC;height:23;}</style>

</head>
<body>
<form action="?action=install"  method="post"  name="installform">
<div id='installbox'><div class='msgtitle'>DjCms3.0安装向导 >> 基本设置</div>
<table style="width:598px;text-align:center;font-size:10pt;"><tr><td align="center"><span onClick="javascript:location.href='install.php?action=main'" style="display:block;float:left;cursor:pointer;background-color:#62C0FF;width:146px;color:#ffffff;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>1.</b></font>基本设置</span><span style="display:block;float:left;background-color:#eeeeee;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>2.</b></font>数据库设置</span><span style="display:block;float:left;background-color:#eeeeee;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>3.</b></font>管理员设置</span><span style="display:block;float:left;background-color:#eeeeee;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>4.</b></font>运行模式设置</span></td></tr></table>
<div id='msgbody'>
<h3>基本信息：</h3>
<label>网站名称：<input class="inpt" type="text" name="siteName" size="30" value="DjCms电影管理系统" /></label>
<label>网站地址：<input class="inpt" type="text" name="siteUrl" size="30" value="<?php echo $baseurl;?>" /><input class="inpt" type="hidden" name="sitePath" size="30" value="<?php echo $strInstallDir;?>" /><font color="blue">(自动获取,如有误差请修改)</font></label>
<br /><br />
<label><font color="blue">注意：安装DjCms3.0，需要将网站目录设置修改、写入权限。</font></label>
<br />
</div>
<table width=90%>
   <tr>
     <td align=left><h3><input type="button" class="btn"  value="<< 上一步"  onClick="javascript:location.href='install.php';"/></h3></td>
     <td align=right><h3><input type="submit" class="btn"  value="下一步 >>"/></h3></td>
   </tr>
</table>
<div id='msgbottom'>Powered By DJCMS3.0</div></div>
</form>
</body>
</html>
<?php
}

function install(){
	$siteName = getForm("siteName", "post");
	$siteUrl = getForm("siteUrl", "post");
	$sitePath = getForm("sitePath", "post");
	$configStr=file_get_contents(DJ_ROOT.'/inc/config.php');
    $configStr=preg_replace('/"siteName","(.*?)"/','"siteName","'.$siteName.'"',$configStr);
    $configStr=preg_replace('/"siteUrl","(.*?)"/','"siteUrl","'.$siteUrl.'"',$configStr);
    $configStr=preg_replace('/"sitePath","(.*?)"/','"sitePath","'.$sitePath.'"',$configStr);
    fwrite(fopen(DJ_ROOT.'/inc/config.php',"wb"),$configStr);
	alertMsg("","install.php?action=stepOne");
}

function stepOne(){
?>
<html><head>
<title>站点安装-数据库设置</title>
<script>var sitePath</script>
<script src="js/common.js"></script>
<script src="js/function.js"></script>
<style>body{text-align:center}#installbox{background-color:white;border:1px solid #1B76B7;margin:0 auto;width:600px;text-align:left;margin-top:2em}.msgtitle{padding:3px 3px;color:white;font-weight:700;line-height:21px;height:25px;font-size:12px;border-bottom:1px solid #1B76B7; text-indent:3px; background-color:#1B76B7}#msgbody{font-size:12px;line-height:25px;height:260px;padding-top:2em;}#msgbottom{text-align:center;height:20px;line-height:20px;font-size:12px;background-color:#1b76b7;color:#FFFFFF}label{display:block;padding-left:50px;height:30px;line-height:30px}label:hover{background-color:#f5f5f5}h3{font-size:18px;font-family:"黑体";font-weight:300;border-bottom:1px solid #C4E1FF;padding:2px 0 2px 30px;color:#333}input{border-width:0;}.inpt{border:1px solid;border-color:#CCCCCC;height:23;height:23px;}
textarea, input{padding:2px;border:1px solid;border-color:#666 #ccc #ccc #666;background:#F9F9F9;color:#333}
.btn{margin:3px 0;padding:2px 5px;*padding:4px 5px 1px;border-color:#ddd #666 #666 #ddd;background:#DDD;color:#000;cursor:pointer;vertical-align:middle}
</style>

</head>
<body>
<form action="?action=chkdata"  method="post"  name="installform">
<div id='installbox'><div class='msgtitle'>DjCms3.0安装向导 >> 数据库设置</div>
<table style="width:598px;text-align:center;font-size:10pt;"><tr><td align="center"><span onClick="javascript:location.href='install.php?action=main'" style="display:block;float:left;cursor:pointer;background-color:#62C0FF;width:146px;color:#ffffff;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>1.</b></font>基本设置</span><span style="display:block;float:left;cursor:pointer;background-color:#62C0FF;width:146px;color:#ffffff;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>2.</b></font>数据库设置</span><span style="display:block;float:left;background-color:#eeeeee;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>3.</b></font>管理员设置</span><span style="display:block;float:left;background-color:#eeeeee;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>4.</b></font>运行模式设置</span></td></tr></table>
<div id='msgbody'>
<h3>数据库连接设置：</h3>
<label>服务器名称：<input class="inpt" type="text" name="databaseServer" id="databaseServer" size="30" value="127.0.0.1" /><font color=red>*</font>SQL服务器IP地址或名称</label>
<label>数据库名称：<input class="inpt" type="text" name="databaseName" id="databaseName" size="30" value="djcms" /></label>
<label>数据库帐号：<input class="inpt" type="text" name="databaseUser" id="databaseUser" size="30" value="root" /></label>
<label>数据库密码：<input class="inpt" type="text" name="databasePwd" id="databasePwd" size="30" value="" /></label>
<label><font color="blue">注意：请使用程序包里的mysql数据库</font></label>

<div id="chkdata" style="text-align:center;"></div>
</div>
<table width=90%>
   <tr>
     <td align=left><h3><input type="button" class="btn"  value="<< 上一步"  onClick="javascript:location.href='install.php?action=main';"/></h3></td>
     <td align=right><h3><input type="submit" class="btn"  value="下一步 >>"/></h3></td>
   </tr>
</table>
<div id='msgbottom'>Powered By DJCMS3.0</div></div>
</form>
</body>
</html>
<?php
}

function chkDatabase(){
	$databaseServer = getForm("databaseServer", "post");
	$databaseName = getForm("databaseName", "post");
	$databaseUser = getForm("databaseUser", "post");
	$databasePwd = getForm("databasePwd", "post");
	if (empty($databaseServer)) die("<font color='red'>SQL服务器地址不能为空</font>");
	if (empty($databaseName)) die("<font color='red'>SQL数据库名不能为空</font>");
	if (empty($databaseUser)) die("<font color='red'>SQL数据库用户名不能为空</font>");
	if (empty($databaseName)) {
		die("<script>alert('数据库名为空，请填写数据库名称');history.go(-1);</script>");
	} else {
		if(!$link = @mysql_connect($databaseServer, $databaseUser, $databasePwd)) {
			$errno = mysql_errno($link);
			$error = mysql_error($link);
			if($errno == 1045) {
				die("<script>alert('无法连接数据库，请检查数据库用户名或者密码是否正确');history.go(-1);</script>");
			} elseif($errno == 2003) {
				die("<script>alert('无法连接数据库，请检查数据库是否启动，数据库服务器地址是否正确');history.go(-1);</script>");
			} else {
				die("<script>alert('数据库连接错误');history.go(-1);</script>");
			}
		}

		if(mysql_get_server_info() > '4.1') {
			mysql_query("CREATE DATABASE IF NOT EXISTS `$databaseName` DEFAULT CHARACTER SET gbk", $link);
		} else {
			mysql_query("CREATE DATABASE IF NOT EXISTS `$databaseName`", $link);
		}

		if(mysql_errno()) {
			$errno = mysql_errno($link);
			die("<script>alert('$errno');history.go(-1);</script>");
		}
		mysql_close($link);
	}
	$db = new dbstuff;
	$db->connect($databaseServer, $databaseUser, $databasePwd, $databaseName, 'gbk');
	$sql = file_get_contents(dirname(__FILE__).'/djcms.sql');
	$sql = str_replace("\r\n", "\n", $sql);
	$ret = array();
	$num = 0;
	foreach(explode(";\n", trim($sql)) as $query) {
		$ret[$num] = '';
		$queries = explode("\n", trim($query));
		foreach($queries as $query) {
			$ret[$num] .= (isset($query[0]) && $query[0] == '#') || (isset($query[1]) && isset($query[1]) && $query[0].$query[1] == '--') ? '' : $query;
		}
		$num++;
	}
	unset($sql);

	foreach($ret as $query) {
		$query = trim($query);
		if($query) {

			if(substr($query, 0, 12) == 'CREATE TABLE') {
				$name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
				$db->query(createtable($query));
			} else {
				$db->query($query);
			}

		}
	}
   
    $configStr=file_get_contents(DJ_ROOT.'/inc/config.php');
    $configStr=preg_replace('/"databaseServer","(.*?)"/','"databaseServer","'.$databaseServer.'"',$configStr);
    $configStr=preg_replace('/"databaseName","(.*?)"/','"databaseName","'.$databaseName.'"',$configStr);
    $configStr=preg_replace('/"databaseUser","(.*?)"/','"databaseUser","'.$databaseUser.'"',$configStr);
    $configStr=preg_replace('/"databasePwd","(.*?)"/','"databasePwd","'.$databasePwd.'"',$configStr);
    fwrite(fopen(DJ_ROOT.'/inc/config.php',"wb"),$configStr);
    alertMsg("","install.php?action=stepTwo");
}

function stepTwo(){
?>
<html><head>
<title>站点安装-管理账号</title>
<script>
function $(id){
	return document.getElementById(id)	
}

function chkUser(){
	if($('user').value == ''){alert('用户名不能为空');return false;}
	if($('pwd1').value == ''){alert('密码不能为空');return false;}
	if($('pwd2').value == ''){alert('确认密码不能为空');return false;}
	if($('pwd2').value != $('pwd2').value){alert('两次输入密码不一致');return false;}
	//$('installform').action='?action=stepThr&setUser=setUser';$('installform').submit();
	return true;
}
</script>
<style>body{text-align:center}#installbox{background-color:white;border:1px solid #1B76B7;margin:0 auto;width:600px;text-align:left;margin-top:2em}.msgtitle{padding:3px 3px;color:white;font-weight:700;line-height:21px;height:25px;font-size:12px;border-bottom:1px solid #1B76B7; text-indent:3px; background-color:#1B76B7}#msgbody{font-size:12px;line-height:25px;height:260px;padding-top:2em;}#msgbottom{text-align:center;height:20px;line-height:20px;font-size:12px;background-color:#1b76b7;color:#FFFFFF}label{display:block;padding-left:50px;height:30px;line-height:30px}label:hover{background-color:#f5f5f5}h3{font-size:18px;font-family:"黑体";font-weight:300;border-bottom:1px solid #C4E1FF;padding:2px 0 2px 30px;color:#333}input{border-width:0;}textarea, input{padding:2px;border:1px solid;border-color:#666 #ccc #ccc #666;background:#F9F9F9;color:#333}
.btn{margin:3px 0;padding:2px 5px;*padding:4px 5px 1px;border-color:#ddd #666 #666 #ddd;background:#DDD;color:#000;cursor:pointer;vertical-align:middle}
.inpt{border:1px solid;border-color:#CCCCCC;height:23;}</style>

</head>
<body>
<form action="?action=stepThr&setUser=setUser"  method="post" onSubmit="return chkUser();"  name="installform">
<div id='installbox'><div class='msgtitle'>DjCms3.0安装向导 >> 管理员设置</div>
<table style="width:598px;text-align:center;font-size:10pt;"><tr><td align="center"><span onClick="javascript:location.href='install.php?action=main'" style="display:block;float:left;cursor:pointer;background-color:#62C0FF;width:146px;color:#ffffff;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>1.</b></font>基本设置</span><span onClick="javascript:location.href='install.php?action=stepOne'" style="display:block;float:left;cursor:pointer;background-color:#62C0FF;width:146px;color:#ffffff;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>2.</b></font>数据库设置</span><span style="display:block;float:left;cursor:pointer;background-color:#62C0FF;width:146px;color:#ffffff;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>3.</b></font>管理员设置</span><span style="display:block;float:left;background-color:#eeeeee;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>4.</b></font>运行模式设置</span></td></tr></table>
<div id='msgbody'>

<h3>设置管理账号：</h3>
<input type="hidden" name="uType" value="add">
<label>管理账号：<input class="inpt" type="text" name="user" id="user" size="20" value="admin" /></label>
<label>管理密码：<input class="inpt" type="text" name="pwd1" id="pwd1" size="20" value="" /></label>
<label>确认密码：<input class="inpt" type="text" name="pwd2" id="pwd2" value="" /></label>
</div>
<table width=90%>
   <tr>
     <td align=left><h3><input type="button" class="btn"  value="<< 上一步"  onClick="javascript:location.href='install.php?action=stepOne';"/></h3></td>
     <td align=right><h3><input type="submit" class="btn"  value="下一步 >>"/></h3></td>
   </tr>
</table>
<div id='msgbottom'>Powered By DJCMS3.0</div></div>
</form>
</body>
</html>

<?php
}

function stepThr(){
	$setUser = getForm("setUser", "post");
	$user = getForm("user", "post");
	$pwd1 = getForm("pwd1", "post");
	$pwd2 = getForm("pwd2", "post");
	$uType = getForm("uType", "post");
	require_once (DJ_ROOT."/inc/config.php");
    $db = new dbstuff;
	$db->connect(databaseServer, databaseUser, databasePwd, databaseName, 'gbk');
	if($setUser="setUser"){
		if(empty($user) || empty($pwd1) || empty($pwd2)) alertMsg("用户名或密码不能为空","<script>history.go(-1)</script>");
		if($pwd1<>$pwd2) alertMsg("两次密码输入不一致","<script>history.go(-1)</script>");
		$db->query("insert into  m_manager(m_username,m_pwd,m_level,m_state) values ('$user','".md5($pwd1)."',0,1)");
	}

?>
<html><head>
<title>站点安装-运行模式</title>
<script>
function checkSelected(){
	for(i=0;i<installform.playermode.length;i++){
		if(installform.playermode[i].checked==true) return true;
	}
	alert("请选择播放器设置")
	return false; 
}
</script>

<style>body{text-align:center}#installbox{background-color:white;border:1px solid #1B76B7;margin:0 auto;width:600px;text-align:left;margin-top:2em}.msgtitle{padding:3px 3px;color:white;font-weight:700;line-height:21px;height:25px;font-size:12px;border-bottom:1px solid #1B76B7; text-indent:3px; background-color:#1B76B7}#msgbody{font-size:12px;line-height:25px;height:260px;padding-top:2em;}#msgbottom{text-align:center;height:20px;line-height:20px;font-size:12px;background-color:#1b76b7;color:#FFFFFF}label{cursor:pointer;display:block;padding-left:50px;height:30px;line-height:30px}label:hover{background-color:#f5f5f5}h3{font-size:18px;font-family:"黑体";font-weight:300;border-bottom:1px solid #C4E1FF;padding:2px 0 2px 30px;color:#333}input{border-width:0;}textarea, input{padding:2px;border:1px solid;border-color:#666 #ccc #ccc #666;background:#F9F9F9;color:#333}
.btn{margin:3px 0;padding:2px 5px;*padding:4px 5px 1px;border-color:#ddd #666 #666 #ddd;background:#DDD;color:#000;cursor:pointer;vertical-align:middle}
.radio{border:0}
</style>

</head>
<body>
<form action="?action=stepFour"  method="post"  name="installform">
<div id='installbox'><div class='msgtitle'>DjCms3.0安装向导 >> 运行模式设置</div>
<table style="width:598px;text-align:center;font-size:10pt;"><tr><td align="center"><span onClick="javascript:location.href='install.php?action=main'" style="display:block;float:left;cursor:pointer;background-color:#62C0FF;width:146px;color:#ffffff;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>1.</b></font>基本设置</span><span onClick="javascript:location.href='install.php?action=stepOne'" style="display:block;float:left;cursor:pointer;background-color:#62C0FF;color:#ffffff;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>2.</b></font>数据库设置</span><span onClick="javascript:location.href='install.php?action=stepTwo'" style="display:block;float:left;cursor:pointer;background-color:#62C0FF;width:146px;color:#ffffff;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>3.</b></font>管理员设置</span><span style="display:block;float:left;cursor:pointer;background-color:#62C0FF;width:146px;color:#ffffff;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>4.</b></font>运行模式设置</span></td></tr></table>
<div id='msgbody'>
<h3>页面运行模式：</h3>
<label for="sitemode"><input type="radio"  name="sitemode" id="sitemode" value="dynamic" class="radio"  checked />动态模式</label>
<label for="sitemode"><input type="radio"  name="sitemode" id="sitemode" value="static" class="radio" />静态模式(<font color="blue">详细配置请登陆系统后台站点配置</font>)</label>
<h3>播放器选择：</h3>
<label for="playermode"><input type="radio"  name="playermode" id="playermode"  value="1" class="radio" />站内(<font color="blue">站内播放，</font><font color="red">可自动播放，可连播</font><font color="blue">，更多播放器参数请在网站后台的<font color="red">"播放器设置"</font>中修改</font>)</label>
<label for="playermode"><input type="radio"  name="playermode" id="playermode" value="0" class="radio"  />站外(<font color="blue">指视频站默认提供的原始引用地址，不能自动播放，不能连播</font>)</label>
</div>
<table width=90%>
   <tr>
     <td align=left><h3><input type="button" class="btn"  value="<< 上一步"  onClick="javascript:location.href='install.php?action=stepTwo';"/></h3></td>
     <td align=right><h3><input type="submit" class="btn"  value="完成安装"  onClick="return checkSelected()"/></h3></td>
   </tr>
</table>
<div id='msgbottom'>Powered By DJCMS3.0</div></div>
</form>
</body>
</html>
<?php
}

function stepFour(){
	$sitemode=getForm("sitemode","post") ; $playermode=getForm("playermode","post");
	if (empty($sitemode) || $playermode=="") die("安装前请选择相关设置");
	$configStr=file_get_contents(DJ_ROOT."/inc/config.php");
    $configStr=preg_replace("/runMode='(.*?)';/is","runMode='".$sitemode."';",$configStr);
	fwrite(fopen(DJ_ROOT."/inc/config.php","wb"),$configStr);
	
	$configStr=file_get_contents(DJ_ROOT."/js/play.js");
	$configStr=preg_replace("/autoPlay=\"(\d+)\";/is","autoPlay=\"".$playermode."\";",$configStr);
	fwrite(fopen(DJ_ROOT."/js/play.js","wb"),$configStr);
?>
<html><head>
<title>安装完成</title>
<script>
function checkSelected(){
	for(i=0;i<installform.playermode.length;i++){
		if(installform.playermode[i].checked==true) return true;
	}
	alert("请选择播放器设置")
	return false; 
}
</script>

<style>body{text-align:center}#installbox{background-color:white;border:1px solid #1B76B7;margin:0 auto;width:600px;text-align:left;margin-top:2em}.msgtitle{padding:3px 3px;color:white;font-weight:700;line-height:21px;height:25px;font-size:12px;border-bottom:1px solid #1B76B7; text-indent:3px; background-color:#1B76B7}#msgbody{font-size:12px;line-height:25px;height:260px;padding-top:2em;}#msgbottom{text-align:center;height:20px;line-height:20px;font-size:12px;background-color:#1b76b7;color:#FFFFFF}label{display:block;text-align:center;height:30px;line-height:30px}label:hover{background-color:#f5f5f5}h3{font-size:18px;font-family:"黑体";font-weight:300;border-bottom:1px solid #C4E1FF;padding:2px 0 2px 30px;color:#333}input{border-width:0;height:40px;width:90px;}textarea, input{padding:2px;border:1px solid;border-color:#666 #ccc #ccc #666;background:#F9F9F9;color:#333}
.btn{margin:3px 0;padding:2px 5px;*padding:4px 5px 1px;border-color:#ddd #666 #666 #ddd;background:#DDD;color:#000;cursor:pointer;vertical-align:middle}
</style>

</head>
<body>
<div id='installbox'><div class='msgtitle'>DjCms3.0安装完成</div>
<table style="width:598px;text-align:center;font-size:10pt;"><tr><td align="center"><span  style="display:block;float:left;background-color:#62C0FF;width:146px;color:#ffffff;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>1.</b></font>基本设置</span><span  style="display:block;float:left;background-color:#62C0FF;color:#ffffff;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>2.</b></font>数据库设置</span><span style="display:block;float:left;background-color:#62C0FF;width:146px;color:#ffffff;width:146px;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>3.</b></font>管理员设置</span><span style="display:block;float:left;background-color:#62C0FF;width:146px;color:#ffffff;border:solid 1px #ffffff;font-size:12px;"><font size="4"><b>4.</b></font>运行模式设置</span></td></tr></table>
<div id='msgbody'>
<h3>恭喜你！DJCMS3.0安装成功！</h3>
<div   style="text-align:center; font-size:16px;font-family:'黑体'" style="color:#1B76B7;">现在就开始体验DjCms的简洁与高效吧！</div>
<div style="margin-top:2em;align:center;width:100%;">
<table width="60%" align=center>
   <tr>
     <td align=left><input type="button" class="btn" style=" width:120px;height:30px;" value="进入网站首页"  onClick="javascript:location.href='index.php';"/></td>
     <td align=right><input type="button" class="btn" style=" width:120px;height:30px;" value="登陆网站后台"  onClick="javascript:location.href='admin/index.php';"/></td>
   </tr>
</table>
</div>
</div>
<div id='msgbottom'>Powered By DJCMS3.0</div></div>
</body>
</html>
<?php
    rename(DJ_ROOT."install.php",DJ_ROOT."install.phpbak");
	//rename("djcms.sql","djcms.sql");
   // @unlink("install.php"); 
	//alertMsg "完成安装转到后台登陆","admin/index.php"
}

function createtable($sql) {

	$type = strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql));
	$type = in_array($type, array('MYISAM', 'HEAP', 'MEMORY')) ? $type : 'MYISAM';
	return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql).
	(mysql_get_server_info() > '4.1' ? " ENGINE=$type DEFAULT CHARSET='gbk'" : " TYPE=$type");
}

class dbstuff {
	var $querynum = 0;
	var $link;
	var $histories;
	var $time;

	function connect($dbhost, $dbuser, $dbpw, $dbname = '', $dbcharset, $pconnect = 0, $tablepre='', $time = 0) {
		$this->time = $time;
		if($pconnect) {
			if(!$this->link = mysql_pconnect($dbhost, $dbuser, $dbpw)) {
				$this->halt('Can not connect to MySQL server');
			}
		} else {
			if(!$this->link = mysql_connect($dbhost, $dbuser, $dbpw, 1)) {
				$this->halt('Can not connect to MySQL server');
			}
		}

		if($this->version() > '4.1') {
			if($dbcharset) {
				mysql_query("SET character_set_connection=".$dbcharset.", character_set_results=".$dbcharset.", character_set_client=binary", $this->link);
			}

			if($this->version() > '5.0.1') {
				mysql_query("SET sql_mode=''", $this->link);
			}
		}

		if($dbname) {
			mysql_select_db($dbname, $this->link);
		}

	}

	function query($sql, $type = '', $cachetime = FALSE) {
		$func = $type == 'UNBUFFERED' && @function_exists('mysql_unbuffered_query') ? 'mysql_unbuffered_query' : 'mysql_query';
		if(!($query = $func($sql, $this->link)) && $type != 'SILENT') {
			$this->halt('SQL:', $sql);
		}
		$this->querynum++;
		return $query;
	}
	function error() {
		return (($this->link) ? mysql_error($this->link) : mysql_error());
	}

	function errno() {
		return intval(($this->link) ? mysql_errno($this->link) : mysql_errno());
	}
	function version() {
		return mysql_get_server_info($this->link);
	}
	
	function halt($message = '', $sql = '') {
		$errormsg = "<b>MySQL Query : </b>$sql <br /><b> MySQL Error : </b>".$this->error()." <br /> <b>MySQL Errno : </b>".$this->errno()." <br /><b> Message : </b> $message";
	}
}

function getForm($k, $type='GP') {
	$type = strtolower($type);
	switch($type) {
		case 'get': $var = &$_GET; break;
		case 'post': $var = &$_POST; break;
		case 'cookie': $var = &$_COOKIE; break;
		default:
			if(isset($_GET[$k])) {
				$var = &$_GET;
			} else {
				$var = &$_POST;
			}
			break;
	}
	return isset($var[$k]) ? $var[$k] : NULL;
}

function alertMsg($str, $url) {
	$urlstr='';
	if (!empty($url)) $urlstr="location.href='$url';";
	if (!empty($str)) $str="alert('$str');";
	echo "<script>$str$urlstr</script>";
}
?>