
<%
/************************************************************@@
  * Program Name	: tot_reports_excel.jsp
  * Description		: /집계자/내문서함/등록함/문서 등록
  * Author				: 강원중
  * Create Date		: 2004.10.11
  * History				:
@@************************************************************/
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8"
	import="java.net.URLEncoder" import="java.net.URLDecoder"
	import="java.util.*" import="java.io.StringReader"
	import="kr.co.kihyun.beans.user.HttpSSOLogin"
	import="javax.jdo.PersistenceManager"
	import="kr.co.kihyun.beans.entity.util.*"
	import="kr.co.kihyun.beans.entity.TotDoc"
	import="javax.swing.text.html.parser.ParserDelegator"
	import="kr.co.kihyun.lang.Encoder" import="kr.co.kihyun.moumi.Moumi"
	import="kr.co.kihyun.lang.MString" import="kr.co.kihyun.lang.MLong"
	import="kr.co.kihyun.beans.totsys.doc.Doc"%>

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

<%
PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
try{
	/********** session내의 userId **********/
	String usID = HttpSSOLogin.getLoginID(request);

	/********** parameter **********/
	Long docID = MLong.parseLong(MString.checkNull(request.getParameter("docID")),null);
	String mode = clearXSS(MString.checkNull(request.getParameter("mode")),"");
	String docForm = null;
	String docName = clearXSS(URLDecoder.decode(MString.checkNull(request.getParameter("docName")), "UTF-8"),"");
	TotDoc totDoc = docID == null ? null : pm.getObjectById(TotDoc.class, docID);
	
	if(mode != null && mode.equals("regist")){
		docForm = (String)session.getAttribute("docForm");
	}else if(mode != null && mode.equals("modify")){
		docForm = totDoc.getForm();
		docName = totDoc.getName();
	}else if(mode != null && mode.equals("preview")){
		docForm = totDoc.getForm();
		docName = totDoc.getName();
	}
	
	response.setHeader("Accept-Ranges", "bytes");
	if((mode != null && mode.equals("preview")) || (mode != null && mode.equals("modify"))){
		response.setHeader("Content-Disposition","attachment; filename="+(URLEncoder.encode(docName, "UTF-8")).replaceAll(":","_").replace("+","%20" ) +".xls;");
	}else{
		response.setHeader("Content-Disposition","attachment; filename="+(URLEncoder.encode(docName, "UTF-8")).replaceAll(":","_").replace("+","%20" ) +".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=''>
<%=docForm %>
</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{
	pm.close();
}
%>
