<%@ page language="java" contentType="text/html;charset=Shift_JIS"%> 
<%@ page import="openolap.viewer.User"%> 
<%
out.println("<?xml version=\"1.0\" encoding=\"Shift-JIS\"?>");
out.println("<?xml:stylesheet type=\"text/xsl\" href=\"tree.xsl\"?>");
%>
<%@ include file="connect.jsp" %>
<%




// Common Variables
String SQL;
String closeTag="";
String preRecordData="";
%>
<OpenOlap ID='OpenOlap'>OpenOlap
<ReportTop ID='ReportTop'>レポート
<%
/*
	SQL = 		" SELECT DISTINCT";
	SQL = SQL + " folder_id, ";
	SQL = SQL + " folder_name ";
	SQL = SQL + " FROM oo_v_folder ";
	SQL = SQL + " order by folder_id";
	rs = stmt.executeQuery(SQL);
	while (rs.next()) {
		out.println("<Folder ID='" + rs.getString("folder_id") + "'>" + rs.getString("folder_name"));

		SQL = 		" SELECT DISTINCT";
		SQL = SQL + " report_id, ";
		SQL = SQL + " report_name ";
		SQL = SQL + " FROM oo_v_report ";
		SQL = SQL + " order by report_id";
		rs2 = stmt2.executeQuery(SQL);
		while (rs2.next()) {
			out.println("<Report ID='" + rs2.getString("report_id") + "'>" + rs2.getString("report_name"));
			out.println("</Report>");
		}
		rs2.close();

		out.println("</Folder>");

	}
	rs.close();
*/

%>


<%
String dimSeq="43";
String objSeq="2";


	int maxLevel=0;
	SQL = "SELECT max(level_no) as maxLevel FROM oo_level WHERE dimension_seq = " + dimSeq;
	rs = stmt.executeQuery(SQL);
	if(rs.next()) {
		maxLevel=rs.getInt("maxLevel");
	}
	rs.close();


//	SQL = "SELECT key,level,leaf_flg,code,short_name,long_name,CASE WHEN org_level = " + maxLevel + " THEN 'F' WHEN org_level = 0 THEN 'V' ELSE 'D' END AS kind FROM oo_dim_tree('oo_dim_" + dimSeq +"_" + objSeq + "',null,null)";
//	SQL = SQL + " WHERE org_level <> " + maxLevel;

	SQL = "SELECT report_id,level,report_name,kind_flg as kind FROM oo_report_tree('oo_v_report',null,null)";
	rs = stmt.executeQuery(SQL);


	int BeforeLevel=0;
	while(rs.next()) {
		for(int j=BeforeLevel;j>=rs.getInt("level");j--){
			out.println("</category>");
		}
		out.println("<category ID='" + rs.getString("report_id") + "' KI='" + rs.getString("kind") + "'>" + rs.getString("report_name") + "");
		BeforeLevel=rs.getInt("level");
	}
	rs.close();

	for(int j=BeforeLevel;j>0;j--){
		out.println("</category>");
	}

%>
</ReportTop>


<%
//管理者認証
User user = (User)session.getAttribute("user");
boolean isAdmin = user.isAdmin();
//boolean isAdmin = false;
if(isAdmin){
%>
<Admin ID='Admin'>管理
	<CreateReport ID='CreateReport'>レポート新規作成</CreateReport>
	<AdminFolderReport ID='AdminFolderReport'>フォルダ・レポート管理</AdminFolderReport>
</Admin>
<%}%>


</OpenOlap>



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