
<%
/************************************************************@@
  * Program Name	: popup_inform_preview.jsp
  * Description		: 집계문서 셀정의(등록과, 변경에서 같이 사용
  * Author			: 기현테크
  * Create Date		: 2010.11.25
  * History			:
@@************************************************************/
%>
<%@ page contentType="text/html; charset=UTF-8"
	import="java.net.URLEncoder" import="java.net.URLDecoder"
	import="javax.jdo.PersistenceManager"
	import="kr.co.kihyun.beans.entity.util.*"
	import="kr.co.kihyun.beans.entity.TotDoc"
	import="kr.co.kihyun.beans.user.HttpSSOLogin"
	import="kr.co.kihyun.lang.MString" import="kr.co.kihyun.lang.Encoder"
	import="kr.co.kihyun.lang.MInteger" import="kr.co.kihyun.lang.MLong"
	import="kr.co.kihyun.text.html.TagFilter"
	import="kr.co.kihyun.moumi.doc.MDocPreview"
	import="kr.co.kihyun.moumi.doc.table.item.MItem"
	import="kr.co.kihyun.beans.totsys.doc.table.item.ItemList"
	import="kr.co.kihyun.moumi.Moumi"
    import="javax.jdo.Transaction"
	import="kr.co.kihyun.text.html.CallbackHandler"%>

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

<%
PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
Transaction tx = pm.currentTransaction();
try{
	int defItemSize = MInteger.parseInt(MString.checkNull(request.getParameter("defItemSize")));

	Long docID = MLong.parseLong(request.getParameter("docID"),null);
	String choice = clearXSS(request.getParameter("choice"),"");
	String deptIDs = clearXSS(Encoder.toJava(MString.checkNull(request.getParameter("deptIDs"))),"");
	String deptNames = clearXSS(Encoder.toJava(MString.checkNull(request.getParameter("deptNames"))),"");
	String userIDs = clearXSS(Encoder.toJava(MString.checkNull(request.getParameter("userIDs"))),"");
	String userNames = clearXSS(Encoder.toJava(MString.checkNull(request.getParameter("userNames"))),"");
	String docName = clearXSS(Encoder.toJava(request.getParameter("docName")),"");
	String stDate = clearXSS(request.getParameter("stDate"),"");
	String edDate = clearXSS(request.getParameter("edDate"),"");
	String accAuth = clearXSS(request.getParameter("accAuth"),"");
	Long repDocID = MLong.parseLong(request.getParameter("repDocID"),null);
	String docGroupID = clearXSS(request.getParameter("docGroupID"),"");
	String isFromFormBox = clearXSS(request.getParameter("isFromFormBox"),"");
	String tableCount  = clearXSS(request.getParameter("tableCount"),"");
	String isDynaTable = clearXSS(request.getParameter("isDynaTable"),"");
	String mode = clearXSS(request.getParameter("mode"),"");
	String tableDefines = clearXSS(request.getParameter("tableDefines"),"");
	String itemNames = clearXSS(Encoder.toJava(request.getParameter("itemNames")),"");
	String tableNums = clearXSS(Encoder.toJava(request.getParameter("tableNums")),"");
	String colNums = clearXSS(Encoder.toJava(request.getParameter("colNums")),"");
	String rowNums = clearXSS(Encoder.toJava(request.getParameter("rowNums")),"");
	String itemSizes = clearXSS(Encoder.toJava(request.getParameter("itemSizes")),"");
	String itemDescs = clearXSS(Encoder.toJava(request.getParameter("itemDescs")),"");
	String itemExprs = clearXSS(Encoder.toJava(request.getParameter("itemExprs")),"");
	String itemTypes = clearXSS(Encoder.toJava(request.getParameter("itemTypes")),"");
	//String docForm = clearXSS(request.getParameter("docForm"),"");

	String tableType  = clearXSS(request.getParameter("tableType"),"");
	String tableTypes  = clearXSS(request.getParameter("tableTypes"),"");

	if(defItemSize < 1 ) defItemSize = 10;

	/************ doc values ************/
	TotDoc totDoc = docID == null ? null : pm.getObjectById(TotDoc.class, docID);
	String docForm = "";

	/************* item values ***********/
	StringBuffer itemNamesBuf = new StringBuffer();
	StringBuffer itemSizesBuf = new StringBuffer();
	StringBuffer itemDescsBuf = new StringBuffer();
	StringBuffer itemExprsBuf = new StringBuffer();
	StringBuffer itemTypesBuf = new StringBuffer();

	if(mode != null && mode.equals("regist")){
		docForm = (String)session.getAttribute("docForm");
	}else if(mode != null && mode.equals("modify")){
		docForm = totDoc.getForm();
	}else	if(mode != null && mode.equals("preview")){
		docForm = totDoc.getForm();
		docName = totDoc.getName();
		if(totDoc.getTotTables().iterator().hasNext())
			defItemSize = totDoc.getTotTables().iterator().next().getItemSize();

		/********** Item values **********/
		ItemList itemList = new ItemList();
                //v2. 13.SQL 삽입 : itemList.executeQuery()에서 prepare SQL 문으로 되어 있다.
		itemList.executeQuery(docID);
                //=================
		int itemCount = itemList.getCount();
		String[] itemNameList = itemList.getNameList();
		String[] itemDescList = itemList.getDescList();
		String[] itemExprList = itemList.getExprList();
		int[] itemTypeList = itemList.getTypeList();
		int[] itemNumList = itemList.getNumList();
		int[] itemSizeList = itemList.getSizeList();
		int[] tableNumList = itemList.getTableNumList();
		int[] colNumList = itemList.getFieldNumList();
		int[] rowNumList = itemList.getRecordNumList();
		int[] itemBNWList = itemList.getBNWList();
		String[] itemTypeNameList = itemList.getTypeNameList();

		for(int i=0; i<itemCount; i++){
			itemNamesBuf.append(i + ":" + itemNameList[i] + MItem.LIST_DELIM);
			itemSizesBuf.append(i + ":" + itemSizeList[i] + MItem.LIST_DELIM);
			itemDescsBuf.append(i + ":" + itemDescList[i] + MItem.LIST_DELIM);
			itemExprsBuf.append(i + ":" + itemExprList[i] + MItem.LIST_DELIM);
			itemTypesBuf.append(i + ":" + MItem.getTypeName(itemTypeList[i]) + MItem.LIST_DELIM);
		}

		itemNames = itemNamesBuf.toString();
		itemSizes = itemSizesBuf.toString();
		itemDescs = itemDescsBuf.toString();
		itemExprs = itemExprsBuf.toString();
		itemTypes = itemTypesBuf.toString();
	}

	/*********** preview로 docForm 변환 ***********/
	String putValScript = "";
	String changeAllScript = "";
	String docBodyForm = "";
	String docTitleForm = "";
	String inputForm = "";

	MDocPreview docPreView = new MDocPreview();
	docPreView.convert(docForm, itemNames, itemSizes, itemExprs, itemTypes, itemDescs, defItemSize);
	docForm = docPreView.getInputForm();
	putValScript = docPreView.getPutValScript();
	changeAllScript = docPreView.getChangeAllScript();
	changeAllScript = changeAllScript.replaceAll("[$]",".");
	inputForm = docPreView.getInputForm();
%>
<html>
<head>
<title><%=Moumi.getTitle()%></title>
<link rel="stylesheet" href="/totsys/common/css/text.css"
	type="text/css">
<link rel="stylesheet" href="/totsys/common/css/kecttep.css"
	type="text/css">
<script src="/totsys/common/js/rollover.js"></script>
<script src="/totsys/common/js/checkNum.js"></script>
<script src="/totsys/common/js/util.js"></script>
<script src="/totsys/common/js/calendar.js"></script>
<script src="/totsys/common/js/drag.js"></script>

<script language='JavaScript'>
			function formTypeCheck(){
				if(opener.dform.tableCount.value > 1 && opener.dform.tableType[1].checked == true){
					if(confirm('<%=Moumi.getMessageBundle().getString("moumi.message.popup.formTypeTableSet")%>')){
						opener.dform.tableType[0].focus();
						return false;
					}
				}else if(opener.dform.isDynaTable == false && opener.dform.tableType[1].checked == true){
					if(confirm('<%=Moumi.getMessageBundle().getString("moumi.message.popup.formTypeSet")%>')){
						opener.dform.tableType[0].focus();
						return false;
					}
				}

				return true;
			}

			function saveform() {
				dform.action = '/servlet/kr.co.kihyun.beans.totsys.doc.HttpDocRegister';
				dform.target = '_self';
				dform.submit();
			}

			function modifyform(){
				if(!formTypeCheck()) return;
				opener.dform.action = '/servlet/kr.co.kihyun.beans.totsys.doc.HttpDocFormModifyer';
				opener.dform.target = '_self';
				opener.dform.submit();
				window.close();
			}

			<%= putValScript %>

			<%
			if(changeAllScript.length() > 0){	%>
				function changeAll() {
				<%= changeAllScript %>

				}
			<%
			}%>


			function formSubmit(){
				formConfig.action = '/totsys/common/web/report_dept/dept_list.jsp';
				formConfig.target = '_self';
				formConfig.submit();
			}

			function beforeSubmit(){
				formConfig.docName.value = "<%= docName%>";
				formConfig.action = '/totsys/totper/mydocbox/formbox/doc_form_config.jsp';
				formConfig.target = '_self';
				formConfig.submit();
			}

		</script>
</head>
<div id="SetWin" style="position: absolute; visibility: hidden; width: 100px; height: 100px; background: silver; border: 1px solid #333333; line-height: 1.4em; padding: 3px 3px"></div>
<body style='' bgcolor="#FFFFFF" text="#000000" leftmargin="0"
	topmargin="0" marginwidth="0" marginheight="0"
	onload="scrollObjectContent('formDiv');">
<form name="formConfig" method="post"
	action="/totsys/common/web/report_dept/dept_list.jsp" target="_self">
<input type="hidden" name="docID" value="<%= docID%>"> <input
	type="hidden" name="choice" value="<%= choice%>"> <input
	type="hidden" name="deptIDs" value="<%= deptIDs%>"> <input
	type="hidden" name="deptNames" value="<%= deptNames%>"> <input
	type="hidden" name="userIDs" value="<%= userIDs%>"> <input
	type="hidden" name="userNames" value="<%= userNames%>"> <input
	type="hidden" name="docName" value="<%= docName%>"> <input
	type="hidden" name="stDate" value="<%= stDate%>"> <input
	type="hidden" name="edDate" value="<%= edDate%>"> <input
	type="hidden" name="accAuth" value="<%= accAuth%>"> <input
	type="hidden" name="repDocID" value="<%= repDocID%>"> <input
	type="hidden" name="docGroupID" value="<%= docGroupID%>"> <input
	type="hidden" name="isFromFormBox" value="<%= isFromFormBox%>">
<input type="hidden" name="tableCount" value="<%= tableCount%>">
<input type="hidden" name="isDynaTable" value="<%= isDynaTable%>">
<input type="hidden" name="mode" value="<%= mode%>"> <input
	type="hidden" name="tableDefines" value="<%= tableDefines%>"> <input
	type="hidden" name="itemNames"
	value='<%= URLEncoder.encode(itemNames, "UTF-8") %>'> <input
	type="hidden" name="tableNums"
	value='<%= URLEncoder.encode(tableNums, "UTF-8") %>'> <input
	type="hidden" name="colNums"
	value='<%= URLEncoder.encode(colNums, "UTF-8") %>'> <input
	type="hidden" name="rowNums"
	value='<%= URLEncoder.encode(rowNums, "UTF-8") %>'> <input
	type="hidden" name="itemSizes"
	value='<%= URLEncoder.encode(itemSizes, "UTF-8") %>'> <input
	type="hidden" name="itemDescs"
	value='<%= URLEncoder.encode(itemDescs, "UTF-8") %>'> <input
	type="hidden" name="itemExprs"
	value='<%= URLEncoder.encode(itemExprs, "UTF-8") %>'> <input
	type="hidden" name="itemTypes"
	value='<%= URLEncoder.encode(itemTypes, "UTF-8") %>'> <input
	type="hidden" name="tableType" value="<%= tableType%>"> <input
	type="hidden" name="defItemSize" value="<%= defItemSize%>"> <input
	type="hidden" name="tableTypes" value="<%= tableTypes%>"></form>
<table width="100%" height="100%" border="0" align="center"
	cellpadding="0" cellspacing="0">

	<tr>
		<td valign="top">
		<table width="100%" border="0" align="center" cellpadding="0"
			cellspacing="0">
			<tr>
				<td>
				<table width="100%" border="0" cellspacing="0" cellpadding="0">

					<!-- 뉴타이틀 -->
					<jsp:include page="/totsys/common/inc/title/title.jsp" flush="true" />
					<!-- 뉴타이틀 -->

					<tr>
						<td height="1"></td>
					<tr>
					<tr>
						<td valign="top">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<form name='dform' method='post' action=''><input
								type="hidden" name="docName" value="<%= docName %>"> <input
								type="hidden" name="stDate" value="<%= stDate %>"> <input
								type="hidden" name="edDate" value="<%= edDate %>"> <input
								type="hidden" name="deptIDs" value="<%= deptIDs %>"> <input
								type="hidden" name="deptNames" value="<%= deptNames %>">
							<input type="hidden" name="userIDs" value="<%= userIDs %>">
							<input type="hidden" name="userNames" value="<%= userNames %>">
							<input type="hidden" name="accAuth" value="<%= accAuth %>">
							<input type="hidden" name="repDocID" value="<%= repDocID %>">
							<input type="hidden" name="docGroupID" value="<%= docGroupID %>">
							<input type="hidden" name="isFromFormBox"
								value="<%= isFromFormBox %>"> <input type="hidden"
								name="tableCount" value="<%= tableCount %>"> <input
								type="hidden" name="isDynaTable" value="<%= isDynaTable %>">
							<input type="hidden" name="mode" value="regist"> <input
								type="hidden" name="tableDefines" value="<%= tableDefines%>">
							<input type="hidden" name="itemNames" value="<%= itemNames%>">
							<input type="hidden" name="tableNums" value="<%= tableNums%>">
							<input type="hidden" name="colNums" value="<%= colNums%>">
							<input type="hidden" name="rowNums" value="<%= rowNums%>">
							<input type="hidden" name="itemSizes" value="<%= itemSizes%>">
							<input type="hidden" name="itemDescs" value="<%= itemDescs%>">
							<input type="hidden" name="itemExprs" value="<%= itemExprs%>">
							<input type="hidden" name="itemTypes" value="<%= itemTypes%>">
							<input type="hidden" name="tableTypes" value="<%= tableTypes%>">

							<input type="hidden" name="backDash" value="back"> <input
								type="hidden" name="docForm"> <input type="hidden"
								name="tableType" value="<%= tableType%>"> <input
								type="hidden" name="defItemSize" value="<%= defItemSize%>">


							<!--- 표시작 ---->
							<tr valign="top">
								<td align="left" height="11" valign="top"
									style="padding-top: 10; padding-bottom: 25;">
								<div id="formDiv"
									style="width: <%=session.getAttribute("formWidth") %>; overflow-x: auto;">
								<!--------------------------- config Content start --------------------------->
								<%= docForm %> <!--------------------------- config Content end --------------------------->
								</div>
								</td>
							</tr>

							<tr>
								<td height="10"></td>
							<tr>
								<!--- 표 끝 ---->
								<!--- 버튼(계산)---->
							<tr>
								<td height="10"></td>
							<tr>

								<!--- 버튼 (확인,취소)  시작 ---->
							<tr valign="middle">
								<td align="center">
								<table border="0" cellspacing="0" cellpadding="0" align="center">
									<tr>
										<!--
																<%//if(mode != null && mode.equals("regist")){%>
																<td align="right"><img name="bt_enter" border="0" style="cursor:hand;" onclick='saveform();' onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('bt_enter','','/totsys/common/web/documents/tot_doc/images/bt_enter-over.gif',1)" src="/totsys/common/web/documents/tot_doc/images/bt_enter.gif"></td>
																<td>&nbsp;</td>
																<td><a href="#" onclick='window.close();' onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('bt_cancel3','','/totsys/common/web/documents/tot_doc/images/bt_cancel3-over.gif',1)"><img name="bt_cancel3" border="0" src="/totsys/common/web/documents/tot_doc/images/bt_cancel3.gif"></a></td>
																<%//}else if(mode != null && mode.trim().equals("modify")){%>
																<td align="right"><img name="bt_enter" border="0" style="cursor:hand;" onclick='modifyform();' onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('bt_enter','','/totsys/common/web/documents/tot_doc/images/bt_enter-over.gif',1)" src="/totsys/common/web/documents/tot_doc/images/bt_enter.gif"></td>
																<td>&nbsp;</td>
																<td><a href="#" onclick='window.close();' onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('bt_cancel3','','/totsys/common/web/documents/tot_doc/images/bt_cancel3-over.gif',1)"><img name="bt_cancel3" border="0" src="/totsys/common/web/documents/tot_doc/images/bt_cancel3.gif"></a></td>
																<%//}else if(mode != null && mode.trim().equals("preview")){%>
																<td width="30">&nbsp;</td>
															-->
										<td><a href="#"><img onclick="beforeSubmit();"
											src="/totsys/common/inc/documents/tot_doc/images/bt_pre.gif"
											name="bt_pre" border="0"></a></td>
										<td>&nbsp;</td>
										<%if ( changeAllScript.length() > 0 ) {%><td align="center"
											valign="top"><a href=# onClick='changeAll();'><img
											src="/totsys/common/web/documents/tot_doc/images/bt_cal.gif"
											border="0"></a></td>
										<td>&nbsp;</td>
										<%}%>
										<td><a href="#"><img onclick="saveform();"
											src="/totsys/common/inc/documents/tot_doc/images/btn_completed.gif"
											name="bt_next" border="0"></a></td>
										<%//}%>
									</tr>
								</table>
								</td>
							</tr>
							<!--- 버튼 (확인,취소) 끝---->
							<tr valign="middle">
								<td align="center"></td>
							</tr>
							</form>
						</table>
						</td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		</td>
		<td width="10"></td>
	</tr>

</table>
</body>
</html>
<%
}catch(Exception ex){
	ex.printStackTrace();%>
<script language="javascript">
		<!--
		alert('<%=Moumi.getMessageBundle().getString("moumi.message.popup.falseTable")%>');
		window.close();
		//-->
	</script>
<%
}finally{
    if(tx.isActive())
    tx.rollback();
	pm.close();
}
%>
