<%@page import="java.sql.ResultSet"%>
<%@page import="kr.co.kihyun.prop.QueryStringList"%>
<%@page import="kr.co.kihyun.db.CommonDBManager"%>
<%@page import="kr.co.kihyun.text.html.ServletUtil"%>
<%@page import="kr.co.kihyun.moumi.MoumiConfig"%>
<%@page import="kr.co.kihyun.beans.batch.UpdateNote"%>
<%    /**
     * **********************************************************@@ Program Name
     * : popup_recall_note.jsp Description	: /보고자/내문서함/임시보고함/임시보고 Author	: 조용준
     * Create Date	: 2004-11-09 History	:
     * @@***********************************************************
     */
%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="kr.co.kihyun.beans.user.HttpSSOLogin"%>
<%@ page import="kr.co.kihyun.lang.MString"
         import="kr.co.kihyun.lang.MLong"%>
<%@ page import="kr.co.kihyun.util.MUtil"%>
<%@ page import="kr.co.kihyun.moumi.Moumi"
         import="javax.jdo.PersistenceManager"
         import="kr.co.kihyun.beans.entity.util.*"
         import="javax.jdo.Transaction" import="kr.co.kihyun.beans.entity.*"
         import="kr.co.kihyun.service.*" import="kr.co.kihyun.service.vo.*"
         import="kr.co.kihyun.lang.Encoder"
         %>
<jsp:useBean id="userView" class="kr.co.kihyun.beans.user.UserView"	scope="page" />
<jsp:useBean id="reportView" class="kr.co.kihyun.beans.totsys.report.ReportView" scope="page" />
<jsp:useBean id="doc" class="kr.co.kihyun.beans.totsys.doc.Doc"	scope="page" />
<%@ include file="/totsys/common/inc/sec/secure.inc.jsp"%>
<%
String usID = HttpSSOLogin.getLoginID(request);

/**
 * ***** 보고자 정보 ********
 */
String deptID = "";
String deptName = "";
String userName = "";
String phone = "";
String email = "";
String docIdNum = "";

/**
 * ******** get parameter **********
 */
Long docID = MLong.parseLong(request.getParameter("docID"), null);
String reportID = request.getParameter("reportID");
String reportType = request.getParameter("reportType");
String procMode = request.getParameter("proc_mode");

/**
String query = QueryStringList.CheckMigulhamSql;
CommonDBManager cdb = new CommonDBManager();
ResultSet rs = cdb.execQuery(query, reportID);
boolean isMigulham = false;
if(rs.next()){
	isMigulham = true;
}
rs.close();
cdb.execClose();
*/
	PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
    Transaction tx = pm.currentTransaction();
    try {
        /**
         * ******** session내의 userId *********
         */

        if (MString.isNull(procMode)) {

            /**
             * ******* report view ******
             */
            userView.executeQuery(usID);
            deptID = userView.getDeptID();
            deptName = userView.getDeptName();
            userName = userView.getName();
            phone = userView.getPhone() == null ? " " : userView.getPhone();
            email = userView.getEmail() == null ? " " : userView.getEmail();

            String note = "";
            userView.getNoteReson(reportID);
            note = userView.getNote();
            docIdNum = userView.getDocId();

            Long docId = new Long(docIdNum);
            TotDocService docService = new TotDocService(pm);

%>



     <%--
     if(isMigulham){
     out.println(ServletUtil.alert(MoumiConfig.getMessageBundle().getString("moumi.message.tot_report.recogCancelWaitDuring")));


  <script language="javascript">
    self.close();
</script>
<%} %>
   --%>
<%
if (!docService.chkIfPossibleForReturn(docId) ) {
    out.println(ServletUtil.alert(MoumiConfig.getMessageBundle().getString("moumi.message.tot_report.noteAlert")));
%>
	<script language="javascript">
	    self.close();
	</script>
<%}%>
<html>
    <head>
        <title><%=Moumi.getTitle()%></title>
        <link rel="stylesheet" href="/totsys/common/css/text.css" type="text/css">
        <script src="/totsys/common/js/rollover.js"></script>
        <script type="text/javascript" src="/totsys/common/js/jquery-1.12.4.min.js"></script>
        <script language="javascript">
            function check() {
                opener.dform.comment.value = comment.value;
                <%
                    if (doc.isDynaTable(docID)) {
                        out.println("opener.modifyForm.comment.value = comment.value;");
                    }
                %>
                self.close();
            }

            function goUp() {
                document.setNote.submit();
            }

            $(document).ready(function() {
               resizeTo(620, 527);
            });
        </script>
    </head>
    <body style='' bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
        <form name="setNote" method="post">
            <input type="hidden" name="proc_mode" value="return_report" />
            <input type="hidden" name="userID" value="<%=usID%>" />
            <input type="hidden" name="docID" value="<%=reportID%>" />
            <input type="hidden" name="docIdNum" value="<%=docIdNum%>" />

            <table width="600" border="0" cellspacing="0" cellpadding="0" height="350">
                <tr>
                    <td width="29"><img src="images/popupt_top_left.gif" width="29" height="19"></td>
                    <td background="images/popupt_top_center.gif" height="19">&nbsp;</td>
                    <td width="30"><img src="images/popupt_top_right.gif" width="30" height="19"></td>
                </tr>
                <tr>
                    <td background="images/popupt_center_left.gif">&nbsp;</td>
                    <td valign="top">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <!--스타일시트-->
                            <link rel="stylesheet" href="/totsys/common/css/kecttep.css"
                                  type="text/css">
                            <!--타이틀-->
                            <tr>
                                <td style="padding-top: 10; padding-bottom: 10">
                                    <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 height="66" valign="top"
                                    style="padding-left: 10; padding-right: 10;">
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <!---- 작성자 정보  시작 ---->
                                        <tr>
                                            <td height="27" colspan="4">
                                                <img src="images/s_write_info.gif">
                                            </td>
                                        </tr>

                                        <!--테이블양식-->
                                        <tr>
                                            <td colspan="4">
                                                <table class="kecttep_list_table" border="0" bordercolor="#abbddd" width="100%"
                                                       cellpadding="0" cellspacing="0">
                                                    <tr>
                                                        <td width="100" class="kecttep_tdmenu">&nbsp;&nbsp;작성자명</td>
                                                        <td height="27" class="kecttep_last_graytd" style="padding-left: 10;"><%= userName%>&nbsp;</td>
                                                        <td width="100" class="kecttep_tdmenu">&nbsp;&nbsp;작성자 ID</td>
                                                        <td width="120" class="kecttep_last_graytd" height="27" style="padding-left: 10;"><%= usID%>&nbsp;</td>
                                                    </tr>
                                                    <tr>
                                                        <td width="100" class="kecttep_tdmenu">&nbsp;&nbsp;기관/부서명</td>
                                                        <td height="27" class="kecttep_last_graytd" style="padding-left: 10;"><%= deptName%>&nbsp;</td>
                                                        <td width="100" class="kecttep_tdmenu">&nbsp;&nbsp;전화번호</td>
                                                        <td height="27" class="kecttep_last_graytd" style="padding-left: 10;"><%= phone%>&nbsp;</td>
                                                    </tr>
                                                    <tr>
                                                        <td width="100" class="kecttep_tdmenu">&nbsp;&nbsp;E-MAIL</td>
                                                        <td height="27" class="kecttep_last_graytd" style="padding-left: 10;"><%= email%>&nbsp;</td>
                                                        <td width="100" class="kecttep_tdmenu">&nbsp;&nbsp;기타</td>
                                                        <td height="27" class="kecttep_last_graytd" style="padding-left: 10;">&nbsp;</td>
                                                    </tr>
                                                    <!---- 작성자 정보  끝 ---->
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td height="20" colspan="4">&nbsp;</td>
                                        </tr>
                                        <!---- 내용 시작 ---->
                                        <tr>
                                            <td colspan="4"><img src="images/s_write_contents.gif"></td>
                                        </tr>
                                        <tr>
                                            <td height="150" colspan="4" valign="top">
                                                <textarea name="comment" cols="70" rows="10" STYLE="ime-mode: active"></textarea>
                                            </td>
                                        </tr>
                                        <!---- 내용 끝 ---->
                                    </table>
                                </td>
                            </tr>
                        </table>
                        <br>
                        <!---- 확인,취소버튼 테이블 시작 ---->
                        <table border="0" cellspacing="0" cellpadding="0" align="center">
                            <tr>
                                <td>
                                    <a href="#" onclick="goUp();">
                                        <img name="bt_enter" border="0" src="/totsys/common/images/bt_ok.gif">
                                    </a>
                                </td>
                                <td width="10">&nbsp;</td>
                                <td>
                                    <a href="javascript:self.close();">
                                        <img name="bt_cancel3" border="0" src="/totsys/common/images/bt_cancle.gif">
                                    </a>
                                </td>
                            </tr>
                        </table>
                        <!---- 확인,취소버튼 테이블  끝 ----></td>
                    <td background="images/popupt_center_right.gif">&nbsp;</td>
                </tr>
                <tr>
                    <td><img src="images/popupt_bottom_left.gif" width="29"
                             height="24"></td>
                    <td background="images/popupt_bottom_center.gif" height="24">&nbsp;</td>
                    <td><img src="images/popupt_bottom_right.gif" width="30"
                             height="24"></td>
                </tr>
            </table>
        </form>
    </body>
</html>
<%
} else {
    String comment = clearXSS(Encoder.toJava(request.getParameter("comment")), null);
    Long reportId = new Long(reportID);

    tx.begin();
    TotReport report = pm.getObjectById(TotReport.class, reportId);
    MUser mUser = pm.getObjectById(MUser.class, usID);
    TotDoc totDoc = report.getTotDoc();
    TotReportService reportService = new TotReportService(pm);
    String autoRtnYn = totDoc.getAutoRtnYn();
    String modeMessage = MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.noteRecall");
    TotReportProcess prss = TotReportProcess.NOTE;      //14.회수요청
    if (autoRtnYn.equals("Y")) {
        prss = TotReportProcess.RETURN;     //3.재입력요청
        //modeMessage = MoumiConfig.getMessageBundle().getString("moumi.message.tot_report.process.return");
        modeMessage = MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.return.auto") + modeMessage;
    }
    reportService.procRecallReport(reportId, prss, comment, mUser);
    tx.commit();
%>
<html>
    <head>
        <script>
            /*
             * 윈도우 로딩 후 호출되는 함수
             * @returns {undefined}
             1*/
            function fn_onLoad() {
                alert("<%= modeMessage%> <%= MoumiConfig.getMessageBundle().getString("moumi.message.popup.process.complete")%>");
                        if (typeof (opener.fn_goToList) != "undefined")
                            opener.fn_goToList();
                        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();
    }
%>
