<?php
error_reporting(E_ALL ^ E_NOTICE);

@set_time_limit(10000);

define('EmpireCMSAdmin','1');
require("../class/connect.php");
require("../class/db_sql.php");
require("../class/functions.php");
require("../data/dbcache/class.php");
require("data/fun.php");
require('upconfig.php');
if(!$_GET['ecms']||$_GET['ecms']=="ChangeConfigFile")
{}
else
{
$link=db_connect();
$empire=new mysqlquery();
}

if($_GET['ecms']=="success")
{
	echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><br><br><br><font color=red><b>帝国网站管理系统6.6版数据库升7.0版成功!请按照升级说明继续完成升级操作。</b></font>";
	exit();
}
elseif($_GET['ecms']=="ChangeInfoTbData")//信息表数据转换(2)
{
	include('data/infosql.php');
	upChangeInfoTbData($_GET);
	exit();
}
elseif($_GET['ecms']=="ChangePlTbData")//评论表数据转换(3)
{
	include('data/plsql.php');
	upChangePlTbData($_GET);
	exit();
}
elseif($_GET['ecms']=="ChangeFileTbData")//附件表数据转换(4)
{
	include('data/filesql.php');
	upChangeFileTbData($_GET);
	exit();
}
elseif($_GET['ecms']=="ChangeMemberTbData")//会员表数据转换(5)
{
	include('data/membersql.php');
	upChangeMemberTbData($_GET);
	exit();
}
elseif($_GET['ecms']=="ChangeShopTbData")//商城订单数据转换(6)
{
	include('data/shopsql.php');
	upChangeShopTbData($_GET);
	exit();
}
elseif($_GET['ecms']=="ChangeTable")//数据表结构升级(7)
{
	include('data/sql.php');
	echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><br>第七步：数据表结构升级完毕，正进入数据库缓存更新......<script>self.location.href='index.php?ecms=ChangeDbCache';</script>";
	exit();
}
elseif($_GET['ecms']=="ChangeDbCache")//更新数据库缓存(8)
{
	upChangeDbCache();
	echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><br>第八步：数据库缓存更新完毕，正进入动态页面更新......<script>self.location.href='index.php?ecms=ChangeFieldData';</script>";
	exit();
}
elseif($_GET['ecms']=="ChangeFieldData")//字段html代码更新(9)
{
	include('data/fieldsql.php');
	upChangeFieldInfo();
	upChangeFieldMember();
	upChangeFieldClass();
	upChangeFieldZt();
	echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><br>第九步：字段html代码更新完毕，正进入动态页面更新......<script>self.location.href='index.php?ecms=ChangeDtFile';</script>";
	exit();
}
elseif($_GET['ecms']=="ChangeDtFile")//更新动态页面(10)
{
	include("../class/moddofun.php");
	upChangeDtFile();
	upChangeAllModForm();
	echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><br>第十步：动态页面更新完毕，正进入会员接口升级......<script>self.location.href='index.php?ecms=ChangeMemberCOM';</script>";
	exit();
}
elseif($_GET['ecms']=="ChangeMemberCOM")//会员接口升级(11)
{
	include('data/membercom.php');
	upChangeMemberCom();
	echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><br>第十一步：会员接口升级完毕，马上完成......<script>self.location.href='index.php?ecms=success';</script>";
	exit();
}
elseif($_GET['ecms']=="ChangeConfigFile")//更新数据库配置文件(1)
{
	CheckReUpdate();
	include('../class/config.php');
	include("../class/user.php");

	$filetext=ReadFiletext('data/config.php');
	//数据库信息
	$filetext=str_replace('[!@--dbtype--@!]',$phome_use_db,$filetext);
	$filetext=str_replace('[!@--dbver--@!]',$phome_use_dbver,$filetext);
	$filetext=str_replace('[!@--dbhost--@!]',$phome_db_server,$filetext);
	$filetext=str_replace('[!@--dbport--@!]',$phome_db_port,$filetext);
	$filetext=str_replace('[!@--dbusername--@!]',$phome_db_username,$filetext);
	$filetext=str_replace('[!@--dbpassword--@!]',$phome_db_password,$filetext);
	$filetext=str_replace('[!@--dbname--@!]',$phome_db_dbname,$filetext);
	$filetext=str_replace('[!@--setchar--@!]',$phome_db_char,$filetext);
	$filetext=str_replace('[!@--dbchar--@!]',$phome_db_dbchar,$filetext);
	$filetext=str_replace('[!@--tbpre--@!]',$dbtbpre,$filetext);

	//其他相关设置
	$filetext=str_replace('[!@--pagechar--@!]',$phome_ecms_charver,$filetext);
	$filetext=str_replace('[!@--setpagechar--@!]',$phome_headercharset,$filetext);
	$filetext=str_replace('[!@--elang--@!]',$ecmslang,$filetext);
	$filetext=str_replace('[!@--openonlinesetting--@!]',$do_openonlinesetting,$filetext);
	if($do_txtpath==ECMS_PATH.'d/txt/')
	{
		$truetxtpath="ECMS_PATH.'d/txt/'";
	}
	else
	{
		$truetxtpath="'$do_txtpath'";
	}
	$filetext=str_replace('[!@--txtpath--@!]',$truetxtpath,$filetext);
	$filetext=str_replace('[!@--saveurlimgclearurl--@!]',$saveurlimgclearurl,$filetext);
	$filetext=str_replace('[!@--deftempid--@!]',$ecmsdeftempid,$filetext);

	//会员接口信息
	if(stristr($user_tablename,'enewsmember'))
	{
		$truemembertablename=$user_tablename==$dbtbpre.'enewsmember'?'"{$dbtbpre}enewsmember"':"'$user_tablename'";
		$truechmember=0;
		$truepwtype=2;
		$trueregtimetype=1;
		$truesaltnum=6;
		$user_salt='salt';
		$fuserkey='userkey';
	}
	else
	{
		$truemembertablename="'$user_tablename'";
		$truechmember=1;
		$truepwtype=$user_dopass;
		$trueregtimetype=$user_register;
		$truesaltnum=$user_saltnum;
		$user_salt=$user_dopass==2?'enewssalt':$user_salt;
		$fuserkey='enewsuserkey';
	}
	$filetext=str_replace('[!@--membertablename--@!]',$truemembertablename,$filetext);
	$filetext=str_replace('[!@--changeregisterurl--@!]',$changeregisterurl,$filetext);
	$filetext=str_replace('[!@--registerurl--@!]',$registerurl,$filetext);
	$filetext=str_replace('[!@--loginurl--@!]',$eloginurl,$filetext);
	$filetext=str_replace('[!@--quiturl--@!]',$equiturl,$filetext);
	$filetext=str_replace('[!@--chmember--@!]',$truechmember,$filetext);
	$filetext=str_replace('[!@--pwtype--@!]',$truepwtype,$filetext);
	$filetext=str_replace('[!@--regtimetype--@!]',$trueregtimetype,$filetext);
	$filetext=str_replace('[!@--regcookietime--@!]',$user_regcookietime,$filetext);
	$filetext=str_replace('[!@--defgroupid--@!]',$user_groupid,$filetext);
	$filetext=str_replace('[!@--saltnum--@!]',$truesaltnum,$filetext);
	$filetext=str_replace('[!@--utfdata--@!]',$utfdata,$filetext);

	$filetext=str_replace('[!@--fuserid--@!]',$user_userid,$filetext);
	$filetext=str_replace('[!@--fusername--@!]',$user_username,$filetext);
	$filetext=str_replace('[!@--fpassword--@!]',$user_password,$filetext);
	$filetext=str_replace('[!@--frnd--@!]',$user_rnd,$filetext);
	$filetext=str_replace('[!@--femail--@!]',$user_email,$filetext);
	$filetext=str_replace('[!@--fregistertime--@!]',$user_registertime,$filetext);
	$filetext=str_replace('[!@--fgroupid--@!]',$user_group,$filetext);
	$filetext=str_replace('[!@--fuserfen--@!]',$user_userfen,$filetext);
	$filetext=str_replace('[!@--fuserdate--@!]',$user_userdate,$filetext);
	$filetext=str_replace('[!@--fmoney--@!]',$user_money,$filetext);
	$filetext=str_replace('[!@--fzgroupid--@!]',$user_zgroup,$filetext);
	$filetext=str_replace('[!@--fhavemsg--@!]',$user_havemsg,$filetext);
	$filetext=str_replace('[!@--fchecked--@!]',$user_checked,$filetext);
	$filetext=str_replace('[!@--fsalt--@!]',$user_salt,$filetext);
	$filetext=str_replace('[!@--fuserkey--@!]',$fuserkey,$filetext);

	//安全设置
	$filetext=str_replace('[!@--loginauth--@!]',$do_loginauth,$filetext);
	$filetext=str_replace('[!@--ecookiernd--@!]',$do_ecookiernd,$filetext);
	$filetext=str_replace('[!@--ckhloginfile--@!]',$do_ckhloginfile,$filetext);
	$filetext=str_replace('[!@--ckhloginip--@!]',$do_ckhloginip,$filetext);
	$filetext=str_replace('[!@--theloginlog--@!]',$do_theloginlog,$filetext);
	$filetext=str_replace('[!@--thedolog--@!]',$do_thedolog,$filetext);

	//COOKIE设置
	$filetext=str_replace('[!@--cookiedomain--@!]',$phome_cookiedomain,$filetext);
	$filetext=str_replace('[!@--cookiepath--@!]',$phome_cookiepath,$filetext);
	$filetext=str_replace('[!@--cookievarpre--@!]',$phome_cookievarpre,$filetext);
	$filetext=str_replace('[!@--cookieadminvarpre--@!]',$phome_cookieadminvarpre,$filetext);
	$filetext=str_replace('[!@--cookieckrnd--@!]',$phome_cookieckrnd,$filetext);
	$cookieckrndtwo=make_password(36);
	$filetext=str_replace('[!@--cookieckrndtwo--@!]',$cookieckrndtwo,$filetext);

	//防火墙
	$filetext=str_replace('[!@--fwopen--@!]',$efw_open,$filetext);
	$filetext=str_replace('[!@--fwpass--@!]',$efw_pass,$filetext);
	$filetext=str_replace('[!@--fwadminloginurl--@!]',$efw_adminloginurl,$filetext);
	$filetext=str_replace('[!@--fwadminhour--@!]',$efw_adminhour,$filetext);
	$filetext=str_replace('[!@--fwadminweek--@!]',$efw_adminweek,$filetext);
	$filetext=str_replace('[!@--fwadminckpassvar--@!]',$efw_adminckpassvar,$filetext);
	$filetext=str_replace('[!@--fwadminckpassval--@!]',$efw_adminckpassval,$filetext);
	$filetext=str_replace('[!@--fwcleargettext--@!]',$efw_cleargettext,$filetext);

	//文件类型
	$filetext=str_replace('[!@--tranpicturetype--@!]',$tranpicturetype,$filetext);
	$filetext=str_replace('[!@--tranflashtype--@!]',$tranflashtype,$filetext);
	$filetext=str_replace('[!@--mediaplayertype--@!]',$mediaplayertype,$filetext);
	$filetext=str_replace('[!@--realplayertype--@!]',$realplayertype,$filetext);

	//其他
	$filetext=str_replace('[!@--pnewsurl--@!]',$public_r['newsurl'],$filetext);

	WriteFiletext_n('../config/config.php',$filetext);

	echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><br>第一步：配置文件转换完毕，正进入信息表数据转换......<script>self.location.href='index.php?ecms=ChangeInfoTbData';</script>";
	exit();
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>帝国网站管理系统6.6版升7.0版升级程序</title>
<style>
a:link     { COLOR: #000000; TEXT-DECORATION: none }
a:visited   { COLOR: #000000 ; TEXT-DECORATION: none }
a:active   { COLOR: #000000 ; TEXT-DECORATION: underline }
a:hover    { COLOR: #000000 ; TEXT-DECORATION:underline }
.home_top { border-top:2px solid #4798ED; }
.home_path { background:#4798ED; padding-right:10px; color:#F0F0F0; font-size: 11px; }
td, th, caption { font-family:  "宋体"; font-size: 14px; color:#000000;  LINE-HEIGHT: 165%; }
.hrLine{MARGIN: 0px 0px; BORDER-BOTTOM: #807d76 1px dotted;}
</style>
<script>
function CheckUpdate(obj){
	if(confirm('确认开始升级?'))
	{
		obj.updatebutton.disabled=true;
		return true;
	}
	return false;
}
</script>
</head>
<body>
<form method="GET" action="index.php" name="formupdate" onsubmit="return CheckUpdate(document.formupdate);">
  <br>
  <br>
  <br>
  <table width="660" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#0472BC">
    <tr> 
      <td height="30"> <div align="center"><strong><font color="#FFFFFF">帝国网站管理系统6.6版升7.0版升级程序</font></strong></div></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="50"> <div align="center"> 
          <input type=submit name=updatebutton value="开始升级">
          <input name="ecms" type="hidden" id="ecms" value="ChangeConfigFile">
        </div></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="25"> <div align="center">说明：点击开始升级。(共十一个更新项)</div></td>
    </tr>
  </table>
</form>
  </body>
  </html>