<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="java.sql.DriverManager"%>
<%@include file="/inc/init.jsp"%>
<%@page import="java.sql.Connection"%>
<%@page import="javax.naming.Context"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%
if(ConfigUtil.isInstalled){
	out.print("已经安装完成，无须再次安装！");
	return;
}else{
	response.setHeader("Cache-Control", "no-cache"); //HTTP   1.1   
	response.setHeader("Pragma", "no-cache"); //HTTP   1.0   
	response.setDateHeader("Expires", 0);
	String host = pu.getString("host");
	String dbuser = pu.getString("dbuser");
	String dbpwd = pu.getString("dbpwd");
	String basedb = pu.getString("basedb");
	String adminname = pu.getString("adminname");
	String adminpwd = pu.getString("adminpwd");
	String action = pu.getString("action");
	if (action.equals("conn")) {
		String[] strs=new String[]{host,dbuser,basedb};
		if(!StringUtil.isFine(strs)){
			out.print("请填写完整的数据库资料再测试连接！");
			return;
		}
		//连接池的获取  
		Install_db idb = new Install_db();
		boolean isok = idb.isconn(host, basedb, dbuser, dbpwd);
		if (isok) {
			out.println("1"); //已经获得无连接池的数据库!
		} else {
			out.println("0"); //无法连接数据，请检查数据库是否已经创建或者数据配置是否正确!
		}
		return;
		//获取连接结束
	} else if (action.equals("install")) {
		Install_db idb = new Install_db();
		String[] strs=new String[]{host,dbuser,basedb,adminname,adminpwd};
		if(!StringUtil.isFine(strs)){
			out.print("请填写完整的资料再安装！");
			return;
		}
		boolean isok = idb.isconn(host, basedb, dbuser, dbpwd);
		if (isok) {
			String rstr = idb.installAll(host,dbuser,dbpwd,basedb, adminname, adminpwd,
					pu.getIpAddr(),pu);
			out.print(rstr);//输出结果
		} else {
			out.print("无法连接数据，请检查配置是否正确!");
		}
	}
}
%>