<%@ page contentType="text/html; charset=UTF-8" language="java" errorPage="" %>
<%@ page import="tot.global.ConfigModule" %>
<%@ page import="tot.db.DBUtils" %>
<%@ page import="tot.search.ArticleIndex"%>
<%@ page import="java.sql.*" %>
<%@ include file="inc/common.jsp"%>
<!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>
<meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8">
<title>淘特站内搜索引擎--安装</title>
<link href="style/global.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
.style2 {
	color: #FFFFFF;
	font-weight: bold;
	font-size: 14px;
}
-->
</style>
</head>
<body>
<%
String act=RequestUtil.getString(request,"act");
String stsfile=request.getRealPath("/")+"install.txt";
String isinstall=FileUtil.readFile(stsfile,"UTF-8");
if(isinstall!=null && isinstall.equals("yes")){
	out.print("<p align=\"center\">已安装过了!</p>");
	out.print("<p align=\"center\"><a href=\"/admin/\">点此登录后台!</a></p>");
	return;
}
if(act!=null && act.equals("do")){	
	ConfigModule cfg=new ConfigModule();
	cfg.updateConfig(request);
	Sysconfig.load();		
	Connection conn = null;
	out.print("<table align=\"center\"><tr><td height=\"500\">");
	try{
		conn = DBUtils.getConnection();
		if(conn!=null){
			out.print("<h2>Success!安装成功</h2>");
			out.print("<p align=\"center\"><a href=\"/admin/\">点此登录后台!</a></p>");
			FileUtil.createFile("yes",stsfile,"UTF-8");
			ArticleIndex.scheduleCreateEmptyIndexTask();
		}else{
			out.print("<h2>数据库连接失败，请检查数据库相关参数！</h2>");
		}
	} catch(SQLException e){
		out.print("<h2>数据库连接失败，请检查数据库相关参数！</h2>");
	} finally{
		DBUtils.closeConnection(conn);
	}
	out.print("</td></tr></table>");
}else{	
%>
<br />
<form id="addGroup" name="addGroup" method="post" action="?act=do" style="margin:0px; padding:0px;">
<table width="98%" height="25" border="0" align="center" cellpadding="2" cellspacing="0" class="black_border">
  <tr>
    <td height="25" colspan="2" bgcolor="#3872b2"><div align="center" class="style1"><strong>淘特站内搜索引擎--安装</strong></div></td>
    </tr>
</table>
<table width="980" height="25" border="0" align="center" cellpadding="2" cellspacing="0" class="black_border">
  <tr>
    <td bgcolor="#FDFDFD">&nbsp;</td>
    <td height="32" bgcolor="#FDFDFD"><strong>数据库配置</strong></td>
  </tr>
  <tr>
    <td width="31%" height="32" valign="top" bgcolor="#FDFDFD"><div align="right">数据库URL：</div></td>
    <td width="69%" valign="top" bgcolor="#FDFDFD"><div align="left" style="line-height:20px;">
      <input name="database_url" type="text" id="database_url" maxlength="250" value="<%=Sysconfig.getDatabaseURL()%>" style="width:90%; border:1px solid #666666;" />
      <br />
      <span class="gray">提示：以上是连接数据库的URL，其中127.0.0.1为数据库服务器地址，totcms为库名称，请根据您的情况自行调整。<br />
      默认编码是utf-8，如果您是gbk编码，请将utf-8改为gbk</span>。</div></td>
  </tr>
  <tr>
    <td height="32" bgcolor="#FDFDFD"><div align="right">用户名：</div></td>
    <td bgcolor="#FDFDFD"><div align="left">
      <input name="database_user" type="text" id="database_user" maxlength="250" value="<%=Sysconfig.getDatabaseUser()%>" style="width:200px; border:1px solid #666666;" />
      <span class="gray">连接数据库用户名</span></div></td>
  </tr>
  <tr>
    <td height="32" bgcolor="#FDFDFD"><div align="right">密码：</div></td>
    <td bgcolor="#FDFDFD"><div align="left">
      <input name="database_password" type="text" id="database_password" maxlength="250" value="<%=Sysconfig.getDatabasePassword()%>" style="width:200px; border:1px solid #666666;" />
      <span class="gray">连接数据密码</span></div></td>
  </tr>
  <tr>
    <td bgcolor="#FDFDFD">&nbsp;</td>
    <td height="32" bgcolor="#FDFDFD"><strong>索引配置</strong></td>
  </tr>
  <tr>
    <td width="31%" bgcolor="#FDFDFD"><div align="right">索引文件保存路径：</div></td>
    <td width="69%" bgcolor="#FDFDFD"><div align="left">
      <input name="indexdir" type="text" id="indexdir" maxlength="250" value="<%=Sysconfig.getIndexDir()%>" style="width:200px; border:1px solid #666666;" />
      <span class="gray">用于存放索引文件的目录</span></div></td>
</tr>  
  <tr>
    <td bgcolor="#FDFDFD">&nbsp;</td>
    <td height="32" bgcolor="#FDFDFD"><strong>管理员帐号</strong></td>
  </tr>
  <tr>
    <td width="31%" height="32" bgcolor="#FDFDFD"><div align="right">用户名：</div></td>
    <td width="69%" bgcolor="#FDFDFD"><div align="left">
      <input name="username" type="text" id="username" maxlength="250" value="<%=Sysconfig.getUserName()%>" style="width:200px; border:1px solid #666666;" />
      <span class="gray">后台登录帐号</span></div></td>
</tr> 
<tr>
    <td width="31%" height="32" bgcolor="#FDFDFD"><div align="right">密 码：</div></td>
    <td width="69%" bgcolor="#FDFDFD"><div align="left">
      <input name="password" type="text" id="password" maxlength="250" value="<%=Sysconfig.getPassword()%>" style="width:200px; border:1px solid #666666;" />
      <span class="gray">后台登录密码</span></div></td>
</tr>  
<tr>
    <td width="31%" bgcolor="#FDFDFD"><div align="right">网站域名(Url)：</div></td>
    <td width="69%" bgcolor="#FDFDFD"><div align="left">
      <input name="siteurl" type="text" id="siteurl" maxlength="250" value="<%=Sysconfig.getSiteUrl()%>" style="width:200px; border:1px solid #666666;" />
      <span class="gray">帝国Cms安装的域名地址</span></div></td>
</tr>
</table>
<table width="980" height="25" border="0" align="center" cellpadding="2" cellspacing="0" class="black_border" style="display:block">
<tr>
  <td width="298" bgcolor="#FDFDFD">&nbsp;</td>
    <td width="674" height="35" colspan="2" bgcolor="#FDFDFD"><div align="left">
      <input name="database_type" type="hidden" id="database_type" maxlength="250" value="<%=Sysconfig.getDatabaseType()%>" />
      <input name="use_datasource" type="hidden" id="use_datasource" maxlength="250" value="<%=Sysconfig.isUseDataSource()%>" />
      <input name="datasource_name" type="hidden" id="datasource_name" maxlength="250" value="<%=Sysconfig.getDataSourceName()%>" />
      <input name="driver_class_name" type="hidden" id="driver_class_name" maxlength="250" value="<%=Sysconfig.getDriverClassName()%>" />
      <input name="lucene_analyzer_implementation" type="hidden" id="lucene_analyzer_implementation" maxlength="250" value="<%=Sysconfig.getLuceneAnalyzerClassName()%>" />
      <input name="max_connection" type="hidden" id="max_connection" maxlength="250" value="<%=Sysconfig.getMaxConnection()%>" />
      <input name="max_time_to_wait" type="hidden" id="max_time_to_wait" maxlength="250" value="<%=Sysconfig.getMaxTimeToWait()%>" />
      <input name="minutes_between_refresh" type="hidden" id="minutes_between_refresh" maxlength="250" value="<%=Sysconfig.getMinutesBetweenRefresh()%>" />
      <input type="hidden" name="blocked_ip" value="<%=Sysconfig.getBlockedIPs()%>"  />
      <input name="server_hour_offset" type="hidden" id="server_hour_offset" maxlength="250" value="<%=Sysconfig.getServerHourOffset()%>" style="width:200px; border:1px solid #666666;" />
      <input type="submit" name="Submit" value="开始安装" />
    </div></td>
    </tr>
</table>
</form>
<%
}
%>
</body>
</html>
