
<%
/************************************************************@@
  * Program Name	: popup_inform_preview.jsp
  * Description		: 집계문서 셀정의(등록과, 변경에서 같이 사용
  * Author				: 강원중
  * Create Date		: 2004.10.11
  * 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.lang.MString" import="kr.co.kihyun.lang.MLong"
	import="kr.co.kihyun.lang.Encoder" import="kr.co.kihyun.lang.MInteger"
	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.beans.user.HttpSSOLogin"
	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{
	/********** session내의 userId **********/
	String usID = HttpSSOLogin.getLoginID(request);

	String strPage  = clearXSS(request.getParameter("strPage"),"");
	String findOption = clearXSS(request.getParameter("findOption"),"");
	String findWord = clearXSS(Encoder.toJava(request.getParameter("findWord")),"");
	String url = "mmform";

	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">
<link rel="stylesheet" href="/totsys/common/css/tabs.css"
	type="text/css">
<link rel="stylesheet" href="/totsys/common/css/SquareButtons.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 formContentModify(){			location.href="/totsys/common/web/documents/form_content_modify/sysadm_form_content_modify.jsp?docID=<%=docID%>&gubun=form";
		}
	</script>
<script language="javascript">
		function docDel(){
				var frm = document.Del;
				if(confirm('양식을 삭제 하시겠습니까?')){
						frm.submit();
				}
		}
	</script>


<script language='JavaScript'>
			function formTypeCheck(){
				if(opener.dform.tableCount.value > 1 && opener.dform.tableType[1].checked == true){
					if(confirm("양식에 표가 두개 이상입니다.\n양식유형을 다시 설정하시겠습니까..?")){
						opener.dform.tableType[0].focus();
						return false;
					}
				}else if(opener.dform.isDynaTable == false && opener.dform.tableType[1].checked == true){
					if(confirm("양식에 입력할수있는 행이 두개 이상입니다.\n양식유형을 다시 설정하시겠습니까..?")){
						opener.dform.tableType[0].focus();
						return false;
					}
				}

				return true;
			}

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

			function modifyform(){
				//if(!formTypeCheck()) return;
				formModify.action = '/servlet/kr.co.kihyun.beans.totsys.doc.HttpDocFormModifyer';
				formModify.target = '_self';
				formModify.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.action = '/totsys/sysadm/formbox/doc_form_modify.jsp';
				formConfig.target = '_self';
				formConfig.submit();
			}

			function formView(){
				location.href="/totsys/sysadm/formbox/doc_view.jsp?docID=<%= docID %>&strPage=<%= strPage %>&findOption=<%= findOption %>&findWord=<%= findWord %>";
			}

			function propertiesUpdate(){
				location.href="/totsys/sysadm/formbox/doc_form_modify.jsp?docID=<%= docID %>&strPage=<%= strPage %>&findOption=<%= findOption %>&findWord=<%= findWord %>";
			}
		</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">
<form name="formModify" method="post"><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="<%= 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="tableType" value="<%= tableType%>"> <input
	type="hidden" name="defItemSize" value="<%= defItemSize%>"> <input
	type="hidden" name="tableTypes" value="<%= tableTypes%>"></form>
<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>

<FORM name="Del"
	action="/servlet/kr.co.kihyun.beans.totsys.doc.HttpDocDeleter"
	method="post"><INPUT type="hidden" name="docID"
	value="<%= docID %>"> <INPUT type="hidden" name="userID"
	value="<%= usID %>"> <INPUT type="hidden" name="url"
	value="<%= url %>"></FORM>


<div>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<!------------------------------- top menu start ------------------------------>
	<jsp:include page="/totsys/common/inc/title/title.jsp" flush="true" />
	<!------------------------------- top menu end ------------------------------->
</table>
</div>


<div id="header">
<ul id="primary">
	<li><a href="#" onclick="formView();">양식정보</a></li>
	<li><a href="#" onclick="formContentModify();">양식수정</a></li>
	<li><span class="kecttep_menu_focous">속성수정</span></li>
</ul>
</div>

<div id="main">
<div id="contents">

<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr class="toolbar">
		<td align="left">
		<table border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td><a class="simplebutton" href="#" onclick="docDel();"><span
					class="remove"><%= Moumi.getMessageBundle().getString("moumi.message.button.formRemove") %></span></a>
				</td>
			</tr>
		</table>
		</td>
	</tr>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<form name='dform' method='post' action=''><!--- 표시작 ---->
	<tr valign="top">
		<td align="left" height="11" valign="top"
			style="padding-left: 20; padding-right: 30; padding-top: 20"><!--------------------------- config Content start --------------------------->
		<%= docForm %> <!--------------------------- config Content end --------------------------->
		</td>
	</tr>
	<!--- 표 끝 ----> <!--- 버튼(계산)---->
	<tr>
		<td height="50"></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="modifyform()"
					src="/totsys/common/inc/documents/tot_doc/images/btn_modify_completed.gif"
					name="bt_next" border="0"></a></td>
				<%//}%>
			</tr>
		</table>
		</td>
	</tr>
	</form>
</table>
</div>
</div>
</body>
</html>
<%
}catch(Exception ex){
	ex.printStackTrace();%>
<script language="javascript">
		<!--
		alert("표 설정이 잘못 되었습니다.\n다시 확인 하시기 바랍니다.");
		window.close();
		//-->
	</script>
<%
}finally{
    if(tx.isActive())
    tx.rollback();
	pm.close();
}
%>
