
<%@page import="kr.co.kihyun.beans.user.HttpSSOLogin"%>
<%
/************************************************************@@
  * Program Name	: doc_list.jsp
  * Description		: /집계자/내문서함/등록함/문서 목록
  * Author			: 강원중
  * Create Date		: 2010.11.27
  * History			: 
@@************************************************************/
%>

<%@ page contentType="application/x-msexcel;charset=UTF-8"
    import="java.net.URLDecoder"
	import="kr.co.kihyun.lang.Encoder"
    import="kr.co.kihyun.lang.MString"
	import="kr.co.kihyun.lang.MLong"
	import="kr.co.kihyun.text.html.HtmlUtil"
	import="kr.co.kihyun.text.excel.Excel"
	import="kr.co.kihyun.text.html.TagFilter"
	import="kr.co.kihyun.lang.StringConverter"
	import="kr.co.kihyun.moumi.Moumi"
	import="kr.co.kihyun.moumi.report.MReport"
	import="kr.co.kihyun.moumi.report.SaveReport"
	import="kr.co.kihyun.beans.user.UserView"
	import="kr.co.kihyun.beans.totsys.doc.table.item.ItemList"
	import="kr.co.kihyun.beans.totsys.report.ReportView"
	import="kr.co.kihyun.beans.totsys.report.ReportViewManager"
	import="kr.co.kihyun.beans.totsys.report.ReportFormElement"
	import="java.net.URLDecoder"
	import="java.net.URLEncoder"
	import="kr.co.kihyun.beans.totsys.report.tots.ReportsViewer"
	import="kr.co.kihyun.beans.totsys.doc.table.item.Item"
	import="kr.co.kihyun.lang.MInteger"
	import="kr.co.kihyun.beans.totsys.doc.table.Table"
	import="javax.jdo.PersistenceManager" import="javax.jdo.Transaction"
	import="kr.co.kihyun.beans.entity.util.*"
	import="kr.co.kihyun.beans.entity.*"%>

<%@ include file="/totsys/common/inc/sec/secure.inc.jsp"%>

<%
PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
Transaction tx = pm.currentTransaction();
try{

    /********** session내의 userId 추가분 **********/
	String usID = HttpSSOLogin.getLoginID(request);

   /********** parameter **********/
	String docID = clearXSS(MString.checkNull(request.getParameter("docID")),"");
	String partID = clearXSS(request.getParameter("partID"),"");
	int gradeCode = MInteger.parseInt(request.getParameter("gradeCode"), -1);
	int tableNum = MInteger.parseInt(request.getParameter("tableNum"), 0);
	int searchType = MInteger.parseInt(request.getParameter("searchType"), -1);
	String displaySummary = MString.checkNull(request.getParameter("displaySummary"));

        //String docName=URLDecoder.decode(request.getParameter("docName"),"UTF-8");
        //String docName=request.getParameter("docName");
        //String docName=URLEncoder.encode(request.getParameter("docName"),"UTF-8");
        String docName=URLDecoder.decode(request.getParameter("docName"));

	//response.setHeader("Accept-Ranges", "bytes");
	//response.setHeader("Content-Disposition","attachment; filename="+request.getParameter("docName").replaceAll(":","_").replace("+", "%20") +".xls;");
        //LJH
        //response.setHeader("Content-Disposition","attachment; filename="+request.getParameter("docName").replaceAll(":","_").replace("+", " ") +".xls;");    
        //response.setHeader("Content-Disposition","attachment; filename="+docName.replaceAll(":","_").replace("+", " ") +".hwp;");
        response.setHeader("Content-Disposition","attachment; filename="+docName.replaceAll(":","_").replace("+", " ") +".xls;");

     /***** 여기서부터 원래 소스 *****/
	Long reportID = MLong.parseLong(request.getParameter("reportID"),null);
	String saveExprType = clearXSS(MString.checkNull(request.getParameter("saveExprType")),"");   
    TotReport totReport = (TotReport)pm.getObjectById(TotReport.class, reportID);
	tx.begin();
    ReportViewManager reportViewManager=null;
            reportViewManager = new ReportViewManager(totReport.getTotDoc(), MReport.EXCEL);
            reportViewManager.setReportData(totReport.getDept(pm).getId(), totReport.getUser(pm).getId());
    tx.rollback();
	String report = reportViewManager.getReport();
	String docName2 = totReport.getTotDoc().getName();
	ReportFormElement reportFormElement = new ReportFormElement(totReport.getTotDoc());
	String Form = reportFormElement.getForm();
	ItemList itemTypes = reportFormElement.getItemList();
	int[] tmpItemTypeList = itemTypes.getTypeList();
	//report = TagFilter.removeFmla(report);  //엑셀 수식 사용안함
	//response.setHeader("Accept-Ranges", "bytes");
    //response.setHeader("Content-Disposition","attachment; filename="+(URLEncoder.encode(docName, "UTF-8")).replaceAll(":","_").replace("+"," " )+".xls;");
    //response.setHeader("Content-Disposition","attachment; filename="+docName.replaceAll(":","_").replace("+", " ") +".xls;"); 
%>
<html xmlns:o="urn:schemas-microsoft-com:office:office"
	xmlns:x="urn:schemas-microsoft-com:office:excel"
	xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type"
	content="text/html; charset=UTF-8">
<meta name="ProgId" content="Excel.Sheet">
<meta name="Generator" content="Microsoft Excel 10">
</head>
<body style=''>
<%if(totReport.getSlaveTotDoc() != null)
{
			//int gradeCode = MInteger.parseInt(request.getParameter("gradeCode"), -1);
			int reportCount = 0;
			ReportsViewer viewManager = new ReportsViewer(totReport.getSlaveTotDoc());
			boolean isAllDelete = false;
			int tableCount = new Table().getCount(totReport.getSlaveTotDoc().getId());
			Item item = new Item();
			int[] inRowCountList = item.getInRowCountList(totReport.getSlaveTotDoc().getId());
			int[] titleRowCountList = item.getTitleRowCountList(totReport.getSlaveTotDoc().getId());
			
		/********* report *********/
			viewManager.setReportDataAll(null, gradeCode);
	
			reportCount = viewManager.getReportsView().getCount();
			String[] repoPartNameList = viewManager.getReportsView().getPartNameList();
			String[] repoDeptNameList = viewManager.getReportsView().getDeptNameList();
			String[] reportList = viewManager.getReportNBSPList();
			String[] totalList = viewManager.getTotalReportNBSPList("save");
			String[] repoUserNameList = viewManager.getReportsView().getUserNameList();
			String[] locationList = viewManager.getReportsView().getLocationList();
			String[] gradeList = viewManager.getReportsView().getGradeList();
			String[] foundationList = viewManager.getReportsView().getFoundationList();
			Integer[] prssList = viewManager.getReportsView().getPrssList();
		%>
<table cellspacing="0" cellpadding="1" align="left" border="1">
	<tr>
		<td align="center"><%=Moumi.getMessageBundle().getString("moumi.message.tot_report.submit")%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.coporation")%></td>
		<td align="center"><%=Moumi.getMessageBundle().getString("moumi.message.tot_report.submit")%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.devision")%></td>
		<td align="center"><%=Moumi.getMessageBundle().getString("moumi.message.tot_report.submit")%><%=Moumi.getMessageBundle().getString("moumi.message.tot_report.area")%></td>
		<td align="center"><%=Moumi.getMessageBundle().getString("moumi.message.tot_report.level")%></td>
		<td align="center"><%=Moumi.getMessageBundle().getString("moumi.message.tot_report.section")%></td>
		<td align="center"><%=Moumi.getMessageBundle().getString("moumi.message.tot_report.submit")%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.person")%></td>
	</tr>
	<%for (int d = 0; d < reportCount; d++) {%>
	<tr>
		<td align="center"><%=repoPartNameList[d]%></td>
		<td align="center"><%=repoDeptNameList[d]%></td>
		<td align="center"><%=locationList[d]%></td>
		<td align="center"><%=gradeList[d]%></td>
		<td align="center"><%=foundationList[d]%></td>
		<td align="center"><%=MString.checkNull(repoUserNameList[d])%>&nbsp;</td>
		<td><%= Excel.adjustFmlaToExcel(TagFilter.removeBlankPara(Excel.removeFmla(totalList[d])))%></td>
	</tr>
	<%}%>
</table>
<%}else{%>
<%= Excel.adjustFmlaToExcel(TagFilter.removeBlankPara(Excel.setCellTypes(Excel.removeFmla(report), tmpItemTypeList))) %>
<%}%>
<!--%= Excel.removeFmla(Excel.setCellTypes(report, tmpItemTypeList)) %-->
<table width="100%" border="0" cellspacing="3" cellpadding="3">
	<!--tr height="1"valign="top" width="100%">
				<td height="10" colspan="2"></td>
			</tr>
			<tr height="1"  valign="top" width="100%">
				<td height="1" colspan="2" bgcolor="cccccc"></td>
			</tr>
			<tr height="1"valign="top" width="100%">
				<td height="1" colspan="2" bgcolor="#EFEFEF"></td>
			</tr>
			<tr height="1"valign="top" width="100%">
				<td height="10" colspan="2"></td>
			</tr>
			<tr valign="top">
				<td width="80"><b><font color="#FF6600">+</font>	<%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.opinion")%>:</b></td>
				<TD style="PADDING-LEFT: 10px; PADDING-BOTTOM: 10px; PADDING-TOP: 10px" width=588> 
					<STYLE>P {MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px}</STYLE>
					<p><%= HtmlUtil.toHtml(totReport.getNote()) %></p>
				</TD>
			</tr>
			<tr height="1"valign="top" width="100%">
				<td height="10" colspan="2"></td>
			</tr>
			<tr height="2"  valign="top">
				<td height="1" colspan="2" bgcolor="cccccc"></td>
			</tr-->
</table>
</body>
</html>
<%
}catch(Exception ex){
	ex.printStackTrace();
	out.println(kr.co.kihyun.text.html.ServletUtil.getJavaScript("location='/servlet/kr.co.kihyun.beans.user.HttpSSOLogin?mode=logout';"));
}finally{
	if(tx.isActive())
		tx.rollback();
	pm.close();
}
%>

