<%@page import="java.io.PrintWriter"%>
<%@page import="java.io.File"%>
<%@page import="java.io.PrintStream"%>
<%@page import="java.util.ArrayList"%>
<%@page import="kr.co.kihyun.io.FileUtil"%>
<%@page import="kr.co.kihyun.prop.QueryStringList"%>
<%@page import="kr.co.kihyun.db.CommonDBManager"%>
<%@page import="java.io.ObjectInputStream"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="kr.co.kihyun.db.DBPool"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="javax.jdo.Query"%>
<%    /**
     * ********************************************************************************
     * 프로그램명	: popup_view.jsp 프로그램설명	: 공지사항 보기 작 성 자	: 강 원 중 작 성 일	: 2004. 06.07
     * 최신변경일	: 2005. 05.11
**********************************************************************************
     */
%>
<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="kr.co.kihyun.service.vo.BoardVO"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="kr.co.kihyun.service.BoardService"%>
<%@page import="kr.co.kihyun.text.html.TagFilter"%>
<%@page import="kr.co.kihyun.text.html.ServletUtil"%>
<%@page import="kr.co.kihyun.lang.StringConverter"%>
<%@page import="kr.co.kihyun.moumi.Moumi"%>
<%@page import="kr.co.kihyun.beans.user.HttpSSOLogin"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="kr.co.kihyun.lang.Encoder"%>
<%@page import="kr.co.kihyun.lang.MString"
        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.Board"%>
<%@page import="java.util.Map.Entry"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Set"%>
<%@page import="java.util.List"%>
<%@page import="java.text.SimpleDateFormat"%>

<%@ include file="/totsys/common/inc/sec/secure.inc.jsp"%>

<%
	boolean isAttach=false;
	CommonDBManager db=new CommonDBManager();
	ResultSet rs = null;

    try {
    	Long boardID = MLong.parseLong(request.getParameter("boardID"), null);
        String boardTitle =null;
        String boardContents =null;
      	String boardType = "";
    	String sql=QueryStringList.NoticeWithOutFileSql;

    	rs = db.execQuery(sql, boardID);

    	if(rs.next()){
			ArrayList<String> fns= FileUtil.getBoardAttachmentsFileNames(boardID, request,false);
    		if(fns!=null&&fns.size()>0)isAttach=true;
    		boardTitle = rs.getString("TITLE");
            boardContents = StringConverter.toHtmlBr(rs.getString("CONTENTS"));
            boardContents = TagFilter.unconvertedMeta(boardContents);
            boardType = Moumi.getMessageBundle().getString("moumi.message.board.notice");
    	}


    	//////////////////////////////////////
%>
<HTML>
    <HEAD>
        <TITLE><%=Moumi.getTitle()%></TITLE>
        <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
        <link rel="stylesheet" href="/totsys/common/css/text.css" type="text/css">
        <link rel="stylesheet" href="/totsys/common/css/SquareButtons.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/popup.js"></script>
        <script type="text/javascript" src="/totsys/common/js/jquery-1.12.4.min.js"></script>
        <script type="text/javascript" src="/totsys/common/js/jquery.custom.indicator.js"></script>

    </HEAD>
    <body style='' BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
    <SCRIPT type="text/javascript">
            function popupViewInner(p_boardID) {
                gEventY = window.event.clientY + document.body.scrollTop;
                gEventX = window.event.clientX + document.body.scrollLeft;

                $.ajax({
                    url: "/servlet/kr.co.kihyun.service.servlet.AjaxProcessServlet",
                    type: "POST",
                    dataType: "json",
                    data: {
                        proc_type: "board_attatch_file",
                        board_id: p_boardID
                    },
                    success: function(data) {
                        $("#fileview").css("display","none");
                        fn_callBackForSuccess(data);
                    },
                    error: function(e) {
                        alert("동시접속자가 많아 파일을 조회할 수 없습니다.");
                    },
                    beforeSend: function() {
                        $.customIndicator.show(window.self);
                    },
                    complete: function() {
                        $.customIndicator.hide(window.self);
                    }
                });
            }

            /**
             * attachmentsMapByBoardID 함수의 성공 시 호출되는 함수
             * @param {type} data
             * @returns {undefined}
             */
            function fn_callBackForSuccess(data) {
                var fileList = "";
                var boardID = "";
                var fileName = "";
                var fileNameEncode = "";

                if (data != null) {
                    for (var i = 0; i < data.length; i++) {
                        boardID = data[i].boardID;
                        fileName = data[i].fileName;
                        fileNameEncode = data[i].fileNameEncode;
                        //fileList += "<a onclick=\"popupClose(\'"+fileIndex+"\');\" href=\'/servlet/kr.co.kihyun.text.html.HttpViewer?saveAs="+ fileNameEncode+ "\&fileName="+ fileNameEncode +"\&reportID="+reportID+"\' target=\'new\'>"+ fileName+ "</a><br/>\n" ;
                        fileList += "<span style='color: #FF9C1B; font-weight: bold;'>+첨부파일 " + (i + 1) + " : </span><a onclick='godown(this);' style='white-space: nowrap;' href=\"#\" url=\'/servlet/kr.co.kihyun.text.html.HttpViewer?fileName=" + fileNameEncode + "\&boardID=" + boardID + "\' target=\'\'>" + fileName + "</a><br/>\n";
                    }
                    document.getElementById("fileNameList").innerHTML = fileList;
                }
            }
             function godown(link){
            	 try{
            		 parent.$('.frameblock').show();
            		 parent.setTimeout($('.frameblock').hide,3000);
            	 }catch(e){}
            	 var url=$(link).attr('url');
            	 //window.open(url);
            	 //window.close();
            	 location.href=url;
             }

        </SCRIPT>
    <div class="frameblock" style="display:none;text-align: center; color: #000; background-color: #fff; font-family: dotum; font-size: 13px; font-weight: bold;position: absolute;top:0;left:0;width:100%;height:100%; z-index: 1001; opacity: 0.5;-ms-filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=50);filter:alpha(opacity=50);"><div style="margin-top:30%;opacity: 1;-ms-filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=100);filter:alpha(opacity=100);"><img src="/totsys/common/js/img/ajax-loader1.gif">&nbsp;처리중입니다...</div></div>
        <table width="100%" height="70" border="0" cellpadding="0" cellspacing="0">
            <%--<jsp:include page="/totsys/common/inc/sysadm/top/top.jsp" flush="true" />--%>
            <tr>
                <td nowrap width="0"></td>
                <td valign="top">
                    <table align="center" width="100%" border="0" cellspacing="0" cellpadding="0">
                        <jsp:include page="/totsys/common/inc/title/title.jsp" flush="true">
                            <jsp:param value='<%= URLEncoder.encode(boardType, "UTF-8")%>' name="title" />
                            <jsp:param value='<%= URLEncoder.encode(boardTitle, "UTF-8")%>' name="desc" />
                            <jsp:param value='99' name="flag" />
                        </jsp:include>

                        <!----  topbar  버튼 끝 ---->

                        <!--1픽셀 띄우기-->
                        <tr>
                            <td height="1"></td>
                        </tr>

                        <!----  리스트 시작 ---->
                        <tr>
                            <td height="31" valign="top">
                                <table border="1px" bordercolor="#e3e3e3" class="kecttep_list_table"
                                       width="100%" cellpadding="0" cellspacing="0">

                                    <!---- 제목 시작 ---->
                                    <tr>
                                        <td class="kecttep_last_tdmenu"
                                            style="padding-left: 10; padding-top: 4"><%= boardTitle%></td>
                                    </tr>
                                    <!---- 제목 끝 ---->

                                    <!---- 내용 ---->
                                    <tr valign="top">

                                        <td class="kecttep_last_graytd"
                                            style="padding-left: 10; padding-top: 10; padding-bottom: 10; padding-right: 10">
                                            <%= boardContents%></td>
                                    </tr>
                                    <!---- 내용 끝 ---->

                                    <!---- 파일첨부 ---->
                                    <tr valign="top">

                                        <td class="kecttep_last_graytd"
                                            style="padding-left: 10; padding-right: 10; padding-top: 10; padding-bottom: 10;">
                                            <!---- 파일첨부 테이블 시작 ---->
                                            <table width="100%" border="0" cellspacing="0" cellpadding="0"
                                                   align="center">
                                                <%--
                                                <% if (board.getAttachments().size() == 0) {%>
                                                 --%>
                                                 <% if (!isAttach) {%>
                                                    &nbsp;
                                                <%} else {%>
                                                <tr>
                                                    <td id = "fileview" class="kecttep_list_graytd" height="20"
                                                        style="padding-left: 3;"><font color="#FF6600"><b>+</b><%= Moumi.getMessageBundle().getString("moumi.message.file")%>
                                                        <a href="javascript:void(0);" onclick="popupViewInner('<%=boardID%>');"><img src="/totsys/totper/mydocbox/prssbox/reports/images/disk.gif"></a>
                                                        </font></td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2" bgcolor="white" style="padding: 2px; white-space: nowrap;">
                                                        <span id="fileNameList" style="white-space: nowrap;">

                                                        </span>
                                                    </td>
                                                </tr>
                                                <%}%>
                                            </table>
                                            <!---- 파일첨부 테이블 끝 ----></td>
                                    </tr>
                                    <!----  파일첨부 끝 ---->
                                </table>
                            </td>
                            <!--<td width="10"></td>-->
                        </tr>
                    </table>
                </td>
            </tr>
            <!------------------------------- top menu start ------------------------------->
            <%@ include file="/totsys/common/inc/buttom/buttom.jsp"%>
            <!------------------------------- top menu end ------------------------------->
        </table>
    </BODY>
</HTML>
<%
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        if (null != rs) {
            rs.close();
        }
        db.execClose();
    }
%>
