<%    /**
     * **********************************************************
     * @@ Program Name     * : report_list.jsp
     * Description	: /보고자/내문서함/접수함/접수 문서 목록
     * Author	: 기현테크
     * Create Date	: 2010.11.26 History	:
     * @@***********************************************************
     */
%>
<%@ page contentType="text/html; charset=UTF-8"
         import="java.util.Calendar"
         import="java.util.Date"
         import="java.util.List"
         import="java.text.SimpleDateFormat"
         import="javax.jdo.PersistenceManager"
         import="javax.jdo.Transaction"
         import="kr.co.kihyun.beans.entity.*"
         import="kr.co.kihyun.beans.ecross.*"
         import="kr.co.kihyun.beans.entity.ecross.*"
         import="kr.co.kihyun.beans.entity.util.*"
         import="kr.co.kihyun.beans.user.HttpSSOLogin"
         import="kr.co.kihyun.lang.Encoder"
         import="kr.co.kihyun.lang.MString"
         import="kr.co.kihyun.lang.MInteger"
         import="kr.co.kihyun.moumi.Moumi"
         import="kr.co.kihyun.beans.entity.MUser"
         import="org.slf4j.Logger"
         import="org.slf4j.LoggerFactory"
         import="java.util.*"
         import="kr.co.kihyun.service.*"
         import="kr.co.kihyun.service.vo.*"
         %>
<%@page import="java.net.URLDecoder"%>
<%@page import="java.net.URLEncoder"%>
<%@ include file="/totsys/common/inc/sec/secure.inc.jsp"%>
<%//response.setBufferSize(1024*8);
//Logger LOG = LoggerFactory.getLogger(this.getClass());
    MPersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
    Transaction tx = pm.currentTransaction();

    try {
        /**
         * ******** session내의 userId *********
         */
        String usID = HttpSSOLogin.getLoginID(request);
        String dpID = HttpSSOLogin.getDeptID(request);

        String strPage = clearXSS(request.getParameter("strPage"), "");
        /**
         * ******** Parameter *********
         */
        String findOption = clearXSS(request.getParameter("findOption"), null);
        String findWord = clearXSS(Encoder.toJava(request.getParameter("findWord")), null);

        String method = clearXSS(request.getParameter("method"), "");

        if (method.equals("GET")) {
            findWord = URLDecoder.decode(MString.checkNull(request.getParameter("findWord")), "UTF-8");
        }
        //String uri = URLEncoder.encode("report_list.jsp?findOption="+MString.checkNull(findOption),"UTF-8")+"&method=GET";
        if(findWord != null){
        String[] filter_word= {"--", "\\(", "\\)", "\\'", "\\\""};
            for(int ii=0; ii< filter_word.length;ii++){
                findWord = findWord.replaceAll(filter_word[ii], "");
            }
        }
        int docNameLengthLimit = 50;

        tx.begin();

        String tmpMagam;

        int pageSize = 0;
        int currentPage = 0;
        int currentPageSetUp = 0;
        int recordSize = 15;

        if (strPage == null || strPage.length() <= 0) {
            currentPage = 1;
        } else if (strPage.equals("null")) {
            currentPage = 1;
        } else {
            try {
                currentPage = Integer.parseInt(strPage);
            } catch (NumberFormatException ex) {
                System.out.println(ex);
            }
        }

        //======================================================================
        MUser mUser = pm.getObjectById(MUser.class, usID);
        SysAuth sysAuth = mUser.getSysAuth();

        TotReportService reportService = new TotReportService(pm);
        //검색조건파라미터
        Map params = new HashMap();
        params.put("findOption", findOption);
        params.put("filterValue", findWord);
        params.put("userId", usID);
        params.put("deptId", dpID);
        params.put("sysAuth", sysAuth);

        //검색메인쿼리와 레코드갯수조회쿼리를 생성 후 멤버변수로 저장
        reportService.createAcceptReportListSearchQuery(params);

        //레코드갯수조회쿼리를 실행하여 레코드갯수를 구함
        int count = reportService.getCountFromMainQuery();

        if ((count % recordSize) == 0) {
            pageSize = (int) (count / recordSize);
        } else {
            pageSize = (int) (count / recordSize) + 1;
        }

        if (currentPage > pageSize) {
            currentPage = pageSize;
        }
        currentPageSetUp = (int) (currentPage / 10) * 10;
        if (currentPage % 10 == 0) {
            currentPageSetUp -= 10;
        }

        int startNo = (currentPage - 1) * recordSize + 1;
        int endNo = currentPage * recordSize;

        List list = null;

        //검색목록조회쿼리 실행
        if (count > 0) {
            //페이징처리를 위한 추가파라미터 설정
            reportService.getParams().put("startNo", startNo);
            reportService.getParams().put("endNo", endNo);

            //검색메인쿼리를 페이징처리를 위한 쿼리로 변환
            reportService.convertToPagenatingQuery();

            //만족하는 레코드가 존재하면 조회
            list = reportService.executeQuery(TotReportVO.class);
        }
        //======================================================================
        tx.rollback();

        SimpleDateFormat ymdFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar cal = Calendar.getInstance();

        String nowTime = "";
        nowTime = sdf.format(cal.getTime());
        Date nowDate = sdf.parse(nowTime);

%>
<!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/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/find.js"></script>
        <script src="/totsys/common/js/mouse.js"></script>
        <script>
            /*
             * 검색조건폼에 대한 submit처리함수
             * @param {type} p_findForm
             * @returns {Boolean}
             */
            function fn_onFindSubmit(p_findForm) {
                if (!findCheck(p_findForm))
                    return false;
                p_findForm.strPage.value = 1;
                return true;
            }
            /*
             * 페이지이동처리함수
             */
            function fn_goToPage(p_page) {
                document.findForm.strPage.value = p_page;
                document.findForm.submit();
            }

            /*
             * 상세보기페이지로 이동처리하는 함수
             * @param {type} p_reportId
             * @param {type} p_endDate
             * @param {type} p_submitDate
             * @returns {undefined}
             */
            function fn_goToView(p_prss, p_reportId, p_tmpStrMagam, p_tmpMagam) {
                document.viewForm.reportID.value = p_reportId;
                document.viewForm.tmpStrMagam.value = p_tmpStrMagam;
                document.viewForm.tmpMagam.value = p_tmpMagam;
                if (p_prss == 0) {      //접수
                    document.viewForm.action = "/totsys/repoper/mydocbox/tempbox/report_regist.jsp";
                } else if (p_prss == 3) {   //재입력요청
                    document.viewForm.action = "./return_report_modify.jsp";
                }
                document.viewForm.submit();
            }
        </script>
    </head>
    <body>
        <form name="viewForm" method="post">
            <input type="hidden" name="reportID" value="">
            <input type="hidden" name="type" value="returndoc">
            <input type="hidden" name="totperInfo" value="true">
            <input type="hidden" name="tmpStrMagam" value="">
            <input type="hidden" name="tmpMagam" value="">
            <input type="hidden" name="strPage" value="<%= currentPage%>">
            <input type="hidden" name="findOption" value="<%=MString.checkNull(findOption)%>">
            <input type="hidden" name="findWord" value="<%=MString.checkNull(findWord)%>">
        </form>
        <table style="height: 70px;">
            <%--<jsp:include page="/totsys/common/inc/repoper/top/top.jsp" flush="true" />--%>
            <tr>
                <td style="width: 0"></td>
                <td>
                    <table>
                        <jsp:include page="/totsys/common/inc/title/title.jsp" flush="true" />
                        <tr>
                            <td>
                                <table>
                                    <tr class="toolbar">
                                        <td>
                                            <table>
                                                <tr>
                                                    <td>
                                                        <form name="findForm" method="post" action="./report_list.jsp" onsubmit="return fn_onFindSubmit(this);" style="margin: 0px;">
                                                            <input type="hidden" name="strPage" value="<%= currentPage%>">
                                                            <select name="findOption" class="inputtxt" onchange="showMSG(this.options[this.selectedIndex].value, msg)">
                                                                <option value="totDoc.name"<%= "totDoc.name".equals(findOption) ? " selected" : ""%>><%= Moumi.getMessageBundle().getString("moumi.message.tot_doc.doc")%><%= Moumi.getMessageBundle().getString("moumi.message.tot_doc.name")%></option>
                                                                <option value="totDoc.executionCode"<%= "totDoc.executionCode".equals(findOption) ? " selected" : ""%>><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.executionCode")%></option>
                                                                <option value="totDoc.mUser.name"<%= "totDoc.mUser.name".equals(findOption) ? " selected" : ""%>>집계요청자</option>
                                                            </select>
                                                            <input name="findWord" value="<%= MString.checkNull(findWord)%>" type="text" class="inputtxt" size="30" maxlength="30px;" style="ime-mode: active;" />
                                                            <input type="image" src="/totsys/common/images/bt_search_inquiry2.gif"	border="0" align="middle" style="MARGIN: 0px 0px 0px 0px">
                                                        </form>
                                                    </td>
                                                    <td><span id="msg" class="kecttep_date_search"
                                                              style='display: none; padding-top: 5'>&nbsp;&nbsp;<%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.daySearchForm")%></span></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>

                        <tr>
                            <td style="height: 31px;/ vertical-align: top;"><!--  내용 -->
                                <table class="kecttep_list_table">
                                    <tr style="padding-top: 3px; vertical-align: middle;">
                                        <td class="kecttep_tdmenu" style="width: 60px; text-align: center">
                                            <%=Moumi.getMessageBundle().getString("moumi.message.tot_report.section")%>
                                        </td>
                                        <td style="width: 130px;" class="kecttep_tdmenu center"><%= Moumi.getMessageBundle().getString("moumi.message.tot_doc.executionCode")%></td>
                                        <td class="kecttep_tdmenu center"><%= Moumi.getMessageBundle().getString("moumi.message.tot_doc.doc")%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.name")%></td>
                                        <td style="width: 150px;" align="center" class="kecttep_tdmenu center"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.request")%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.coporation")%></td>
                                        <td style="width: 97px;" align="center" class="kecttep_tdmenu center"><%=TotDocType.TOT_DOC%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.request")%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.person")%></td>
                                        <td style="width: 105px;" align="center" class="kecttep_tdmenu center" rowspan="1"><%=Moumi.getMessageBundle().getString("moumi.message.tot_report.submit")%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.person")%></td>
                                        <td style="width: 97px;" align="center" class="kecttep_tdmenu center"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.startDate")%></td>
                                        <td style="width: 125px;" align="center" class="kecttep_tdmenu center"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.endDate")%></td>
                                        <td style="width: 97px;" align="center" class="kecttep_last_tdmenu center"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.remark")%></td>
                                    </tr>
                                    <%
                                        if (count > 0) {
                                            int listCount = list.size();
                                            for (int i = 0; i < listCount; i++) {
                                                TotReportVO reportVO = (TotReportVO) list.get(i);
                                                String tmpMoumiAcptLimitStrategy = Integer.toString(reportVO.getSubmitLimitCnt());
                                                String tmp2 = null;
                                                String tstr = "시";
                                                String tcnt;
                    //선착순 집계의 현재 제출수, 총집계수를 출력하도록 수정. 2014.11.26 by YOUNGJUN,CHO
                                                //tcnt = "("+Integer.toString(reportVO.getSubmitLimitCnt())+"개 기관)";
                                                tcnt = "<br /><span title='총 " + Integer.toString(reportVO.getSubmitLimitCnt()) + " 개 기관 중 " + Integer.toString(reportVO.getCompleteReportCount()) + " 개 기관에서 제출하였습니다.'>제출기관  (" + Integer.toString(reportVO.getCompleteReportCount()) + " / " + Integer.toString(reportVO.getSubmitLimitCnt()) + ")" + "</span>";
                                                if (tmpMoumiAcptLimitStrategy.equals("0")) {
                                                    tmp2 = new SimpleDateFormat("yyyy-MM-dd HH").format(reportVO.getEndDate());
                                                    tcnt = "";
                                                } else {
                                                    tmp2 = Moumi.getMessageBundle().getString("moumi.message.tot_doc.endBySubmitTotal");                        //선착순집계
                                                    tstr = "";
                                                }
                                                if (tmp2.contains("9999-12-30")) {
                                                    tmp2 = Moumi.getMessageBundle().getString("moumi.message.tot_doc.docGethering");  //집계진행중
                                                }
                                                if (tmp2.equals(Moumi.getMessageBundle().getString("moumi.message.tot_doc.docGethering"))) {
                                                    tstr = "";            //집계진행중
                                                }
                                                tmpMagam = tmp2;
                                    %>
                                    <tr style="padding-top: 3px; vertical-align: middle;"
                                        onmouseover="this.style.backgroundColor = 'F9F9F9'"
                                        onmouseout="this.style.backgroundColor = 'white'" bgColor=#ffffff>
                                        <td class="kecttep_graytd center" style="height: 25px; width: 60px;">
                                            <%
                                        // 2014.09.23 by youngjun cho (문서 구분방식에 따라 색상차별화 추가)
                                        if (reportVO.isPeriodicalDoc() && reportVO.isDocCollection()) {%>
                                            <span class="kecttep_doc_append_type kecttep_doc_append_type_periodical_collection"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.create.periodical") + "/" + Moumi.getMessageBundle().getString("moumi.message.tot_doc.collection")%></span>
                                            <%} else if (reportVO.isPeriodicalDoc() && !reportVO.isDocCollection()) {%>
                                            <span class="kecttep_doc_append_type kecttep_doc_append_type_periodical_file"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.create.periodical") + "/" + Moumi.getMessageBundle().getString("moumi.message.tot_doc.file")%></span>
                                            <%} else if (!reportVO.isPeriodicalDoc() && reportVO.isDocCollection()) {%>
                                            <span class="kecttep_doc_append_type kecttep_doc_append_type_random_collection"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.create.random") + "/" + Moumi.getMessageBundle().getString("moumi.message.tot_doc.collection")%></span>
                                            <%} else if (!reportVO.isPeriodicalDoc() && !reportVO.isDocCollection()) {%>
                                            <span class="kecttep_doc_append_type kecttep_doc_append_type_random_file"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.create.random") + "/" + Moumi.getMessageBundle().getString("moumi.message.tot_doc.file")%></span>
                                            <%}%>
                                            <%--<%= reportVO.isPeriodicalDoc() ? Moumi.getMessageBundle().getString("moumi.message.tot_doc.create.periodical") : Moumi.getMessageBundle().getString("moumi.message.tot_doc.create.random") %>/<%= reportVO.isDocCollection() ? Moumi.getMessageBundle().getString("moumi.message.tot_doc.collection") : Moumi.getMessageBundle().getString("moumi.message.tot_doc.file")%>--%>
                                        </td>
                                        <!-- 문서번호 -->
                                        <td style="width: 130px; height: 25px; text-align: center;" class="kecttep_graytd"><%=MString.checkNull(reportVO.getExecCode())%>&nbsp;</td>
                                        <!-- 문서명 -->
                                        <%
                                            int tmpb = -1;
                                            String iid = reportVO.getUserId();
                                            if (iid != null) {
                                                if (iid.equals(usID)) {
                                                    tmpb = 1;
                                                } else {
                                                    tmpb = 0;
                                                }
                                            } else {
                                                tmpb = -1;
                                            }
                                        %>
                                        <%if (tmpb == 1 || tmpb == -1 || sysAuth.equals(SysAuth.SUB_SYSADM) || sysAuth.equals(SysAuth.SUB_TOTADM) || sysAuth.equals(SysAuth.SYSADM) || sysAuth.equals(SysAuth.REPOADM)) {%>    <!--제출자아이디와 파라미터로받아온 값 비교 같으면 링크 sysAuth값 5,7,9 이면 링크-->
                                        <%if (reportVO.getPrss() == 3) {%> <!--TotReportProcess.RETURN = 재입력요청 상태값 3-->
                                        <td class="kecttep_graytd">&nbsp;&nbsp;
                                            <%-- if (reportVO.getDownDocId() == 0) {--%>

                                            <a onmouseover="balloon_on('<%=  MString.getEllipsis(reportVO.getDocName(), docNameLengthLimit)%>', this, 10, 4)"  onmouseout="balloon_off()" href="javascript:fn_goToView(<%= reportVO.getPrss()%>, '<%= reportVO.getId()%>', '', '');">
                                                <span style="color:blue;">
                                                <%= MString.getEllipsis(reportVO.getDocName(), docNameLengthLimit)%>
                                                </span>
                                            </a>

                                            <%-- } else {%>

                                            <a onmouseover="balloon_on('<%=reportVO.getDocName()%>', this, 10, 4)"  onmouseout="balloon_off()" href="./report_view.jsp?reportID=<%= reportVO.getId()%>&type=returndoc&totperInfo=true&tmpStrMagam=<%=tmpMagam%>&tmpMagam=<%=tmpMagam%>">
                                                <font color="<%if (reportVO.getEndDate().getTime() < nowDate.getTime()) {%>red<%} else {%>blue<%}%>">
                                                <%= MString.getEllipsis(reportVO.getDocName(), docNameLengthLimit)%>
                                                </font>
                                            </a>

                                        <% } --%>
                                        </td>
                                        <%} else if (reportVO.getPrss() == 0) {%> <!--TotReportProcess.ACCEPT = 접수 상태값 0-->
                                        <td class="kecttep_graytd">&nbsp;&nbsp;
                                            <a onmouseover="balloon_on('<%=  MString.getEllipsis(reportVO.getDocName(), docNameLengthLimit)%>', this, 10, 4)"  onmouseout="balloon_off()"
                                               href="javascript:fn_goToView(<%= reportVO.getPrss()%>, '<%= reportVO.getId()%>', '', '');">
                                                <span style="color:blue;">
                                                <%= MString.getEllipsis(reportVO.getDocName(), docNameLengthLimit)%>
                                                </span>
                                            </a>
                                        </td>
                                        <%}%>
                                        <%}else{%>
                                        <td class="kecttep_graytd" onmouseover="balloon_on('<%=  MString.getEllipsis(reportVO.getDocName(), docNameLengthLimit)%>', this, 10, 4)"  onmouseout="balloon_off()">&nbsp;&nbsp;
                                                <span style="color:blue;">
                                                <%= MString.getEllipsis(reportVO.getDocName(), docNameLengthLimit)%>
												</span>
                                        </td>
                                        <%}%>
                                        <!-- 요청기관/부서 -->
                                        <td style="width: 150px; text-align: center;" class="kecttep_graytd"><%= MString.checkNull(reportVO.getDeptName())%></td>
                                        <!-- 집계요청자 -->
                                        <td style="width: 97px; text-align: center;" class="kecttep_graytd"><%= MString.checkNull(reportVO.getDocOwnerName())%></td>
                                        <!-- 제출자 -->
                                        <td style="width: 105px; text-align: center;" class="kecttep_graytd">
                                            <% if (reportVO.getUserId() != null) {%>
                                            <%= MString.checkNull(reportVO.getOwnerName())%><br>(<%=MString.checkNull(reportVO.getUserId())%>)</td>
                                            <%} else {%>
                                        &nbsp;
                                        <%}%>
                                        <!-- 시작일 -->
                                        <td style="width: 97px; text-align: center;" class="kecttep_graytd"><%=ymdFormat.format(reportVO.getStartDate())%></td>
                                        <!-- 종료일 -->
                                        <td style="width: 125px; text-align: center;" class="kecttep_graytd">
                                            <%
                                                out.write(tmp2 + tstr + tcnt);
                                            %>
                                        </td>
                                        <!-- 비고 -->
                                        <td style="width: 97px; text-align: center;"  class="kecttep_last_graytd">
                                            <%if (reportVO.getPrss() == 3) {%>
                                            <%=TotReportProcess.RETURN%>
                                            <%}%>&nbsp;
                                        </td>
                                    </tr>
                                    <%
                                            }       //end of for list
                                        }       //end of if( count > 0)
                                    %>
                                </table>
                            </td>
                        </tr>

                        <tr>
                            <td style="height: 15px;"></td>
                        </tr>
                        <%if (count > 0) {%>
                        <tr style="padding-top: 3px; vertical-align: middle;">
                            <td class="kecttep_board" colspan="13" align="center"><!----------------- 페이지수 나오는 부분 시작 ----------------->
                                <jsp:include page="/totsys/common/inc/board/page_module.jsp" flush="true">
                                    <jsp:param name="pageFunction" value="fn_goToPage" />
                                    <jsp:param name="pageSize" value="<%= pageSize%>" />
                                    <jsp:param name="currentPage" value="<%= currentPage%>" />
                                    <jsp:param name="currentPageSetUp" value="<%= currentPageSetUp%>" />
                                </jsp:include> <!----------------- 페이지수 나오는 부분 끝 ----------------->
                            </td>
                        </tr>
                        <%} else {%>
                        <tr>
                            <td class="kecttep_none_tdmenu" colspan="7" style="height: 25px; text-align: center;">
                            	<%=Moumi.getMessageBundle().getString("moumi.message.tot_report.notSubmitDoc")%>
                            </td>
                        </tr>
                        <%}%>
                        <input type="hidden" name="tmpFind" id="tmpFind"
                               value="<%=MString.checkNull(findOption)%>">
                        <script>
                            if (tmpFind.value == "totDoc.name") {
                                findForm.findOption.selectedIndex = 0;
                            } else if (tmpFind.value == "totDoc.mDept.name") {
                                findForm.findOption.selectedIndex = 1;
                            } else if (tmpFind.value == "totDoc.mUser.name") {
                                findForm.findOption.selectedIndex = 2;
                            } else if (tmpFind.value == "totDoc.startDate") {
                                findForm.findOption.selectedIndex = 3;
                            } else if (tmpFind.value == "totDoc.repoEndDate") {
                                findForm.findOption.selectedIndex = 4;
                            }
                        </script>
                    </table>
                </td>
                <td style="width: 10px;"></td>
            </tr>

            <!-- top menu start -->
            <%--<%@ include file="/totsys/common/inc/buttom/buttom.jsp"%>--%>
            <!-- top menu end -->
        </table>
    </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();
    }
%>
