<%@ page contentType="text/html; charset=UTF-8"
	import="java.net.URLEncoder" import="kr.co.kihyun.lang.MString"
	import="kr.co.kihyun.lang.MLong"
	import="kr.co.kihyun.beans.entity.TotDoc"
	import="kr.co.kihyun.beans.user.HttpSSOLogin"
	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="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"
	import="kr.co.kihyun.beans.entity.TotTable"%>
<%@page import="kr.co.kihyun.beans.entity.TotDoc"%>
<%@page import="kr.co.kihyun.beans.entity.TotDocProcess"%>
<%@ 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);
	int sysAuth = HttpSSOLogin.getSysAuth(request);
	/********** get Parameter *************/
	Long docID = MLong.parseLong(request.getParameter("docID"),null);
	String gubun = clearXSS(Encoder.toJava(request.getParameter("gubun")),"");

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

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

<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>
<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 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 : "굴림=굴림;굴림체=굴림체;궁서=궁서;궁서체=궁서체;돋움=돋움;돋움체=돋움체;바탕=바탕;바탕체=바탕체;"
*/
                theme_advanced_buttons1 : ""
		//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('<%=Moumi.getMessageBundle().getString("moumi.message.popup.notModifyData")%>');
				return;
			}else{
				docFormCM.submit();
				//window.close();
			}
		}
	</script>

<script language="javascript">
		function docDel(){
			var frm = document.Del;
			if(confirm('<%=Moumi.getMessageBundle().getString("moumi.message.popup.formDelete")%>')){
				frm.submit();
			}
		}
		
		function formView(){
			location.href="/totsys/totper/mydocbox/formbox/doc_view.jsp?docID=<%=docID%>&strPage=<%=strPage%>&findOption=<%=findOption%>&findWord=<%=findWord%>";
		}
		
		function reg_use(){
			if(confirm('<%=Moumi.getMessageBundle().getString("moumi.message.popup.reuse")%>'))
				location.href="/totsys/totper/mydocbox/regbox/doc_regist.jsp?reuseDocID=<%=docID%>&reuseDocName=<%=docName%>&isFromFormBox=true";
		}
		
		function propertiesUpdate(){
			location.href="/totsys/totper/mydocbox/formbox/doc_form_modify.jsp?docID=<%=docID%>&strPage=<%=strPage%>&findOption=<%=findOption%>&findWord=<%=findWord%>";
		}
	</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="formView();"><%=TotDocProcess.FORM%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.info")%></a></li>
	<li><span class="kecttep_menu_focous"><%=TotDocProcess.FORM%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.modify")%></span></li>
	<!--<li><a href="#" onclick="propertiesUpdate();"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.value")%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.modify")%></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>
				<%if(sysAuth == Moumi.TOTPER){%>
				<td><a class="simplebutton" href="#" onclick="reg_use();"><span
					class="regist">서식재사용</span></a>
				</td>
				<%}%>
				<td <%if(sysAuth == Moumi.TOTPER){%> class="kecttep_button_td" <%}%>>
				<a class="simplebutton" href="#" onclick="docDel();"><span
					class="remove"><%= Moumi.getMessageBundle().getString("moumi.message.button_small.docDel") %></span></a>
				</td>
			</tr>
		</table>        
		</td>
	</tr>
--%>

	<tr>
		<td height="10"></td>
	</tr>
	<tr>
		<td width="100%">
		<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>

		<table align="center" border="0" cellspacing="0" cellpadding="0">
			<tr>
                            <%--
				<td><a href="#" onclick="javascript:docFormContentModify();"><img
					src="/totsys/totper/mydocbox/formbox/images/bt_enter.gif"
					name="bt_enter1" border="0" id="bt_enter1"></a></td>
				<td>&nbsp;</td>
				<td><a
					href="/totsys/totper/mydocbox/formbox/doc_view.jsp?docID=<%= docID %>&strPage=<%= strPage %>&findOption=<%= findOption %>&findWord=<%= findWord %>"><img
					src="/totsys/totper/mydocbox/formbox/images/bt_cancel3.gif"
					name="bt_cancel3" border="0"></a></td>
                          --%>
                          <td><a href="#" onclick="javascript:docFormContentModify();"><img
					src="/totsys/totper/mydocbox/regbox/images/bt_next.gif"
					name="bt_enter1" border="0" id="bt_enter1"></a></td>



			</tr>
		</table>
		</form>
		</td>
	</tr>
</table>
</div>
</div>
<!--<form name="docFormCM" action="/servlet/kr.co.kihyun.beans.totsys.doc.HttpFormContentModify" method="post">-->
<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="form"></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>
</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();
	}
%>
