
<%
            /************************************************************@@
             * Program Name	: list.jsp
             * Description		: /집계자/공지사항
             * Author				: 강원중
             * Create Date		: 2004.10.11
             * History				:
            @@************************************************************/
%>
<%@ page contentType="text/html; charset=UTF-8" import="java.util.Date"
         import="java.net.URLEncoder" import="java.util.List"
         import="kr.co.kihyun.lang.MString" import="kr.co.kihyun.lang.MInteger"
         import="kr.co.kihyun.util.MDate"
         import="kr.co.kihyun.text.html.TagFilter"
         import="kr.co.kihyun.lang.MLong" import="javax.jdo.PersistenceManager"
         import="javax.jdo.Transaction"
         import="kr.co.kihyun.beans.entity.util.*"
         import="kr.co.kihyun.beans.entity.*"%>
<%@ page import="java.util.Map.Entry"%>
<%@ page import="java.util.List"%>
<%@ page import="kr.co.kihyun.text.html.ServletUtil"%>
<%@ page import="kr.co.kihyun.moumi.Moumi"%>
<%@ page import="kr.co.kihyun.lang.StringConverter"%>
<%@ page import="kr.co.kihyun.beans.user.HttpSSOLogin"%>
<%@ include file="/totsys/common/inc/sec/secure.inc.jsp"%>
<%            PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
            Transaction tx = pm.currentTransaction();
            try {
                /****** Parameter ******/
                Long docID = MLong.parseLong(request.getParameter("docID"));
                String boardGroupID = Category.ID_TOT_DOC_COMMENT;
                String url = clearXSS(request.getParameter("url"), "");
                int sysAuth;

                if (url == null) {
                    url = "";
                }

                TotDoc totDoc = pm.getObjectById(TotDoc.class, docID);
                Category category = pm.getObjectById(Category.class, boardGroupID);
                List<Board> boardList = totDoc.getBoards(pm, category);

                if (boardList.size() < 1) {
//		return;
                }
%>
<%
    /*********** User HttpSSOLogin check ***********/
    if (!HttpSSOLogin.isLogin(request)) {
        String connURL = "opener.location='/totsys/login/login.jsp';";
        out.println(ServletUtil.getJavaScript(connURL));
        out.println(ServletUtil.getJavaScript("window.close();"));
        return;
    }

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

    /*********** Parameter values ***********/
    Long boardID = null;

    if (boardList.size() > 0) {
        boardID = boardList.get(0).getId();
    }
    /*********** Board View vlaues ***********/
    Board board = null;
    String regID = "";
    String boardContents = "";
    String usrFilenames = "";
    String svrFilenames = "";
    int visit = 0;

    if (boardList.size() > 0) {
        tx.begin();
        board = boardID == null ? null : pm.getObjectById(Board.class, boardID);
        regID = board.getUser(pm) == null ? null : board.getUser(pm).getId();
        boardContents = TagFilter.convertSpace(board.getContents());
        for (Entry<String, List<Byte>> entry : board.getAttachments().entrySet()) {
            usrFilenames += entry.getKey() + ";";
            svrFilenames += entry.getKey() + ";";
        }
        docID = board.getTotDoc() == null ? null : board.getTotDoc().getId();
        boardGroupID = board.getCategory().getId();
        visit = board.getVisit();
        board.setVisit(visit + 1);
        pm.makePersistent(board);
        tx.commit();
    }
    /****** Doc list data get ******/
    String docName = totDoc.getName();

    /*********** append file name vlaues ***********/
    String[] usrFilenameList = usrFilenames.split(";");
    String[] svrFilenameList = svrFilenames.split(";");

    /****** 본인 유무 처리 ******/
    boolean isManager = false;
    if (usID.equals(regID)) {
        isManager = true;
    }

    /***** 버튼 처리 ******/
    String buttonPrss = (String) session.getAttribute("homeTagetURL");
%>
<SCRIPT>
    function opener(url, width, height) {
        var leftpos = (screen.width - width) / 2;
        var toppos = (screen.height - height) / 2;
        post= window.open(url, "post","width="+width+", height="+height+", toolbar=no,menubar=no,status=no,location=no,scrollbars=no,resizable=no,directories=no,left=" + leftpos + ",top=" + toppos);
        post.focus();
    }
			
</SCRIPT>
<tr>
    <td colspan="4">
        <table border="0" width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td style="width: 14"><img src="/totsys/common/images/ico_1.gif"></td>
                <td class="kecttep_title" style="padding-left: 5" align="left"
                    width="150">[입력요령 및 관련<%=Moumi.getMessageBundle().getString("moumi.message.doc")%>]</td>
                <td class="kecttep_div_show"><span id="listshow"
                                                   style="display: none;"><a href="#" class="textbutton"
                                              onclick="listView('list2','listshow','listnone');">보기</a></span><span
                        id="listnone"><a href="#" class="textbutton"
                                     onclick="listView('list2','listshow','listnone');">숨기기</a></span></td>
                <td>&nbsp;</td>
            </tr>
        </table>
    </td>
</tr>
<!----- 첨부파일 시작 ---->
<tr>
    <td bgcolor="#FFFFFF" valign="bottom" colspan="2">
        <div id="list2" style="display: '';">
            <table width="100%" border="0" cellspacing="0" cellpadding="0"
                   align="center">
                <%
                    int i = 0;
                    for (i = 0; i < svrFilenameList.length; i++) {
                        if (svrFilenameList[i] != null && !svrFilenameList[i].equals("")) {
                %>
                <tr>
                    <td class="body" height="17" style="padding-left: 20; padding-top: 4"><font
                            color="#FF6600"><b>+</b><%= Moumi.getMessageBundle().getString("moumi.message.file")%>
                            <%= (i + 1)%></font>&nbsp;&nbsp; <a
                            href="/servlet/kr.co.kihyun.text.html.HttpViewer?saveAs=<%=URLEncoder.encode(usrFilenameList[i], "UTF-8")%>&fileName=<%=URLEncoder.encode(svrFilenameList[i], "UTF-8")%>&docID=<%=docID%>"
                            target="hiddenIframe"><%= usrFilenameList[i]%></a></td>
                </tr>
                <%
                        }
                    }
                %>
            </table>
        </div>
    </td>
</tr>
<!----- 첨부파일 끝 ---->
<tr>
    <td colspan="4" valign="top">
        <table border="0" width="100%" cellpadding="0" cellspacing="0">
            <%
                if (boardList.size() > 0) {

            %>
            <tr align="right" style="padding-top: 3;">
                <!--  집계자 본인일때만 글쓰기 가능-->
                <td colspan="5" style="padding-right: 10;">
                    <%									if (url.equals("prss") | url.equals("reg")) {%> <!--<a href="#" onclick="opener('/totsys/common/inc/board/doc/popup_write.jsp?docID=<%=docID%>&boardGroupID=<%=boardGroupID%>','538','544');">
													<img src="./images/bt_notice_write.gif"  border="0"></a>-->
                    <%									}%> <script src="/totsys/common/js/rollover.js"></script> <SCRIPT
                        language="JAVASCRIPT">
                            function goList(){
				window.close();
                            }

                            function boardDel(){
				if(confirm("삭제 하시겠습니까?")){
                                    location.href = "/servlet/kr.co.kihyun.beans.totsys.board.HttpBoardDelete?docID=<%= docID%>&boardID=<%= boardID%>&boardGroupID=<%=boardGroupID%>";
				}
                            }

                            function boardModify(){
                                window.open('/totsys/common/inc/board/doc/popup_modify.jsp?boardID=<%=boardID%>&docID=<%=docID%>','','width=538, height=540,toolbar=no, directories=no, status=no, menubar=no, resizable=no');
                                //				window.close();
                            }
			
                            function alertModify(){
                                alert("해당 주의사항에 대한 변경 권한이 없습니다.");
                            }

                            function alertDel(){
                                alert("해당 주의사항에 대한 삭제 권한이 없습니다.");
                            }
                    </SCRIPT>
                    </head>
            <body style='' bgcolor="#FFFFFF" text="#000000" leftmargin="0"
                  topmargin="0" marginwidth="0" marginheight="0">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <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 valign="top">
                                        <table width="100%" border="0" cellspacing="0" cellpadding="0"
                                               align="center">
                                            <tr>
                                                <td valign="top">
                                                    <table border="0" width="100%" cellpadding="0" cellspacing="0">
                                                        <tr>
                                                            <td valign="top" colspan="2">
                                                                <table width="95%" border="0" cellspacing="0" cellpadding="0"
                                                                       height="100%" align="center">
                                                                    <!----- 내용 시작---->
                                                                    <tr>
                                                                        <td valign="top"><%= boardContents%></td>
                                                                    </tr>
                                                                    <!----- 내용 끝---->
                                                                </table>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>

                <%} else {%>
            <tr align="right" style="padding-top: 3;">
                <td height="35" align="center" colspan="5">등록된 글이 없습니다.</td>
            </tr>
            <!--  집계자 본인일때만 글쓰기 가능-->
            <tr align="right" style="padding-top: 3;">
                <td height="35" colspan="5" align="right" style="padding-right: 15;">
                    <%                            }
                    %>
                </td>
            </tr>
            <!---- 공지사항 끝 ---->
        </table>
    </td>
</tr>
<%
            } 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();
            }
%>
<iframe name="hiddenIframe" width="0" height="0" style="display: none;"></iframe>
