
<%
/************************************************************@@
  * Program Name	: doc_list.jsp
  * Description		: /집계자/내문서함/등록함/문서 목록
  * Author			: 강원중
  * Create Date		: 2010.11.27
  * History			: 
@@************************************************************/
%>

<%@ page contentType="application/x-msexcel;charset=UTF-8"
	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{
	/********* Parameter *********/
	Long reportID = MLong.parseLong(request.getParameter("reportID"),null);
	String saveExprType = clearXSS(MString.checkNull(request.getParameter("saveExprType")),"");
        TotReport totReport = pm.getObjectById(TotReport.class, reportID);

	tx.begin();
	/********* report *********/
        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 docName = 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");
        //LJH
        response.setHeader("Content-Disposition","attachment; filename="+(URLEncoder.encode(docName, "UTF-8")).replaceAll(":","_").replace("+"," " )+".xls;");

%>
<html 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">
    <style type="text/css">
        /*td {mso-number-format:"\@";}*/  // 엑셀저장시 문자로 취합하도록 설정 
        .x124 {mso-number-format:"\@";}
        br {mso-data-placement:same-cell;} //엑셀저장시 BR을 같은 셀로 인식하도록 설정
    </style>
</head>
<body>
<%
        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">
</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();
}
%>

