<%@ page language="java" contentType="text/html;charset=Shift_JIS"%>
<%@ page import = "java.util.*"%>
<%@ page import = "java.sql.*"%>

<%@ include file="../../connect.jsp"%>
<%
/*
Connection connMeta = null;
Statement stmt = null;
Statement stmt2 = null;
Statement stmt3 = null;
ResultSet rs = null;
ResultSet rs2 = null;
ResultSet rs3 = null;
connMeta = (Connection)session.getValue(session.getId()+"Conn");
stmt     = (Statement) session.getValue(session.getId()+"Stmt");
stmt2     = (Statement) session.getValue(session.getId()+"Stmt2");
stmt3     = (Statement) session.getValue(session.getId()+"Stmt3");
*/
%>

<%



	String Sql="";
	String strKey=request.getParameter("key");
	String addFlg="";
	if(strKey.equals("-999")){
		addFlg="1";
	}else{
		addFlg="0";
	}
	
	String strReportName="";
	String strKindFlg="F";

	Sql = "SELECT update_date,report_name,kind_flg ";
	Sql = Sql + " FROM " + session.getValue("CustomTableName") + " WHERE report_id = " + strKey;
	rs = stmt.executeQuery(Sql);
	if(rs.next()) {
		strReportName=rs.getString("report_name");
		strKindFlg=rs.getString("kind_flg");
	}
	rs.close();


	if(addFlg.equals("1")){
		Sql = "SELECT NEXTVAL('" + session.getValue("CustomTableSequence") + "') AS new_seq";
		rs = stmt.executeQuery(Sql);
		if (rs.next()) {
			strKey=rs.getString("new_seq");
		}
		rs.close();
	}

	String strNow="";
	Sql = "SELECT to_char(NOW(),'YYYY/MM/DD') AS now";
	rs = stmt.executeQuery(Sql);
	if (rs.next()) {
		strNow=rs.getString("now");
	}
	rs.close();

%>

<html>
<head>
	<title>OpenOLAP Viewer</title>
	<meta http-equiv="Content-Type" content="text/html;charset=Shift_JIS">
	<link REL="stylesheet" TYPE="text/css" HREF="../../../css/common.css">
	<link rel="stylesheet" type="text/css" href="../../../css/member.css">
	<script language="JavaScript" src="../js/registration.js"></script>
</head>

<body class="sub" onload="changefocus()">
	<form id="form_main" method="post" name="form_main">
		<br>
		<br>
		名前： <input type='text' name='txt_report_name' value='<%=strReportName%>' size='30' maxlength='30' mON='名前'">
		<p>
		<br>
		<br>
		<input type = 'button' value='' onclick="regist();" class="normal_ok" onMouseOver="className='over_ok'" onMouseDown="className='down_ok'" onMouseUp="className='up_ok'" onMouseOut="className='out_ok'" >
		<input type = 'button' value='' onclick="cancel();" class="normal_cancel" onMouseOver="className='over_cancel'" onMouseDown="className='down_cancel'" onMouseUp="className='up_cancel'" onMouseOut="className='out_cancel'">
		<input type = 'hidden' name = 'hid_key' value='<%=strKey%>'>
	</form>
</body>
</html>

<script language="JavaScript">
var arrArg;


function changefocus(){

	arrArg = dialogArguments;

//	window.focus();
	document.form_main.txt_report_name.focus();
	document.form_main.txt_report_name.select();
}




function regist(){

		//共通エラーチェックを先に行う
		if(!checkData()){return;}

		if(showConfirm("CFM2",document.form_main.txt_report_name.value)){
			<%if(addFlg.equals("1")){%>//追加
			arrArg[0].SpreadForm.action = "../hidden/report_mng_tree_regist.jsp?opr=add&key=" + document.form_main.hid_key.value + "&par_key=" + arrArg[0].SpreadForm.hid_par_key.value + "&txt_report_name=" + document.form_main.txt_report_name.value;
			<%}else{%>//名前の変更
			arrArg[0].SpreadForm.action = "../hidden/report_mng_tree_regist.jsp?opr=rename&key=" + document.form_main.hid_key.value + "&par_key=" + arrArg[0].SpreadForm.hid_par_key.value + "&txt_report_name=" + document.form_main.txt_report_name.value;
			<%}%>
		//	arrArg[0].SpreadForm.target = arrArg[0].parentNode.parent.frames[0].name;
			arrArg[0].SpreadForm.target = "update_tree_frm";
			arrArg[0].SpreadForm.submit();
		}else{
			return;
		}





		<%if(addFlg.equals("1")){%>//追加
		var newRow = arrArg[0].getElementById("DataTable").rows[0].cloneNode(true);
		arrArg[0].getElementById("DataTable").childNodes[1].appendChild(newRow);
		var selectedRow = arrArg[0].getElementById("DataTable").childNodes[1].lastChild;
		selectedRow.style.display="block";
		selectedRow.id="<%=strKey%>";
		selectedRow.cells[0].firstChild.childNodes[1].innerHTML=document.form_main.txt_report_name.value;
		selectedRow.cells[1].firstChild.innerHTML="<%=strKey%>";
		if("<%=strKindFlg%>"=="F"){
			selectedRow.cells[2].firstChild.innerHTML="フォルダ";
		}else if("<%=strKindFlg%>"=="R"){
			selectedRow.cells[2].firstChild.innerHTML="レポート";
		}
		selectedRow.cells[3].firstChild.innerHTML="<%=strNow%>";

		//左側ツリーへメンバ追加
	//	arrArg[0].parentNode.parent.frames[1].addMember(document.form_main.txt_report_name.value,document.form_main.txt_report_name.value,<%=strKey%>);
		arrArg[1].addMember(document.form_main.txt_report_name.value,document.form_main.txt_report_name.value,<%=strKey%>);


		<%}else{%>//名前の変更
		var selectedRow = arrArg[0].getElementById("<%=strKey%>");
		selectedRow.cells[0].firstChild.childNodes[1].innerHTML=document.form_main.txt_report_name.value;
		selectedRow.cells[3].firstChild.innerHTML="<%=strNow%>";

		arrArg[1].renMember(<%=strKey%>,document.form_main.txt_report_name.value);

		<%}%>



		//Window Close
		self.window.close();


}

function cancel(){
	self.window.close();
}


</script>

<%@ include file="../../connect_close.jsp" %>
