
<%
/************************************************************@@
  * 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="kr.co.kihyun.beans.user.HttpSSOLogin"
	import="kr.co.kihyun.moumi.MoumiConfig"
	import="kr.co.kihyun.lang.MString" import="kr.co.kihyun.lang.MInteger"
	import="kr.co.kihyun.lang.MLong"
	import="kr.co.kihyun.beans.totsys.doc.Doc"
	import="kr.co.kihyun.text.html.ServletUtil"
	import="java.net.URLDecoder" import="kr.co.kihyun.lang.Encoder"
	import="kr.co.kihyun.beans.entity.*"
	import="javax.jdo.PersistenceManager" import="javax.jdo.Transaction"
	import="kr.co.kihyun.beans.entity.util.*"
%>

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

<%
PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
Transaction tx = pm.currentTransaction();
try{

	/*********** parameter value ***********/
	String usID = HttpSSOLogin.getLoginID(request);
	int sysAuth = HttpSSOLogin.getSysAuth(request);
	
	String docUserID = "";
	Long docID = MLong.parseLong(request.getParameter("docID"), null);
	String modify = MString.checkNull(request.getParameter("modify"));
	String docName = Encoder.toJava(MString.checkNull(request.getParameter("docName")));
	
	int accAuth = MInteger.parseInt(request.getParameter("accAuth"), 0);
	TotDoc totDoc = pm.getObjectById(TotDoc.class, docID);

	if(modify.equals("modify")){
		tx.begin();

		if(sysAuth == MoumiConfig.TOTPER && !usID.equals(totDoc.getUser(pm).getId())){
			out.println(ServletUtil.alert("정상적인 방법으로 이용해주시기 바랍니다."));
			out.println(ServletUtil.getJavaScript("parent.opener.window.location.reload();"));
			out.println(ServletUtil.getJavaScript("self.close();"));
			return;
		}

		totDoc.setName(docName);
		totDoc.setAccessAuth(AccessAuth.asAccessAuth(accAuth));
		pm.makePersistent(totDoc);

		tx.commit();

		out.println(ServletUtil.getJavaScript("parent.opener.window.location.reload();"));
		out.println(ServletUtil.getJavaScript("self.close();"));
	}
	docName = totDoc.getName();
	accAuth = totDoc.getAccessAuth().ordinal();
	docUserID = totDoc.getUser(pm).getId();
%>

<html>
<head>
<title><%=TotDocProcess.FORM%>테스트</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 saveform() {
				dform.modify.value = "modify";
				dform.submit();
			}

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

<table border="1px" class="kecttep_list_table" bordercolor="#e3e3e3"
	width="100%" cellpadding="0" cellspacing="0">
	<form name='dform' method='post' action='./popup_modify.jsp'><input
		type="hidden" name="docID" value="<%=docID %>"> <input
		type="hidden" name="modify" value=""> <!--- 표시작 ---->
	<tr valign="middle">
		<td align="left" nowrap class="kecttep_tdmenu"
			style="padding-left: 15;"><%=MoumiConfig.getMessageBundle().getString("moumi.message.doc")%>명</td>
		<td width="300" nowrap style="padding-left: 15;"
			class="kecttep_graytd"><input name="docName" type="text"
			class="inputtxt" STYLE="ime-mode: active; width: 98%"
			value="<%=docName%>"></td>
		<td width="120" align="left" nowrap class="kecttep_tdmenu"
			style="padding-left: 15;"><%=MoumiConfig.getMessageBundle().getString("moumi.message.doc")%>공개여부</td>
		<td style="padding-left: 15;" class="kecttep_graytd">
		<%if(accAuth == 0){%> <input name="accAuth" value="1" type="radio">공개
		<input name="accAuth" value="0" type="radio" checked>비공개 <%}else if(accAuth == 1){%>
		<input name="accAuth" value="1" type="radio" checked>공개 <input
			name="accAuth" value="0" type="radio">비공개 <%}%>
		</td>
	</tr>
	<!--- 표 끝 ----> <!--- 버튼(계산)----></form>
</table>

<table align="center">
	<tr height="10">
		<td></td>
	</tr>
	<tr>
		<%if(usID.equals(docUserID) || sysAuth == MoumiConfig.SYSADM){ %>
		<td><a href="#" onclick='saveform();'><img
			src="/totsys/common/images/bt_sub_form_modify.gif" border="0"></a></td>
		<td width="5"></td>
		<%}%>
		<td><a href="#" onclick='window.close();'><img
			src="/totsys/common/images/bt_cancel3.gif" border="0"></a></td>
	</tr>
</table>
</body>
</html>
<%
} catch (Exception ex) {
	ex.printStackTrace();
	ex.printStackTrace();
	out.println(ServletUtil.alert("변경이 실패 되었습니다."));
} finally {
	if(tx.isActive())
		tx.rollback();
	pm.close();
}
%>
