<%@ page contentType="text/html; charset=UTF-8"
	import="java.net.URLEncoder" import="java.net.URLDecoder"
	import="kr.co.kihyun.lang.MString" import="kr.co.kihyun.lang.MLong"
	import="kr.co.kihyun.text.html.HtmlUtil"
	import="kr.co.kihyun.lang.StringConverter"
	import="kr.co.kihyun.text.html.ServletUtil"
	import="kr.co.kihyun.beans.user.HttpSSOLogin"
	import="kr.co.kihyun.moumi.Moumi"
	import="kr.co.kihyun.moumi.report.MReport"
	import="kr.co.kihyun.beans.user.HttpSSOLogin"
	import="kr.co.kihyun.beans.user.Dept"
	import="kr.co.kihyun.beans.user.UserView"
	import="kr.co.kihyun.beans.totsys.report.Report"
	import="kr.co.kihyun.beans.totsys.report.ReportView"
	import="kr.co.kihyun.beans.totsys.report.ReportViewManager"
	import="kr.co.kihyun.text.hml.Hwp"
	import="kr.co.kihyun.text.html.HtmlUtil"
	import="kr.co.kihyun.beans.totsys.report.tots.ReportsViewer"
	import="kr.co.kihyun.lang.MInteger"
	import="kr.co.kihyun.beans.totsys.doc.table.Table"
	import="kr.co.kihyun.beans.totsys.doc.table.item.Item"
	import="kr.co.kihyun.text.excel.Excel" import="org.slf4j.Logger"
	import="org.slf4j.LoggerFactory" import="kr.co.kihyun.beans.user.User"
	import="kr.co.kihyun.text.html.TagFilter"
	import="kr.co.kihyun.lang.MLong" import="javax.jdo.PersistenceManager"
	import="javax.jdo.Transaction"
	import="kr.co.kihyun.beans.entity.util.*"
	import="kr.co.kihyun.beans.entity.*"%>
<%@page import="java.util.List"%>
<%@ page import="java.util.Map.Entry"%>
<%@page import="javax.jdo.Query"%>

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

<%
	Logger LOG = LoggerFactory.getLogger(this.getClass());

	PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
	Transaction tx = pm.currentTransaction();
	try {
		/********* Parameter *********/
		Long reportID = MLong.parseLong(request.getParameter("reportID"), null);
		TotReport totReport = pm.getObjectById(TotReport.class, reportID);

		/********* report *********/
		String docName = totReport.getTotDoc().getName();

		// TODO: extract method.
		String report = null;
		if (totReport.getSlaveTotDoc() == null)
			report = TotReportUtil.toHTML(totReport);
		else {
			TotDoc slaveDoc = totReport.getSlaveTotDoc();
			if (!slaveDoc.getCompReports(pm).isEmpty())
				report = TotReportUtil.toHTML(totReport.getTotDoc(), slaveDoc.getCompReports(pm));
		}

		if (report == null) {
			out.println(ServletUtil.alert(Moumi.getMessageBundle().getString("moumi.message.popup.notReport")));
			out.println(ServletUtil.getJavaScript("history.go(-1);"));
			return;
		}
		/********* report view *******/
		String note = MString.checkNull(totReport.getNote());
		Long downDocID = totReport.getSlaveTotDoc() == null ? null : totReport.getSlaveTotDoc().getId();

		// 연계수정
		String memo = MString.checkNull(totReport.getRecentHistory() == null ? null : totReport.getRecentHistory().getMemo());
		String url = clearXSS(request.getParameter("url"),"");
		if(url == null){ url = ""; }


%>
<html>
	<head>
		<link rel="stylesheet" href="/totsys/common/css/text.css" type="text/css">
		<link rel="stylesheet" href="/totsys/common/css/kecttep.css" type="text/css">
                <link rel="stylesheet" href="/totsys/common/css/SquareButtons.css"
	type="text/css">
	</head>
        <script Language="javascript">
    function excelLink(){
        location.href="/totsys/common/web/documents/report/report_view_excel.jsp?reportID=<%= reportID%>";
    }

</script>
<body style="margin: 10px" width="100%" BGCOLOR="#FFFFFF" LEFTMARGIN="0" TOPMARGIN="0"
	MARGINWIDTH="0" MARGINHEIGHT="0">
<table border="0" cellspacing="0" cellpadding="0">


	<!------------------------------- 보고자 정보 시작 ------------------------------->
	<%
	tx.begin();
	if(!totReport.getHistories().isEmpty()){%>
	<jsp:include page="/totsys/common/inc/repoper/repoper.jsp"
		flush="true">
		<jsp:param name="reportID" value="<%= reportID %>" />
		<jsp:param name="tmp1" value="1" />
	</jsp:include>
	<%}else{%>
	<jsp:include page="/totsys/common/inc/repoper/repoper.jsp"
		flush="true">
		<jsp:param name="reportID" value="<%= reportID %>" />
	</jsp:include>
	<%}
	tx.rollback();
	%>
	<!------------------------------- 보고자 정보 끝 ------------------------------->
	<tr valign="top"
		style="padding-top: 10; padding-bottom: 25; padding-left: 10;">
		<!---- 본문  시작---->
		<td>
			<jsp:include page="/totsys/common/inc/documents/report/report_view.jsp">
				<jsp:param name="reportID" value="<%= reportID %>" />
			</jsp:include>
		</td>
               </tr>
</table>
<!-- 테두리수정,글자가림수정 -->
<script type="text/javascript">
$(function(){
	$('#formDiv > table').attr({'border':'1','bo':'true'}).css('border','1px solid #000')
		.find('td').each(function(i,o){
			if($(o).closest('table').attr('bo')=='true'){
				$(this).css('border','1px solid #000');
			}
		});
	$('#formDiv span').css('line-height','2');
});
</script>
</body>
</html>
<%
	} catch (Exception ex) {
		ex.printStackTrace();
		out.println(kr.co.kihyun.text.html.ServletUtil.getJavaScript("alert('"+Moumi.getMessageBundle().getString("moumi.message.popup.requestAdmin")+"');"));
		out.println(kr.co.kihyun.text.html.ServletUtil.getJavaScript("location='/totsys/totper/main.jsp';"));
	} finally {
		if(tx.isActive())
			tx.rollback();
		pm.close();
	}
%>
