<?php
error_reporting(0);

@set_time_limit(1000);

if(file_exists("../../c/einstall/install.off"))
{
	echo"《帝國網站管理系統》安裝程序已鎖定。如果要重新安裝，請刪除<b>/c/einstall/install.off</b>文件！";
	exit();
}

//安裝密碼
include('data/fun.php');
$ins_password='';
$ins_pwvar='';
$ins_insretime=0;
include('ins_config.php');
eins_CkInsPass();

include("../class/connect.php");
include("../class/functions.php");
include LoadLang("pub/fun.php");
include("../class/t_functions.php");
include("../data/dbcache/class.php");
$link=db_connect();
$empire=new mysqlquery();

$ecms=$_GET['ecms'];
$defaultdata=(int)$_GET['defaultdata'];
$echdbtype=(int)$_GET['echdbtype'];

//----------------生成表情JS
function eins_InstallGetPlfaceJs(){
	global $empire,$dbtbpre,$public_r;
	$r=$empire->fetch1("select plface,plfacenum from {$dbtbpre}enewspl_set".do_dblimit_one());
	if(empty($r['plfacenum']))
	{
		return '';
	}
	$filename="../../d/js/js/plface.js";
	$facer=explode('||',$r['plface']);
	$count=count($facer);
	for($i=1;$i<$count-1;$i++)
	{
		if($i%$r['plfacenum']==0)
		{
			$br="<br>";
		}
		else
		{
			$br="&nbsp;";
		}
		$face=explode('##',$facer[$i]);
		$allface.="<a href='#eface' onclick=\\\"eaddplface('".$face[0]."');\\\"><img src='".$public_r['newsurl']."d/efilepub/eplface/".$face[1]."' border=0></a>".$br;
	}
	$allface="document.write(\"<script src='".$public_r['newsurl']."e/data/js/addplface.js'></script>\");document.write(\"".$allface."\");";
	WriteFiletext_n($filename,$allface);
}

//更新其它數據
if($ecms=='ChangeInstallOtherData')
{
	//--- 刪除緩存文件 ---
	DelListEnews();
	//--- 更新動態頁面 ---
	GetPlTempPage();//評論列表模板
	GetPlJsPage();//評論JS模板
	ReCptemp();//控制面板模板
	GetSearch();//三搜索表單模板
	GetPrintPage();//打印模板
	GetDownloadPage();//下載地址頁面
	ReGbooktemp();//留言板模板
	ReLoginIframe();//登陸狀態模板
	ReSchAlltemp();//全站搜索模板
	//生成首頁
	$indextemp=GetIndextemp();
	NewsBq(0,$indextemp,1,0);
	//--- 更新反饋表單 ---
	$sql=$empire->query("select bid,btemp from {$dbtbpre}enewsfeedbackclass order by bid");
	while($r=$empire->fetch($sql))
	{
		//替換公共變量
		$btemp=ReplaceTempvar($r['btemp']);
		$btemp=str_replace("[!--cp.header--]","<?php include(\"../../../c/ecachetemp/epubtemp/cp_1.php\");?>",$btemp);
		$btemp=str_replace("[!--cp.footer--]","<?php include(\"../../../c/ecachetemp/epubtemp/cp_2.php\");?>",$btemp);
		$btemp=str_replace("[!--member.header--]","<?php include(\"../../template/incfile/header.php\");?>",$btemp);
		$btemp=str_replace("[!--member.footer--]","<?php include(\"../../template/incfile/footer.php\");?>",$btemp);
		$file="../../c/ecachetemp/efbtemp/feedback".$r['bid'].".php";
		$btemp="<?php
if(!defined('InEmpireCMS'))
{exit();}
?>".$btemp;
		WriteFiletext($file,$btemp);
	}
	//--- 評論表情文件 ---
	eins_InstallGetPlfaceJs();
	echo"更新文件完畢.<script>self.location.href='index.php?enews=changetbpgsql&f=5&ok=1&echdbtype=$echdbtype&defaultdata=$defaultdata';</script>";
	exit();
}
else//更新數據庫緩存
{
	GetConfig(1);//更新參數設置
	GetClass();//更新欄目
	GetMemberLevel();//更新會員組
	GetSearchAllTb();//更新全站搜索數據表
	EcmsConfigDayUpRnd('mustdore');//天天隨機驗證字符
	echo"更新數據庫緩存完畢.<script>self.location.href='changedata.php?ecms=ChangeInstallOtherData&echdbtype=$echdbtype&defaultdata=$defaultdata';</script>";
	exit();
}
?>