<%@page import="java.util.ArrayList"%>
<%    /**
     * **********************************************************@@ Program Name
     * : popup_inform_preview.jsp Description	: 집계문서 미리보기(등록과, 변경에서 같이 사용 Author
     * : 기현테크 Create Date	: 2010.11.25 History	:
     * @@***********************************************************
     */
%>
<%@ page contentType="text/html; charset=UTF-8" import="java.util.Date"
         import="java.util.List"
         import="java.text.SimpleDateFormat"
         import="java.net.URLEncoder"
         import="java.sql.Clob"
         import="java.sql.Blob"
         import="java.net.URLDecoder"
         import="kr.co.kihyun.beans.user.HttpSSOLogin"
         import="kr.co.kihyun.util.MDate" import="kr.co.kihyun.lang.MString"
         import="kr.co.kihyun.lang.MInteger" import="kr.co.kihyun.lang.MLong"
         import="kr.co.kihyun.lang.Encoder" import="kr.co.kihyun.moumi.MoumiConfig"
         import="kr.co.kihyun.moumi.doc.MDoc" import="kr.co.kihyun.moumi.Moumi"
         import="kr.co.kihyun.moumi.report.MReport"
         import="kr.co.kihyun.service.*"
         import="kr.co.kihyun.beans.user.User"
         import="kr.co.kihyun.beans.user.Dept"
         import="kr.co.kihyun.beans.totsys.report.Report"
         import="kr.co.kihyun.beans.totsys.doc.Doc"
         import="javax.jdo.PersistenceManager" import="javax.jdo.Transaction"
         import="kr.co.kihyun.beans.entity.util.*"
         import="kr.co.kihyun.beans.entity.*"
         import="org.slf4j.Logger"
         import="org.slf4j.LoggerFactory"
         import="javax.jdo.Query"
         %>
<%@page import="java.net.URLDecoder"%>
<%@ include file="/totsys/common/inc/sec/secure.inc.jsp"%>
<%    PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
    Transaction tx = pm.currentTransaction();

    try {
        request.setCharacterEncoding("UTF-8");
        Logger LOG = LoggerFactory.getLogger(this.getClass());
        /**
         * ******** session내의 userId *********
         */
        String usID = HttpSSOLogin.getLoginID(request);
        int sysAuth = HttpSSOLogin.getSysAuth(request);
        String dpID = HttpSSOLogin.getDeptID(request);
        String docType = clearXSS(request.getParameter("docType"), null);

        String docID = clearXSS(request.getParameter("docID"), null);
        String id = clearXSS(request.getParameter("id"), "");
        String user_id = clearXSS(request.getParameter("user_id"), "");
        String procMode = clearXSS(request.getParameter("proc_mode"), "");

        String getNote = null;
        NoteData notedata = new NoteData();
        notedata.getNoteReson(docID, id, user_id);

        if (MString.isNull(procMode)) {

            int getCount;



            getCount = notedata.getCount();
            getNote = clearXSS(notedata.getNote(),"");

            String reportID = docID;

%>
<html>
    <head>
        <title>자료회수승인</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() {
                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;
                }
                opener.dform.action = '/servlet/kr.co.kihyun.beans.totsys.doc.HttpDocFormModifyer';
                opener.dform.target = '_self';
                opener.dform.submit();
                window.close();
            }

            function closeWin()
            {
                window.close();
            }

            function goAccept()
            {
                document.acceptNote.submit();
            }

            function goRestore()
            {
                if(confirm("해당자료의 자료회수요청건을 반려 하시겠습니까?")){
                    document.restore.submit();
                }else{
                    alert("취소되었습니다.");
                    return;
                }
            }
        </script>
    </head>
    <div id="SetWin" style="position: absolute; Visibility: hidden; width: 100px; height: 100px; background: silver; border: 1px #333333 solid; 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="restore" method="post">
            <input type="hidden" name="userID" value="<%=user_id%>"/>
            <input type="hidden" name="id" value="<%=id%>"/>
            <input type="hidden" name="proc_mode" value="restore"/>
        </form>
        <!-- 반려기능 끝-->

        <form name="acceptNote" method="post">
            <input type="hidden" name="userID" value="<%=user_id%>"/>
            <input type="hidden" name="id" value="<%=id%>"/>
            <!-- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
            <input type="hidden" name="proc_mode" value="acceptNote"/>
            <!-- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
            <table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                    <td nowrap width="29" height="19" background="/totsys/common/web/documents/tot_doc/images/popupt_top_left.gif"></td>
                    <td background="/totsys/common/web/documents/tot_doc/images/popupt_top_center.gif" height="19">&nbsp;</td>
                    <td nowrap width="30" height="19" background="/totsys/common/web/documents/tot_doc/images/popupt_top_right.gif"></td>
                </tr>
                <tr>
                    <td background="/totsys/common/web/documents/tot_doc/images/popupt_center_left.gif">&nbsp;</td>
                    <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">

                                        <!--타이틀-->
                                        <tr>
                                            <td style="padding-top: 10px; padding-bottom: 10px">
                                                <table width="100%" height="29" border="0" cellpadding="0" cellspacing="0">
                                                    <tr>
                                                        <td width="39" background="images/title1.gif">&nbsp;</td>
                                                        <td class="kecttep_title" background="images/titlebg.gif">자료회수요청 사유</td>
                                                        <td width="13" background="images/title2.gif">&nbsp;</td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <!--타이틀 끝-->

                                        <tr>
                                            <td valign="top">
                                                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                    <form name='dform' method='post' action=''><!--- 표시작 ---->
                                                        <tr valign="top">
                                                            <td align="left" valign="top">
                                                                <TEXTAREA NAME="note" COLS=50 ROWS=6 readonly="readonly"><%=getNote%></TEXTAREA>
                                                            </td>
							</tr>
							<!--- 표 끝 ---->
                            <!--- 버튼(계산)---->
							<tr height="10">
                                                            <td></td>
							</tr>
							<tr valign="middle">
                                                            <td align="center">
                                                                <a href="#" onclick="goAccept();">
                                                                    <img name="bt_enter" border="0" src="/totsys/common/images/bt_recallRestore_approve.jpg">
                                                                </a>
                                                                &nbsp;
                                                                <a href="#" onclick="goRestore();">
                                                                    <img name="bt_restore" border="0" src="/totsys/common/images/bt_recallRestore_cancel.jpg">
                                                                </a>
                                                                &nbsp;
                                                                <a href="javascript:self.close();">
                                                                    <img name="bt_cancel3" border="0" src="/totsys/common/images/bt_close_new.jpg">
                                                                </a>
                                                           </td>
                              <!--//
							    <td align="left" valign="top">
                                  <a href="#" onclick="goAccept();">승인하기</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="closeWin()">닫기</a>
							    </td>
                             //-->
							</tr>
							<tr valign="middle">
								<td align="center"></td>
							</tr>
						  </form>
						</table>
						</td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
	</td>
	<td background="/totsys/common/web/documents/tot_doc/images/popupt_center_right.gif">&nbsp;</td>
	</tr>
	<tr>
		<td nowrap height="24" background="/totsys/common/web/documents/tot_doc/images/popupt_bottom_left.gif"></td>
		<td background="/totsys/common/web/documents/tot_doc/images/popupt_bottom_center.gif" height="24">&nbsp;</td>
		<td background="/totsys/common/web/documents/tot_doc/images/popupt_bottom_right.gif"></td>
	</tr>
</table>
</form>
</body>
</html>
<%
        }else{
//             String comment = clearXSS(Encoder.toJava(request.getParameter("comment")), null);
            String comment = clearXSS(notedata.getNote(),"");
            MUser mUser = pm.getObjectById(MUser.class, usID);
            Long reportId = new Long(id);

            tx.begin();
            TotReport report = pm.getObjectById(TotReport.class, reportId);
            TotDoc totDoc = report.getTotDoc();
            TotReportService reportService = new TotReportService(pm);

            TotReportProcess prss = null;

            if(procMode.equals("acceptNote")){            // 확인버튼 클릭시 - 회수요청을 승인
                prss = TotReportProcess.RETURN;        // 3.재입력요청
            }else{                                                   // 반려버튼 클릭시 - 회수요청을 반려(제출완료상태로 변경)
                prss = TotReportProcess.COMP;           // 6.제출완료
            }
			
            reportService.procRecallReport(reportId, prss, comment, mUser);
            tx.commit();
%>
<html>
    <head>
        <script>
            /*
             * 윈도우 로딩 후 호출되는 함수
             * @returns {undefined}
             1*/
            function fn_onLoad() {
                if (typeof (opener.fn_goToList) != "undefined"){
                   alert( "<%=MoumiConfig.getMessageBundle().getString("moumi.message.popup.process.complete")%>");
                }
                    var changeReportID = <%=reportId%>;
                    opener.prssChange.changeReportID.value = changeReportID;
                    opener.prssChange.changePrss.value = "note";
                    opener.prssChange.submit();
                    self.close();
            }
                    window.onload = fn_onLoad;
        </script>
    </head>
</html>
<%
        }
    } catch (Exception ex) {
        ex.printStackTrace();
//	out.println(kr.co.kihyun.text.html.ServletUtil.getJavaScript("location='/servlet/kr.co.kihyun.beans.user.HttpSSOLogin?mode=logout';"));
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
%>
