<%@ include file="validate.jsp" %>
<%@ page language="java" contentType="text/html; charset=GBK" import="cn.sendsms.jdsmsserver.web.*"
    pageEncoding="GBK"%>
    <%@ page import="cn.sendsms.jdsmsserver.*"%>
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragrma","no-cache");
response.setDateHeader("Expires",0);
%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title><%
		out.println(ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_setting"));
	%></title>
<link href="css.css" type="text/css" rel="stylesheet">
<script type="text/javascript">

function testConnection()
{	
	
	if(document.getElementById('type').value == "oracle-rac"){

		var array=document.getElementsByName('datasource.update_outbound_on_statusreport');

		var url="/datasource-config?action=test&datasource.type="+document.getElementById('type').value+
		"&datasource.username="+document.getElementById('username').value+
		"&datasource.racurl="+document.getElementById('racurl').value+
		"&datasource.password="+encodeURIComponent(document.getElementById('password').value)+
		"&datasource.batch_size="+document.getElementById('batch_size').value+
		"&datasource.retries="+document.getElementById('retries').value+
		"&datasource.update_outbound_on_statusreport=";
		if(array[0].checked)
			url+=array[0].value;
		else url+=array[1].value;

		window.location.href=url;
	}else{

		var array=document.getElementsByName('datasource.update_outbound_on_statusreport');
		var url="/datasource-config?action=test&datasource.type="+document.getElementById('type').value+"&datasource.ip="+document.getElementById('ip').value+"&datasource.port="+document.getElementById('port').value+
		"&datasource.username="+document.getElementById('username').value+"&datasource.password="+encodeURIComponent(document.getElementById('password').value)+
		"&datasource.databaseName="+document.getElementById('databaseName').value+
		"&datasource.batch_size="+document.getElementById('batch_size').value+
		"&datasource.retries="+document.getElementById('retries').value+
		"&datasource.update_outbound_on_statusreport=";
		if(array[0].checked)
			url+=array[0].value;
		else url+=array[1].value;

		window.location.href=url;
	}

}
function initDatabase()
{
		
		if (document.getElementById('type').value == "oracle-rac") {

			var racurl = document.getElementById('racurl').value.trim();
			
			var array = document
					.getElementsByName('datasource.update_outbound_on_statusreport');
			var url = "/datasource-config?action=initDatabase&datasource.type="
					+ document.getElementById('type').value
					+ "&datasource.racurl="+racurl
					
					+ "&datasource.username="
					+ document.getElementById('username').value
					+ "&datasource.password="
					+ encodeURIComponent(document.getElementById('password').value)
					+ "&datasource.batch_size="
					+ document.getElementById('batch_size').value
					+ "&datasource.retries="
					+ document.getElementById('retries').value
					+ "&datasource.update_outbound_on_statusreport=";

			if (array[0].checked)
				url += array[0].value;
			else
				url += array[1].value;

			window.location.href = url;
		} else {
			
			var array = document
					.getElementsByName('datasource.update_outbound_on_statusreport');
			var url = "/datasource-config?action=initDatabase&datasource.type="
					+ document.getElementById('type').value
					+ "&datasource.ip="
					+ document.getElementById('ip').value
					+ "&datasource.port="
					+ document.getElementById('port').value
					+ "&datasource.username="
					+ document.getElementById('username').value
					+ "&datasource.password="
					+ encodeURIComponent(document.getElementById('password').value)
					+ "&datasource.databaseName="
					+ document.getElementById('databaseName').value
					+ "&datasource.batch_size="
					+ document.getElementById('batch_size').value
					+ "&datasource.retries="
					+ document.getElementById('retries').value
					+ "&datasource.update_outbound_on_statusreport=";

			if (array[0].checked)
				url += array[0].value;
			else
				url += array[1].value;

			window.location.href = url;
		}

	}
	function typechange(obj) {
		var index = obj.selectedIndex;
		var type = obj.options[index].value;

		if(type == 'mysql' || type == 'mysql8'){

		}
		var port = document.getElementById("port");
		if (type == 'mysql'||type == 'mysql8') {
			//port.value='3306';

			url = "/datasource-config?action=Init&datasource.type=" + type
					+ "&datasource.port=3306";
			window.location.href = url;
		}
		if (type == 'mssql2000' || type == 'mssql2005-2017') {
			//port.value='1433';
			url = "/datasource-config?action=Init&datasource.type=mssql&datasource.port=1433&datasource.mstype="
					+ type;
			window.location.href = url;
		}
		if (type == 'oracle') {
			//port.value='1521';

			url = "/datasource-config?action=Init&datasource.type=" + type
					+ "&datasource.port=1521";
			window.location.href = url;
		}
		if (type == 'postgresql') {

			//port.value='5432';
			url = "/datasource-config?action=Init&datasource.type=" + type
					+ "&datasource.port=5432";
			window.location.href = url;
		}
		if (type == 'oracle-rac') {

			//to do something

			url = "/datasource-config?action=Init&datasource.type=" + type;
			window.location.href = url;
		}
		if(type=='Dm7') {
			url = "/datasource-config?action=Init&datasource.type=" + type
				+ "&datasource.port=5236";
			window.location.href = url;
		}
		if(type=='OSCAR7') {
			url = "/datasource-config?action=Init&datasource.type=" + type
				+ "&datasource.port=2003";
			window.location.href = url;
		}
		if(type=='KINGBASE8') {
			url = "/datasource-config?action=Init&datasource.type=" + type
				+ "&datasource.port=54321";
			window.location.href = url;
		}
		if(type=='GBASE8A') {
			url = "/datasource-config?action=Init&datasource.type=" + type
				+ "&datasource.port=5258";
			window.location.href = url;
		}

	}
	function chongzhi() {
		//alert("here");
		window.location.href = "/datasource-config?action=Init";
	}

</script>
<script type="text/javascript">
	window.onload = function(){
		document.addEventListener("submit",function(e){
			return true;
		});

		var type = document.getElementById('type').value;
		var iname = document.getElementById('user');
		iname.innerHTML = "";
		var rname = "";
		
		if(type == "mysql" || type == "mysql8" || type == "postgresql"){
			rname = "<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_user")%>";
		}else{
			rname = "<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_user1")%>";
		}

		iname.innerHTML = rname;
	}
	
</script>
<style type="text/css">
	#table{
		box-shadow: none;
	}
	#table table{
		margin-left:50px;
		margin-top:50px;
		font-size: 14px;
	}
	#table table tr{
		border:none;
	}
	#table table tr th{
		text-align: right;
		background: #fff;
		padding:5px 0px;
	}
	select{
		height: 28px;
		width:174px;
		padding:0px 5px 0px;
	}
	input{
		height:24px;
		width:160px;
		padding:0px 5px 0px;
		line-height: 24px;
	}
	input[type='radio']{
		width:auto;
		height:auto;
		margin:0px 5px;
	}
	input[type='button']{
		width:auto;margin-left:15px;height:28px;line-height: 28px;padding:0px 10px;border:1px solid #9cc0c1;border-radius:5px;color:#5db3b6;background: #fff;font-size: 13px;font-weight: 500;
	}

	/*#modal_frame{
		width:100%;
		height:100%;
		position: absolute;
		top:0;
		background: #ccc;
		opacity: 0.5;
		margin-left:-15px;
	}*/
</style>
<!-- <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script> -->

</head>
<body>
<%
	DataSourceBean bean =(DataSourceBean) request.getAttribute("datasource");
	if(bean == null)bean = new DataSourceBean();
%>

<div id="top"><span><img src="img/tu1.jpg"></span><%
		out.println(ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_setting"));
	%></div>
<div id="center">
	<!-- <div id="modal_frame">&nbsp;</div> -->
<form id="form_db"action="/datasource-config" style="margin-top:-30px;">
<input type="hidden" name="action" id="action" value="save">
<input type="hidden" name="datasource.interfaceid" id="interfaceid" value="<%=bean.getInterfaceid()%>">
<input type="hidden" name="datasource.infid" id="infid" value="<%=bean.getInfid()%>">
<div id="table">
<table  border="0" cellpadding="0" cellspacing="0" >
<tr>
<th><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_type")%></th>
<td>
<select name="datasource.type" id="type" onchange="typechange(this);">
		<option value="mysql" <%if(bean.getType().equalsIgnoreCase("mysql")) %>selected<%; %>>MySQL</option>
		<option value="mysql8" <%if(bean.getType().equalsIgnoreCase("mysql8")) %>selected<%; %>>MySQL8</option>
		<option value="mssql2000" <%if(bean.getType().equalsIgnoreCase("mssql")&&bean.getMssqltype().equalsIgnoreCase("mssql2000")) %>selected<%; %>>SQL Server 2000</option>
		<option value="mssql2005-2017" <%if(bean.getType().equalsIgnoreCase("mssql")&&bean.getMssqltype().equalsIgnoreCase("mssql2005-2017")) %>selected<%; %>>SQL Server 2005-2017</option>
		<option value="oracle" <%if(bean.getType().equalsIgnoreCase("oracle")) %>selected<%; %>>Oracle</option>
		<option value="postgresql" <%if(bean.getType().equalsIgnoreCase("postgresql")) %>selected<%; %>>PostgreSQL</option>
		<option value="oracle-rac" <%if(bean.getType().equalsIgnoreCase("oracle-rac")) %>selected<%; %>>OracleRAC</option>
		<option value="Dm7" <%if(bean.getType().equalsIgnoreCase("Dm7")) %>selected<%; %>>Dm7</option>
		<option value="OSCAR7" <%if(bean.getType().equalsIgnoreCase("OSCAR7")) %>selected<%; %>>OSCAR7</option>
		<option value="KINGBASE8" <%if(bean.getType().equalsIgnoreCase("KINGBASE8")) %>selected<%; %>>KINGBASE8</option>
		<option value="GBASE8A" <%if(bean.getType().equalsIgnoreCase("GBASE8A")) %>selected<%; %>>GBASE8A</option>
</select>

</tr>
<% if(!bean.getType().equalsIgnoreCase("oracle-rac")){ %>
<tr>
<th><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_ip")%></th>
<td><input type="text" name="datasource.ip" id="ip" size="20" maxlength="30" value="<%=bean.getIp()%>"></td>
</tr>
<tr>
<th><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_port")%></th>
<td><input type="text" name="datasource.port" id="port" size="20" maxlength="30" value="<%=bean.getPort()%>"></td>
</tr>
<%} %>

<tr>
<th><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_user")%></th>
<td><input type="text" name="datasource.username" id="username" size="20" maxlength="30" value="<%=bean.getUsername()%>"></td>


</tr>
<% if(!bean.getType().equalsIgnoreCase("oracle-rac")){ %>
<tr>
<th><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_psw")%></th>
<td><input type="password" name="datasource.password" id="password" size="21" maxlength="30" value=""><input type="button"  value=<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_test")%> onclick="testConnection()" ></td>

</tr>
<tr>
<th><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_name")%></th>
<td><input type="text" name="datasource.databaseName" id="databaseName" size="20" maxlength="30" value="<%=bean.getDatabaseName()%>"><input type="button"  value=<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_init")%> onclick="initDatabase()" ></td>
</tr>
<%} %>
<% if(bean.getType().equalsIgnoreCase("oracle-rac")){ %>
<tr>
<th><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_psw")%></th>
<td><input type="password" name="datasource.password" id="password" size="21" maxlength="30" value=""><input type="button" value=<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_test")%> onclick="testConnection()" > <input type="button" value=<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_init")%> onclick="initDatabase()" ></td>

</tr>
<tr>
	<th ><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_database_clustering_url")%></a></th>
	<td ><textarea rows="5" cols="50" name="racurl" id="racurl" style="border:1px solid #c1c1c1"><%=bean.getUrlRac()%></textarea></td>
</tr>
<%} %>
<th><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_processing_amount_each_time")%></th>
<td><input type="text" name="datasource.batch_size" id="batch_size" size="20" maxlength="30" value="<%=bean.getBatch_size()%>">
</tr>
<tr>
<th><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_retry_attempts")%></th>
<td><input type="text" name="datasource.retries" id="retries" size="20" maxlength="30" value="<%=bean.getRetries()%>">
</tr>
<tr>
<th><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_acknowledgement_of_receipt")%></th>
<td>
<label>
	<input type="radio" name="datasource.update_outbound_on_statusreport" id="update_outbound_on_statusreport" value="yes" <%if(bean.getUpdate_outbound_on_statusreport().equals("yes"))out.print("checked"); %>><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_needed")%>
</label>
	
<label style="margin-left:52px;">
	<input type="radio" name="datasource.update_outbound_on_statusreport" id="update_outbound_on_statusreport" value="no" <%if(bean.getUpdate_outbound_on_statusreport().equals("no"))out.print("checked"); %>><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_not_needed")%>
</label>

</tr>
<tr>
<td colspan="2" align="center"><input type="submit" style="width:121px;margin-left:15px;height:30px;line-height: 30px;border:1px solid #9cc0c1;border-radius:5px;background: #5db3b6;color:#fff;font-size: 13px;font-weight: 500;" value=<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_save")%> class="botton2">        <input type="button" style="width:121px;height:30px;line-height: 30px;" value=<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.db_reset")%> onclick="chongzhi()" class="botton2"></td>
</tr>
</table>
<div>
</div>
</div>
</form>

<%
if(request.getAttribute("global_info")!=null&&request.getAttribute("global_info")!=""){	
%>

<script type="text/javascript">
try{
	if('<%=request.getAttribute("global_info")%>'){
	top.window.func.window.open_modal('<%=request.getAttribute("global_info")%>');
}
}catch(e){
	alert('<%=request.getAttribute("global_info")%>')
}

</script>

<%} %>
</body>

<script type="text/javascript">
	var p = "<%=bean.getPassword()%>";
	flag = false;
	var pas = document.getElementById('password');
	pas.value=p;
	pas.addEventListener("change",function(){
		flag = true;
		this.value=pas.value;
	});

</script>
</html>