<%  /**
     * **********************************************************
     * @@ Program Name  : doc_modify.jsp
     * @@ Description	: /집계자/내문서함/등록함/기본정보 변경
     * @@ Author	: 기현테크
     * @@ Create Date	: 2010-11-21
     * @@ History	:
     * @@***********************************************************
     */
%>

<%@ page contentType="text/html; charset=UTF-8"
         import="java.net.URLEncoder"
         import="java.net.URLDecoder"
         import="java.util.List"
         import="kr.co.kihyun.beans.user.HttpSSOLogin"
         import="kr.co.kihyun.moumi.Moumi"
         import="kr.co.kihyun.lang.Encoder"
         import="kr.co.kihyun.lang.MInteger"
         import="kr.co.kihyun.lang.MString"
         import="kr.co.kihyun.moumi.doc.MDoc"
         import="kr.co.kihyun.beans.totsys.menu.MenuBean"
         import="kr.co.kihyun.service.ShareDocService"
         import="kr.co.kihyun.beans.entity.TotDoc"
         import="kr.co.kihyun.beans.entity.TotDocProcess"
         import="kr.co.kihyun.beans.entity.TotDocType"
         import="javax.jdo.PersistenceManager"
         import="javax.jdo.Transaction"
         import="kr.co.kihyun.beans.entity.util.*"
         import="kr.co.kihyun.lang.MLong"%>

<%@ 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);

        /**
         * **** Parameter *****
         */
        String docID = clearXSS(request.getParameter("docID"), "");
        String docType = clearXSS(request.getParameter("docType"), null);
        int strPage = MInteger.parseInt(request.getParameter("strPage"), 1);
        String findOption = clearXSS(request.getParameter("findOption"), "");
        String findWord = clearXSS(Encoder.toJava(request.getParameter("findWord")), "");
        String stDate = clearXSS(request.getParameter("stDate"),"");
        String edDate = clearXSS(request.getParameter("edDate"),"");

        String method = clearXSS(request.getParameter("method"), "");
        if (method.equals("GET")) {
            findWord = URLDecoder.decode(MString.checkNull(request.getParameter("findWord")), "UTF-8");
        }
//System.out.println("findWord = "+findWord);

        int userShareCount = 0;

        tx.begin();

        TotDoc totDoc = pm.getObjectById(TotDoc.class, MLong.parseLong(docID));
        String regID = totDoc.getUser(pm).getId();
        String docName = totDoc.getName();

        //싱글인 경우에만 조회한다.
        ShareDocService shareDoc = new ShareDocService(pm);
        List tmpList = shareDoc.getSearchDocIdType('N', docID, 'D');
        userShareCount = tmpList.size();


        tx.rollback();

        String redirectURI = "/totsys/totper/mydocbox/prssbox/doc_list.jsp?docType=" + docType;

        session.setAttribute("modifySuccTargetURI", "totper/mydocbox");
        session.setAttribute("modifyFailTargetURI", "/totsys/totper/mydocbox/prssbox/doc_modify.jsp?docID=" + docID);

        MenuBean modifyMenu     = new MenuBean(request, "/totsys/totper/mydocbox/prssbox/doc_modify.jsp?docID=" + docID + "&docType=" + docType);
        MenuBean reportsMenu    = new MenuBean(request, "/totsys/totper/mydocbox/prssbox/reports/report_list.jsp?docID=" + docID + "&docType=" + docType);
        MenuBean totReportsMenu = new MenuBean(request, "/totsys/totper/mydocbox/prssbox/tot_reports/total_reports.jsp?docID=" + docID + "&docType=" + docType);
//        MenuBean totReportMenu  = new MenuBean(request, "/totsys/totper/mydocbox/prssbox/tot_report/total_report.jsp?docID=" + docID + "&docType=" + docType);
%>

<!DOCTYPE html>
<html lang="ko">
	<head>
        <title><%=Moumi.getTitle()%></title>
		<meta charset="UTF-8">
        <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/tabs.css" type="text/css">
        <link rel="stylesheet" href="/totsys/common/css/SquareButtons.css" type="text/css">
        <link rel="stylesheet" href="/totsys/common/css/contentStyle.css" type="text/css">
		<link rel="stylesheet" href="/totsys/common/css/basic.css" type="text/css">
        <script src="/totsys/common/js/rollover.js"></script>
		<script src="/totsys/common/js/jquery-1.12.4.min.js"></script>
        <script>
        //연계문서이면 볼수있게
    if ('<%=regID%>' != '<%=usID%>' && '<%=sysAuth%>' == '<%=Moumi.TOTPER%>' && <%=docID%> < 1700000000) {
        alert("<%=Moumi.getMessageBundle().getString("moumi.message.popup.docModify")%>");
        location.replace('/totsys/totper/mydocbox/prssbox/doc_list.jsp?docType=<%=docType%>');
    }
        function userShareSelect() {
            var urlname = "";
            var height  = screen.height;
            var width   = screen.width;
            var leftpos = width / 2 - 350;
            var toppos  = height / 2 - 350;

            //docReportType:문서 구분(D:집계문서, R:제출문서)
            urlname = "/totsys/common/web/report_dept/popup_user_share_select.jsp?docID=<%=docID%>&docReportType=D&userYN=Y&selfDeptYn=N&exeFlag=form";
            post= window.open(urlname, "post","width=900, height=600, toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=" + leftpos + ",top=" + toppos);
            post.focus();
       }

        /*
         * 목록페이지로 이동처리하는 함수
         */
        function fn_goToList() {
            document.listForm.submit();
        }

    </script>
    </head>
    <body style="overflow: auto">
        <form name="listForm" method="post" action="./doc_list.jsp">
            <input type="hidden" name="docType"    value="<%= docType%>">
            <input type="hidden" name="strPage"    value="<%= strPage%>">
            <input type="hidden" name="findOption" value="<%= MString.checkNull(findOption)%>">
            <input type="hidden" name="findWord"   value="<%= MString.checkNull(findWord)%>">
            <input type="hidden" name="stDate"     value="<%= stDate %>">
            <input type="hidden" name="edDate"     value="<%= edDate %>">
        </form>

        <div>
            <table>
                <!-- top menu start -->
                   <jsp:include page="/totsys/common/inc/title/title.jsp" flush="true" >
                    <jsp:param value='<%= URLEncoder.encode(docName, "UTF-8")%>' name="desc" />
                </jsp:include>
                <!--jsp:include page="/totsys/common/inc/totper/top/top.jsp" flush="true" /-->
                <!-- top menu end -->
            </table>
        </div>
        <!--tap 시작-->
        <div id="header">
            <ul id="primary">
            <!-- ie10,11 에서 호환성 보기 문제 수정 a 태그에 스타일 추가 -->
                <li><span class="kecttep_menu_focous" style="padding: 0px; line-height: 25px;"><%= modifyMenu%></span></li>
                <li><a href="<%= reportsMenu.getUrl()%>" style="padding: 0px; line-height: 25px;"><%= reportsMenu%></a></li>
                <li><a href="<%= totReportsMenu.getUrl()%>" style="padding: 0px; line-height: 25px;"><%= totReportsMenu%></a></li>
            </ul>
        </div>
        <!--tap 끝-->

        <div id="main">
            <div id="contents">
                <table>
                     <tr class="toolbar">
                        <td colspan="4">
                            <table>
                                <tr>
                                    <td class="kecttep_button_td">
                                        <% if ("PRSS".equals(docType)) {%>
                                        <!-- 집계완료 button -->
                                        <a href="javascript:void(0);" onclick="endDoc();">
                                            <img src="/totsys/common/images/bt_totalok.gif" alt="<%= Moumi.getMessageBundle().getString("moumi.message.button_small.docEnd")%>" />
                                        </a>
                                        <%}%>
                                        <!-- 담당변경 button -->
<%--                                         <%if(  MLong.parseLong(docID) < 1700000000){ %> --%>
                                        <a href="javascript:void(0);" onclick="window.open('/totsys/repoper/mydocbox/returnbox/popup_rep_transfer6.jsp?boxName=returnbox&hideUser=false&docID=<%=docID%>&docReportType=D&exeFlag=form&docType=<%=docType%>&strPage=<%=strPage%>', '', 'width=572, height=680,toolbar=no, directories=no, status=no, menubar=no, resizable=no');">
                                            <img alt="담당변경" src="/totsys/common/images/bt_damdang.gif"  />
                                        </a>
<%--                                         <%}%> --%>
                                        <!-- 사용자공유 button : 2014.08.21 Add by KWON,HAN -->
                                        <a href="javascript:void(0);" onclick="javascript:userShareSelect();">
                                            <img src="/totsys/common/images/bt_user_share.jpg" alt="<%= Moumi.getMessageBundle().getString("moumi.message.tot_doc.user")%><%= Moumi.getMessageBundle().getString("moumi.message.tot_doc.share")%>" />
                                        </a>
                                         <span id="userShareCountText" class="center">
                                    <%
                                        if (userShareCount > 0) {
                                    %>
                                            <!-- 명의 사용자에게 공유되어 있습니다. -->
                                            <span style="color: #009999"><%=userShareCount%><%=Moumi.getMessageBundle().getString("moumi.message.popup.userShareCounter")%></span>
                                    <%
                                        }
                                    %> 
                                		</span>
                                        <!-- 목록 -->
                                    	<a href="javascript:void(0);" onclick="javascript:fn_goToList();">
                                            <img src="/totsys/common/images/bt_list.gif" alt="<%= Moumi.getMessageBundle().getString("moumi.message.button.boardList")%>" />
                                        </a>
                                       
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>

                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <!-- 문서 기본정보 변경 시작 -->
                    <jsp:include page="/totsys/common/inc/documents/tot_doc/base_info_modify.jsp" flush="true">
                        <jsp:param name="docID" value="<%= docID%>" />
                        <jsp:param name="docType" value="<%= docType%>" />
                        <jsp:param name="redirectURI" value='<%= redirectURI%>'/>
                    </jsp:include>
                </table>
            </div>
        </div>
        <!-- 문서 기본정보 변경 끝-->
	    <div id="SetWin" style="position: absolute; Visibility :hidden; width :100px; height :100px; background: silver; border: 1px #333333 solid; line-height: 1.4em; padding: 3px;"></div>
</body>
</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();
    }
%>
