<?php
error_reporting(0);

@set_time_limit(1000);

define('InEmpireCMS',TRUE);
define('InEmpireCMSIns',TRUE);
define('ECMS_PATH',substr(dirname(__FILE__),0,-9));
define('MAGIC_QUOTES_GPC',function_exists('ini_get')&&ini_get('magic_quotes_gpc'));
define('STR_IREPLACE',function_exists('str_ireplace'));

@header('Content-Type: text/html; charset=utf-8');

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

$ecms_config=array();
$ecms_config['db']['showerror']=1;
$link='';
$empire='';
$dbtbpre='';

//導入文件
include('data/fun.php');
include('../class/EmpireCMS_version.php');

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


//------ 參數開始 ------

$char_r=array();
$char_r=eins_InstallReturnDbChar();
$version="8.0,1735574400";
$dbchar=$char_r['dbchar'];
$setchar=$char_r['setchar'];
$headerchar=$char_r['headerchar'];
$eins_candefdata=0;
$eins_usepgsql=0;

//------ 參數結束 ------

$enews=$_GET['enews'];
if(empty($enews))
{
	$enews=$_POST['enews'];
}
//測試採集
if($enews=="TestCj")
{
	echo"<title>TEST</title>";
	eins_TestCj();
}
$ok=$_GET['ok'];
if(empty($ok))
{
	$ok=$_POST['ok'];
}
$ok=(int)$ok;
//步驟
$f=$_GET['f'];
if(empty($f))
{
	$f=$_POST['f'];
}
if(empty($f))
{
	$f=1;
}
$f=(int)$f;
//數據庫類型
$echdbtype=$_GET['echdbtype'];
if(empty($echdbtype))
{
	$echdbtype=$_POST['echdbtype'];
}
if(empty($echdbtype))
{
	$echdbtype=0;
}
$echdbtype=(int)$echdbtype;
$eusedbtypename=$echdbtype>2?'PostgreSQL':'MySQL';
//數據庫操作
if($ok)
{
	if($enews=='setdb'||$enews=='systb'||$enews=='systbdata'||$enews=='modtb'||$enews=='modtbdata'||$enews=='templatetb'||$enews=='templatetbdata'||$enews=='defaultdata'||$enews=='firstadmin'||$enews=='changetbpgsql')
	{
		if($enews!='setdb')
		{
			@include("../config/config.php");
			$ecms_config['db']['showerror']=1;
		}
		if($echdbtype>2)//pgsql
		{
			if(!function_exists('pg_connect'))
			{
				echo'PostgreSQL is close!';
				exit();
			}
			if($eins_usepgsql!=1)
			{
				echo'此項需商業授權版才支持';
				exit();
			}
			include('../class/dbpg/db_pgsql.php');
			include('../class/dbpg/mytopgsqltb.php');
		}
		else//mysql
		{
			if(function_exists('mysql_connect')||function_exists('mysqli_connect'))
			{}
			else
			{
				echo'MySQL is close!';
				exit();
			}
			if(function_exists('mysql_connect'))
			{
				include('../class/db/db_mysql.php');
			}
			else
			{
				include('../class/db/db_mysqli.php');
			}
		}
	}
}
//處理
if($enews=="setdb"&&$ok)
{
	eins_SetDb($_POST);
}
elseif($enews=="systb"&&$ok)
{
	eins_InstallTb($_GET);
}
elseif($enews=="systbdata"&&$ok)
{
	eins_InstallTbData($_GET);
}
elseif($enews=="modtb"&&$ok)
{
	eins_InstallModTb($_GET);
}
elseif($enews=="modtbdata"&&$ok)
{
	eins_InstallModTbData($_GET);
}
elseif($enews=="templatetb"&&$ok)
{
	eins_InstallTemplateTb($_GET);
}
elseif($enews=="templatetbdata"&&$ok)
{
	eins_InstallTemplateTbData($_GET);
}
elseif($enews=="defaultdata"&&$ok)
{
	eins_InstallDefaultData($_GET);
}
elseif($enews=="firstadmin"&&$ok)
{
	eins_FirstAdmin($_POST);
}
elseif($enews=="changetbpgsql"&&$ok)
{
	eins_InstallChangeTbPgsql($_GET);
}
else
{}

$shorttag=ini_get('short_open_tag');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>帝國網站管理系統安裝程序 - Powered by EmpireCMS</title>

<link href="images/css.css" rel="stylesheet" type="text/css">
</head>

<body bgcolor="#C9F1FF" leftmargin="0" topmargin="0">
<?php
if(!$shorttag)
{
?>
<br>
<br><br>
<table width="500" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
  <tr> 
    <td height="25" class="header"><div align="center"><strong><font color="#FFFFFF">錯誤提示</font></strong></div></td>
  </tr>
  <tr> 
    <td height="25" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="1" cellpadding="3">
        <tr>
          <td height="25">您的PHP配置文件php.ini配置有問題，請按下面操作即可解決：</td>
        </tr>
        <tr>
          <td height="25">1、修改php.ini，將：short_open_tag 設為 On</td>
        </tr>
        <tr>
          <td height="25">2、修改後重啟apache/iis方能生效。</td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<?php
	echo"</body></html>";
	exit();
}
?>
<table width="776" height="100%" border="0" align="center" cellpadding="6" cellspacing="0" bgcolor="#FFFFFF">
  <tr> 
    <td height="56" colspan="2" background="images/topbg.gif"> 
      <div align="center">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="80%"><div align="center"><img src="images/installsay.gif" width="500" height="50"></div></td>
            <td width="20%" valign="bottom"><font color="#FFFFFF">最後更新: <?php echo EmpireCMS_LASTTIME;?></font></td>
          </tr>
        </table>
        
      </div></td>
  </tr>
  <tr> 
    <td width="21%" rowspan="3" valign="top">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td><div align="center"><a href="http://www.phome.net" target="_blank"><img src="images/logo.gif" width="170" height="72" border="0"></a></div></td>
        </tr>
      </table>
      <br> 
	  <table width="100%" border="0" cellpadding="3" cellspacing="1" class="tableborder">
        <tr class="header"> 
          <td height="25" colspan="2"> <div align="left"><strong><font color="#FFFFFF">版權信息</font></strong></div></td>
        </tr>
        <tr bgcolor="#FFFFFF"> 
          <td width="34%" height="25">軟件名稱</td>
          <td width="66%" height="25">帝國網站管理系統</td>
        </tr>
        <tr bgcolor="#FFFFFF">
          <td height="25">英文名稱</td>
          <td height="25">EmpireCMS</td>
        </tr>
        <tr bgcolor="#FFFFFF"> 
          <td height="25">程序版本</td>
          <td height="25">Version 8.0 </td>
        </tr>
        <tr bgcolor="#FFFFFF"> 
          <td height="25">開發團隊</td>
          <td height="25">帝國軟件開發團隊</td>
        </tr>
        <tr bgcolor="#FFFFFF"> 
          <td height="25">公司名稱</td>
          <td height="25">漳州市薌城帝興軟件開發有限公司</td>
        </tr>
        <tr bgcolor="#FFFFFF"> 
          <td height="25">官方網站</td>
          <td height="25"><a href="http://www.PHome.Net" target="_blank">www.PHome.Net</a></td>
        </tr>
      </table>
      <br> 
	  <table width="100%" border="0" cellpadding="3" cellspacing="1" class="tableborder">
        <tr class="header"> 
          <td height="25"><strong><font color="#FFFFFF">安裝進程</font></strong></td>
        </tr>
        <tr> 
          <td bgcolor="#FFFFFF"> <table width="100%" border="0" cellspacing="1" cellpadding="3">
              <tr> 
                <td><img src="images/noadd.gif" width="15" height="15">&nbsp;<font color="<?php echo $f==1?'#FF0000':'#000000';?>">閱讀用戶使用條款</font></td>
              </tr>
              <tr> 
                <td><img src="images/noadd.gif" width="15" height="15">&nbsp;<font color="<?php echo $f==2?'#FF0000':'#000000';?>">檢測運行環境</font></td>
              </tr>
              <tr> 
                <td><img src="images/noadd.gif" width="15" height="15">&nbsp;<font color="<?php echo $f==3?'#FF0000':'#000000';?>">設置目錄權限</font></td>
              </tr>
			  <tr> 
                <td><img src="images/noadd.gif" width="15" height="15">&nbsp;<font color="<?php echo $f==4?'#FF0000':'#000000';?>">選擇數據庫類型</font></td>
              </tr>
              <tr> 
                <td><img src="images/noadd.gif" width="15" height="15">&nbsp;<font color="<?php echo $f==5?'#FF0000':'#000000';?>">配置數據庫</font></td>
              </tr>
              <tr> 
                <td><img src="images/noadd.gif" width="15" height="15">&nbsp;<font color="<?php echo $f==6?'#FF0000':'#000000';?>">初始化管理員賬號</font></td>
              </tr>
              <tr> 
                <td><img src="images/noadd.gif" width="15" height="15">&nbsp;<font color="<?php echo $f==7?'#FF0000':'#000000';?>">安裝完畢</font></td>
              </tr>
            </table></td>
        </tr>
      </table></td>
    <td><div align="center"><strong><font color="#0000FF" size="3">想到即可做到 - 帝國網站管理系統</font></strong></div></td>
  </tr>
  <tr> 
    <td valign="top"> 
    <?php
	if($enews=="ckere")//運行環境
	{
		include('page/eins_ere.php');
	}
	elseif($enews=="ckpath")//設置目錄權限
	{
		include('page/eins_ckpath.php');
	}
	elseif($enews=="chdbtype")//選擇數據庫類型
	{
		include('page/eins_chdbtype.php');
	}
	elseif($enews=="setdb")//配置數據庫
	{
		$mycookievarpre=strtolower(eins_InstallMakePassword(5));
		$myadmincookievarpre=strtolower(eins_InstallMakePassword(5));
		include('page/eins_setdb.php');
	}
	elseif($enews=="firstadmin")//初使化管理員
	{
		include('page/eins_firstadmin.php');
	}
	elseif($enews=="success")//安裝完畢
	{
		//鎖定安裝程序
		$fp=@fopen("../../c/einstall/install.off","wb");
		@fclose($fp);
		$word='恭喜您！您已成功安裝帝國網站管理系統．';
		if($_GET['defaultdata'])
		{
			$word='恭喜您！您已成功安裝帝國網站管理系統．<br>請繼續操作初始化內置數據(看安裝說明第三大步)。';
		}
		include('page/eins_success.php');
	}
	else//用戶條款
	{
		include('page/eins_readme.php');
	}
	?>
    </td>
  </tr>
  <tr> 
    <td valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td><hr align="center"></td>
        </tr>
        <tr> 
          <td height="25"><div align="center"><a href="http://www.PHome.Net" target="_blank">官方網站</a>&nbsp; 
              | &nbsp;<a href="http://www.phome.net/support/" target="_blank">技術支持</a>&nbsp; 
              | &nbsp;<a href="http://www.phome.net/case/" target="_blank">部分案例</a>&nbsp; 
              | &nbsp;<a href="http://www.phome.net/ecmssay/" target="_blank">系統特性</a>&nbsp; 
              | &nbsp;<a href="http://www.phome.net/template/" target="_blank">模板下載</a>&nbsp; 
              | &nbsp;<a href="http://www.phome.net/docs/" target="_blank">教程下載</a>&nbsp; 
              | &nbsp;<a href="http://www.phome.net/service/about.html" target="_blank">關於帝國</a></div></td>
        </tr>
        <tr> 
          <td height="36"> <div align="center">帝興軟件開發有限公司 版權所有<BR>
              <font face="Arial, Helvetica, sans-serif">Copyright &copy; 2002 
              - 2025<b> <a href="http://www.PHome.net"><font color="#000000">PHome</font><font color="#FF6600">.Net</font></a></b></font></div></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>