<%@ page language="java" contentType="text/html;charset=Shift_JIS"%>
<%@ page import = "java.sql.*"%>
<%//@ include file="../../connect.jsp" %>
<%@ include file="../../connect.jsp" %>
<%
//request.setCharacterEncoding("Shift_JIS");
%>

<%
/*
Connection connMeta = null;
Statement stmt = null;
Statement stmt2 = null;
Statement stmt = 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");
stmt     = (Statement) session.getValue(session.getId()+"stmt");
*/
%>
<%
	String SQL = "";

	String parentRecord = "";
	String childRecord = "";
	int updateCount = 0;


	//処理種別
	String strOPR = request.getParameter("opr");


	if ( strOPR.equals("update") ) {

		// *********************************************************************
		// **** update ****
		// *********************************************************************
		if (request.getParameter("parent_record") == null) {
			return;
		}
		if (request.getParameter("child_record") == null) {
			return;
		}
		parentRecord = request.getParameter("parent_record");
		childRecord =  request.getParameter("child_record");
		if ( parentRecord.equals("") || childRecord.equals("") ) {
			return;
		}

		SQL = 		" update " + session.getValue("CustomTableName") + "";
		if ( parentRecord.equals("root") ) {
			SQL = SQL + " set par_id = null ";
		} else {
			SQL = SQL + " set par_id = " + parentRecord;
		}
		SQL = SQL + " ,update_date = NOW()";
		SQL = SQL + " where report_id in (" + childRecord + ")";

		updateCount = stmt.executeUpdate(SQL);

	} else if ( strOPR.equals("delete") ) {
		// *********************************************************************
		// **** delete ****
		// *********************************************************************
		SQL = " delete from " + session.getValue("CustomTableName") + "";
		SQL = SQL + " where report_id in (" + request.getParameter("hid_delete_key") + ")";
		updateCount = stmt.executeUpdate(SQL);

		SQL = " delete from oo_v_axis";
		SQL = SQL + " where report_id in (" + request.getParameter("hid_delete_key") + ")";
		updateCount = stmt.executeUpdate(SQL);

		SQL = " delete from oo_v_axis_member";
		SQL = SQL + " where report_id in (" + request.getParameter("hid_delete_key") + ")";
		updateCount = stmt.executeUpdate(SQL);

		SQL = " delete from oo_v_color";
		SQL = SQL + " where report_id in (" + request.getParameter("hid_delete_key") + ")";
		updateCount = stmt.executeUpdate(SQL);

		SQL = " delete from oo_v_measure_member_type";
		SQL = SQL + " where report_id in (" + request.getParameter("hid_delete_key") + ")";
		updateCount = stmt.executeUpdate(SQL);

	} else if ( strOPR.equals("rename") ) {
		// *********************************************************************
		// **** rename ****
		// *********************************************************************

		SQL = " update " + session.getValue("CustomTableName") + "";
		SQL = SQL + " set report_name = '" + request.getParameter("txt_report_name") + "'";
		SQL = SQL + " ,update_date = NOW()";
		SQL = SQL + " where report_id = " + request.getParameter("key");
		updateCount = stmt.executeUpdate(SQL);



	} else if ( strOPR.equals("add") ) {

		SQL = " insert into " + session.getValue("CustomTableName") + "(";
		SQL = SQL + " report_id            ";
		SQL = SQL + ",par_id        ";
		SQL = SQL + ",report_name";
		SQL = SQL + ",cube_seq";
		SQL = SQL + ",kind_flg";
		SQL = SQL + ",update_date";
		SQL = SQL + ") values (";
		SQL = SQL + "" + request.getParameter("key");
		if("root".equals(request.getParameter("par_key"))){
			SQL = SQL + ",NULL";
		}else{
			SQL = SQL + "," + request.getParameter("par_key");
		}
		SQL = SQL + ",'" + request.getParameter("txt_report_name") + "'";
		SQL = SQL + ",0";
		SQL = SQL + ",'F'";
		SQL = SQL + ",NOW()";
		SQL = SQL + ")";
		updateCount = stmt.executeUpdate(SQL);




	}

%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=Shift_JIS">
	<title>OpenOLAP Viewer</title>
	<script language="JavaScript" src="../js/registration.js"></script>
	<script language="javascript">
		function load(){
		//	setChangeFlg();//アクションごとにDBに反映されるので破棄メッセージは要らない
			location.replace("blank.jsp");
		}
	</script>
</head>
<body onload="load()">
<form id="update_form" method="post" name="update_form" target="right"> 
<input type="hidden" name = "preClick"/>
<%=SQL + "<BR>"%>
<%=strOPR + "<BR>"%>
<%=updateCount + "<BR>"%>
</form>
</body>
</html>
<%@ include file="../../connect_close.jsp" %>
