<%@ page contentType="text/html; charset=UTF-8"
	import="kr.co.kihyun.lang.MString" import="kr.co.kihyun.lang.MLong"
	import="kr.co.kihyun.beans.entity.TotDoc"
	import="kr.co.kihyun.beans.entity.TotDocProcess"
	import="kr.co.kihyun.text.html.TagFilter"
	import="kr.co.kihyun.lang.StringConverter"
	import="kr.co.kihyun.moumi.Moumi" import="kr.co.kihyun.lang.Encoder"
	import="java.net.URLEncoder" import="kr.co.kihyun.lang.MInteger"
	import="kr.co.kihyun.beans.totsys.report.Report"
	import="org.apache.commons.lang.StringEscapeUtils"
	import="javax.jdo.PersistenceManager" import="javax.jdo.Transaction"
	import="kr.co.kihyun.beans.entity.util.*"
	import="kr.co.kihyun.beans.entity.TotDoc"%>
<%@ include file="/totsys/common/inc/sec/secure.inc.jsp"%>
<%
PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
Transaction tx = pm.currentTransaction();
try{
	/********** get Parameter *************/
	Long docID = MLong.parseLong(request.getParameter("docID"),null);
	String gubun = clearXSS(Encoder.toJava(request.getParameter("gubun")),"");

	/*********** doc value *****************/
	String docForm = "";
	String docName = "";
	if(docID != null){
		TotDoc totDoc = pm.getObjectById(TotDoc.class, docID);
		docForm = totDoc.getForm();
		docName = totDoc.getName();
		docForm = TagFilter.convertSingle(docForm);
		docForm = StringConverter.toOneLine(docForm);

		//한글2002 버전특성에 인한 " "이 잘못 쌓여지는 버그가 있어서 추가한 부분
		docForm = docForm.replaceAll("font-family: \"","font-family: ");
		docForm = docForm.replaceAll("\"; text-align: ","; text-align: ");
		docForm = docForm.replaceAll("<table width=700 border=0><tbody><tr><td width=\"100%\"></td></tr></tbody></table>","\"자료입력창\"");
	}
	
	int tmp = MInteger.parseInt(request.getParameter("tmp"), 0);
	
	int allReportCount = 0;
	int sendReportCount = 0;
	Report report = new Report();
	allReportCount = report.getAllCount(docID);
	sendReportCount = report.getSendCount(docID);
%>

<%@page import="kr.co.kihyun.beans.entity.TotDocType"%><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/SquareButtons.css"
	type="text/css">
<script src="/totsys/common/js/rollover.js"></script>
<link rel="stylesheet" href="/totsys/common/css/tabs.css"
	type="text/css">
<script type="text/javascript" src="/lib/js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
		tinyMCE.init({
		// General options
		mode : "exact",
		elements : "EditCtrl",
		theme : "advanced",
		plugins : "table",
		language: "ko",
		extended_valid_elements : "td[abbr|align<center?char?justify?left?right|axis|bgcolor|char|charoff|class"
												+"|colspan|dir<ltr?rtl|headers|height|id|lang|nowrap<nowrap|onclick"
												+"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
												+"|onmouseout|onmouseover|onmouseup|rowspan|scope<col?colgroup?row?rowgroup"
												+"|style|title|valign<baseline?bottom?middle?top|width"
												+"|*]",
		setup : function(ed) {
	        ed.makeReadOnly = function(ro) {
	            var t = this, s = t.settings, DOM = tinymce.DOM, d = t.getDoc();
	
	            if(!s.readonly && ro) {
	                if (!tinymce.isIE) {
	                    try {
	                        d.designMode = 'Off';
	                    } catch (ex) {
	                        alert(ex);
	                    }
	                } else {
	                    b = t.getBody();
	                    DOM.hide(b);
	                    b.contentEditable = false;
	                    DOM.show(b);
	                }
	                s.readonly = true;
	            } else if(s.readonly && !ro) {
	                if (!tinymce.isIE) {
	                    try {
	                        d.designMode = 'On';
	                        // Design mode must be set here once again to fix a bug where
	                        // Ctrl+A/Delete/Backspace didn't work if the editor was added using mceAddControl then removed then added again
	                        d.designMode = 'Off';
	                        d.designMode = 'On';
	                    } catch (ex) {
	                        alert(ex);
	                    }
	                } else {
	                    b = t.getBody();
	                    DOM.hide(b);
	                    b.contentEditable = true;
	                    DOM.show(b);
	                }
	                s.readonly = false;
	            }
	        };
	    },

		forced_root_block : false,
		force_br_newlines: true,
		force_p_newlines: false,

		theme_advanced_buttons1 : "bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_fonts : "굴림=굴림;굴림체=굴림체;궁서=궁서;궁서체=궁서체;돋움=돋움;돋움체=돋움체;바탕=바탕;바탕체=바탕체"
		});
	</script>
<script language=javascript>
			function docFormContentModify(){
				docFormCM.docFCM.value = tinyMCE.getInstanceById('EditCtrl').getContent();

				if(docFormCM.docFCM.value == ''){
					alert('변경할 <%=TotDocProcess.FORM%>이 없습니다.\\n 다시 확인하시고 변경하여 주십시요.');
					return;
				}else{
					docFormCM.submit();
					//window.close();
				}
			}
		</script>
<script language="javascript">
			function formContentModify(){
				if(confirm("현재 <%=TotDocType.TOT_DOC %>에 대한\n제출건수 : <%=sendReportCount%>건\n미제출건수 : <%=(allReportCount-sendReportCount)%>건\n이 있습니다.\n계속 진행하시면 모든 제출완료 문서가 접수 상태로 변경됩니다\n계속 진행하시겠습니까?")){
					location.href="./form_content_modify.jsp?docID=<%=docID%>";
				}else{
					return;
				}
			}

			function formPreference(){
				if(confirm("현재 <%=TotDocType.TOT_DOC %>에 대한\n제출건수 : <%=sendReportCount%>건\n미제출건수 : <%=(allReportCount-sendReportCount)%>건\n이 있습니다.\n계속 진행하시면 모든 제출완료 문서가 접수 상태로 변경됩니다\n계속 진행하시겠습니까?")){
					location.href="./doc_form_modify.jsp?docID=<%= docID %>";
				}else{
					return;
				}
			}
	
			function modify(){
				location.href="/totsys/sysadm/prssbox/doc_modify.jsp?docID=<%= docID %>&url=mmprss";
			}
	
			function formView(){
				location.href="/totsys/sysadm/prssbox/doc_form_view.jsp?docID=<%=docID%>";
			}
	
			function reports(){
				location.href="/totsys/sysadm/prssbox/reports/report_list.jsp?docID=<%= docID %>";
			}
	
			function totReports(){
				location.href="/totsys/sysadm/prssbox/tot_reports/total_reports.jsp?docID=<%= docID %>";
			}
	
			function totReport(){
				location.href="/totsys/sysadm/prssbox/tot_report/total_report.jsp?docID=<%= docID %>";
			}
			
		</script>
</head>

<body style='' bgcolor="#FFFFFF" text="#000000" leftmargin="0"
	topmargin="0" marginwidth="0" marginheight="0">
<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="modify();">기본정보</a></li>
	<li><span class="kecttep_menu_focous">양식정보</span></li>
	<li><a href="#" onclick="reports();">제출현황</a></li>
	<li><a href="#" onclick="totReports();">집계현황</a></li>
	<li><a href="#" onclick="totReport();">집계표</a></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="javacscript:formContentModify();"><span class="modify">
				<%if(tmp == 1){%> <%= Moumi.getMessageBundle().getString("moumi.message.button.formCheck") %></span>
				<%}else{%> <%= Moumi.getMessageBundle().getString("moumi.message.button.formModify") %></span>
				<%}%> </a></td>
				<td class="kecttep_button_td"><a class="simplebutton" href="#"
					onclick="javascript:formPreference();"><span class="modify"><%= Moumi.getMessageBundle().getString("moumi.message.button.formPreference") %></span></a>
				</td>
			</tr>
		</table>
		</td>
	</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td width="100%">
		<table valign="top" cellSpacing="0" cellPadding="0" border="0"
			width="100%">
			<tr>
				<td>
				<table width="100%" border="0" cellpadding=0 cellspacing=0
					class=llist1>
					<tr class=bgw1>
						<td colspan=3>
						<table width="100%" cellpadding=0 cellspacing=0 border=0>
							<tr>
								<td><textarea id="EditCtrl"
									style="width: 100%; height: 18em;">
																	<%if(docID != null){
                                                                                                                                                        //v2. 14.디렉토리 경로 조작(getParameter)_CWE-22/23 : 오탐
																			out.write(StringEscapeUtils.escapeHtml(docForm));
																		}
																	%>
																	</textarea></td>
							</tr>
						</table>
						</td>
					</tr>
				</table>
				<br>

				<!-- [이전단계][다음단계] 설정 --> <%if(tmp == 1){%> <%}else{%>
				<table align="center" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<!--
													<td><a href="#" onclick="javascript:docFormContentModify();" ><img src="/totsys/common/images/bt_enter.gif" name="bt_enter1" border="0" id="bt_enter1"></a></td>
													<td >&nbsp;</td>
													<td><a href="./doc_form_view.jsp?docID=<%//= docID %>"><img src="/totsys/common/images/bt_cancel3.gif" name="bt_cancel3" border="0"></a></td>
													-->
						<td><a href="./doc_form_view.jsp?docID=<%= docID %>"><img
							src="/totsys/common/inc/documents/tot_doc/images/bt_pre.gif"
							name="bt_pre" border="0"></a></td>
						<td>&nbsp;</td>
						<td><a href="#" onclick="javascript:docFormContentModify();"><img
							src="/totsys/common/inc/documents/tot_doc/images/bt_preview.gif"
							name="bt_next" border="0"></a></td>
					</tr>
				</table>
				<%}%>
				</td>
			</tr>
		</table>
		</td>
	</tr>
</table>
</div>
</div>

<form name="docFormCM"
	action="/servlet/kr.co.kihyun.beans.totsys.doc.HttpReFormReader"
	method="post" encType="multipart/form-data"><input type="hidden"
	name="docFCM"> <input type="hidden" name="docID"
	value="<%= docID %>"> <input type="hidden" name="isAdmin"
	value="admin"></form>
</body>
</html>
<%
}catch(Exception ex){
        //38.오류메세지를 통한 정보 노출(getMessage)_CWE-209 : Update by YOUNGJUN,CHO
	//out.println(ex);
	ex.printStackTrace();
	//out.println("<html><body style='overflow=auto' bgcolor='white'><h1>Can't contact servlet runner</h1><br><br>Message : "+ex.getMessage()+"</body></html>");
	//out.println("<META HTTP-EQUIV='refresh' CONTENT='0.1; URL=/error/exception.jsp'>");
        //================================================
}finally{
    if(tx.isActive())
    tx.rollback();
	pm.close();
}
%>
