
<%@page import="java.util.ArrayList"%>
<%@page import="kr.co.kihyun.io.FileUtil"%>
<%@page import="kr.co.kihyun.text.html.TagFilter"%>
<%
/**********************************************************************************
	프로그램명		: popup_view.jsp
	프로그램설명	: 공지사항 보기
	작 성 자			: 강 원 중
	작 성 일			: 2004. 06.07
	최신변경일		: 2005. 05.11
***********************************************************************************/
%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ 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"%>

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

<%
PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
Transaction tx = pm.currentTransaction();
try{
	/*********** User HttpSSOLogin check ***********/
	if(!HttpSSOLogin.isLogin(request)){
		//login 성공후 되돌아올 주소
		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);
	String dtID = HttpSSOLogin.getDeptID(request);
	int sysAuth = HttpSSOLogin.getSysAuth(request);

	/*********** Parameter values ***********/

	//int currentPage = 0;

        String strPage  = clearXSS(request.getParameter("strPage"), "");
        Long boardID = MLong.parseLong(request.getParameter("boardID"),null);
	String boardUserID = clearXSS(Encoder.toJava(request.getParameter("boardUserID")),"");
        String findOption = clearXSS(request.getParameter("findOption"),null);
	String findWord = clearXSS(Encoder.toJava(request.getParameter("findWord")),null);

	/*********** Board View vlaues ***********/
	tx.begin();
	Board board = pm.getObjectById(Board.class, boardID);
	String regID = board.getUser(pm) == null ? null : board.getUser(pm).getId();
	String boardGroupID = board.getCategory().getId();

	String boardTitle = TagFilter.unconvertedMeta(board.getTitle());
	String boardContents = StringConverter.toHtmlBr(board.getContents());
        boardContents=TagFilter.unconvertedMeta(boardContents);
        String checkPopup=board.getPopupYn();
	String usrFilenames = "";
	String svrFilenames = "";
	//파일이 있으면 파일에서 불러오게
	/* for (Entry<String, List<Byte>> entry : board.getAttachments().entrySet()) {
		usrFilenames += entry.getKey() + ";";
		svrFilenames += entry.getKey() + ";";
	} */
	ArrayList<String> fns= FileUtil.getBoardAttachmentsFileNames(board.getId(), request, false);
	for (String fn : fns) {
		usrFilenames += fn + ";";
		svrFilenames += fn + ";";
	}
	int visit = board.getVisit();
	List<Board> replies = board.getChildBoards();
	board.setVisit(visit+1);
	pm.makePersistent(board);
	tx.commit();

	String boardType = "";
	if("ID_SYSTEM_NOTICE".equals(boardGroupID)){
		boardType = Moumi.getMessageBundle().getString("moumi.message.board.notice");
	}else if("ID_FAQ".equals(boardGroupID)){
		boardType = Moumi.getMessageBundle().getString("moumi.message.board.faq");
	}else if("ID_QNA".equals(boardGroupID)){
		boardType = Moumi.getMessageBundle().getString("moumi.message.board.qna");
	}else if("ID_PDS".equals(boardGroupID)){
		boardType = Moumi.getMessageBundle().getString("moumi.message.board.pds");
	}
	/*********** append file name vlaues ***********/
	String[] usrFilenameList = usrFilenames.split(";");
	String[] svrFilenameList = svrFilenames.split(";");

	/****** 본인 유무 처리 ******/
	boolean isManager = false;
	if(usID.equals(regID)){
		isManager = true;
	}
	session.setAttribute("delTargetURI", "location.href='/totsys/sysadm/board/board_list.jsp?boardGroupID=" + boardGroupID+"&strPage="+strPage+"'");
%>
<%@page import="java.util.Set"%>
<%@page import="java.util.List"%>
<%@page import="java.text.SimpleDateFormat"%>
<!DOCTYPE html>
<html lang="ko">
	<head>
<meta charset="UTF-8">
<title><%=Moumi.getTitle()%></title>
<link rel="stylesheet" href="/totsys/common/css/contentStyle.css" type="text/css">
<link rel="stylesheet" href="/totsys/common/css/basic.css" type="text/css">
<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/jquery-1.12.4.min.js"></script>
<script src="/totsys/common/js/jquery.custom.indicator.js"></script>
<script>
        function boardDel(regID){
                if(regID == '<%=usID%>' || '<%=sysAuth%>'=='<%=Moumi.SYSADM%>'){
                        if(confirm("삭제 하시겠습니까?")){
                            $.customIndicator.show(window.self);
                            document.f_delete.target = "hiddenFrame";
                            document.f_delete.submit();
                        }
                }else{
                        alert("삭제 권한이 없습니다.!");
                        return;
                }
        }

        function boardModify(regID){
                if(regID == '<%=usID%>' || '<%=sysAuth%>'=='<%=Moumi.SYSADM%>'){
                        location.href = "./board_modify.jsp?boardID=<%=boardID%>";
                }else{
                        alert("수정 권한이 없습니다.!");
                        return;
                }
        }
        function boardLIst(regID, id){
                location.href = "./board_list.jsp?boardGroupID=<%=boardGroupID%>&boardID="+id+""+"&strPage=<%=strPage%>";
        }
        function conInsert(){
                document.dform.submit();
        }

        function conDelete(id){
                location.href = "/servlet/kr.co.kihyun.beans.totsys.board.HttpBoardDelete?boardGroupID=<%=boardGroupID%>&boardID="+id;
        }

        function changeEditShow(showNumber){
                <%for(int i=0; i<replies.size(); i++){%>
                        if(showNumber == <%=i%>){
                                viewContents<%=i%>.style.display='none';
                                editContents<%=i%>.style.display='';
                        }
                <%}%>
        }

        function changeViewShow(showNumber){
                <%for(int i=0; i<replies.size(); i++){%>
                        if(showNumber == <%=i%>){
                                viewContents<%=i%>.style.display='';
                                editContents<%=i%>.style.display='none';
                        }
                <%}%>
        }

        function conUpdate(updateNumber,id){
        var contents = "";
                <%for(int i=0; i<replies.size(); i++){%>
                        if(updateNumber == <%=i%>){
                                contents = document.dform.updateContents<%=i%>.value;
                                location.href = "/servlet/kr.co.kihyun.beans.totsys.board.HttpBoardModify?id=<%=boardID%>&boardGroupID=<%=boardGroupID%>&userID=<%=usID%>&contents="+contents+"&boardID="+id;
                        }
                <%}%>
        }

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

       /*
        * 수정페이지로 이동처리하는 함수
        * @returns {undefined}
        */
       function fn_goToModify(regID) {
            if(regID == '<%=usID%>' || '<%=sysAuth%>'=='<%=Moumi.SYSADM%>'){
                document.f_modify.submit();
            }else{
                alert("수정 권한이 없습니다.!");
                return;
            }
       }
</script>
</head>

<body>
<form name="f_list" method="post" action="./board_list.jsp">
    <input type="hidden" name="strPage" value="<%= strPage %>">
    <input type="hidden" name="boardGroupID" value="<%= boardGroupID %>">
    <input type="hidden" name="findWord" value="<%= findWord %>">
    <input type="hidden" name="findOption" value="<%= findOption %>">
</form>
<form name="f_modify" method="post" action="./board_modify.jsp">
    <input type="hidden" name="boardID" value="<%= boardID %>">
    <input type="hidden" name="strPage" value="<%= strPage %>">
    <input type="hidden" name="boardGroupID" value="<%= boardGroupID %>">
    <input type="hidden" name="findWord" value="<%= findWord %>">
    <input type="hidden" name="findOption" value="<%= findOption %>">
</form>
<form name="f_delete" method="post" action="/servlet/kr.co.kihyun.beans.totsys.board.HttpBoardDelete">
    <input type="hidden" name="boardID" value="<%= boardID %>">
    <input type="hidden" name="callbackFunc" value="parent.fn_goToList()">
</form>
<table>
    <jsp:include page="/totsys/common/inc/sysadm/top/top.jsp" flush="true" />
    <tr>
        <td style="width: 0px;"></td>
        <td class="vTop">
            <table>
                <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:include>

			<!--  리스트 시작 -->
			<tr>
               <td style="height: 31px; vertical-align: top;">
				<table class="kecttep_list_table">

                                    <!-- 제목 시작 -->
                                    <tr>
                                        <td class="kecttep_tdmenu_middle" style="width: 130px; height: 31px;">
                                            <span style="width: 130px; padding-left:20px;">제목</span>
                                        </td>
                                        <td class="kecttep_last_graytd" style="padding-left: 10px; padding-top: 4px">
                                            <%= boardTitle %>
                                        </td>
                                    </tr>
                                    <!-- 제목 끝 -->

                                    <!-- 내용 -->
                                    <tr class="vTop">
                                        <td class="kecttep_tdmenu_middle" style="padding-top: 10px; height: 200px; padding-left:20px; width: 130px;">
                                            내용
                                        </td>
                                        <td class="kecttep_last_graytd" style="padding-left: 10px; padding-top: 10px; padding-bottom: 10px; padding-right: 10px;">
                                            <%= boardContents %>
                                        </td>
                                    </tr>
                                    <!-- 내용 끝 -->

					<!-- 파일첨부 -->
                                    <tr class="vTop">
                                        <td class="kecttep_tdmenu_middle" style="padding-top: 20px; padding-left:20px; width: 130px;">
                                            관련자료 첨부
                                        </td>
                                        <td class="kecttep_last_graytd" style="padding-left: 10px; padding-right: 10px; padding-top: 10px; padding-bottom: 10px;">
                                            <!-- 파일첨부 테이블 시작 -->
                                            <table style="width: 100%; text-align: center;">
                                            <%
                                            if (svrFilenameList.length != 0 && !MString.isNull(svrFilenameList[0])) {
                                                for(int i=0; i < svrFilenameList.length; i++){
                                            %>
                                                <tr>
                        <!--			<td class="kecttep_last_graytd" height="20"
                                                                style="padding-left: 3;"><font color="#FF6600"><b>+</b><%= Moumi.getMessageBundle().getString("moumi.message.file") %>
                                                        <%= (i+1) %>&nbsp;:&nbsp; <a
                                                                href="/servlet/kr.co.kihyun.text.html.HttpViewer?<%=URLEncoder.encode(usrFilenameList[i], "UTF-8")%>&fileName=<%=URLEncoder.encode(svrFilenameList[i], "UTF-8")%>&boardID=<%=boardID%>"
                                                                target="new"><%= usrFilenameList[i] %></a></font></td>-->
                                                    <td class="kecttep_last_graytd_bottom" style="padding-left: 3px; border-bottom:none; height: 20px;">
                                                        <span style="color: #FF6600"><b>+</b><%= Moumi.getMessageBundle().getString("moumi.message.file") %>
                                                        <%= (i+1) %>&nbsp;:&nbsp; <a
                                                                href="/servlet/kr.co.kihyun.text.html.HttpViewer?fileName=<%=URLEncoder.encode(svrFilenameList[i], "UTF-8")%>&boardID=<%=boardID%>"
                                                                target="hiddenIframe">
                                                         <%

                                    int checkCommaBefore;
                                    int checkComma = usrFilenameList[i].lastIndexOf(".");

                                    if(usrFilenameList[i].lastIndexOf("_") == -1){
                                        checkCommaBefore = checkComma;
                                                }else{
                                        checkCommaBefore = usrFilenameList[i].lastIndexOf("_");
                                                        }

                                    usrFilenameList[i] = usrFilenameList[i].substring(0, checkCommaBefore).concat(usrFilenameList[i].substring(checkComma));
                                    %>
                                    <%= usrFilenameList[i]%>
                                                        </a>
                                                        </span>
                                                    </td>
                                                </tr>
                                                <%
                                                    }
                                            }
                                                %>
                                            </table>
                                            <!-- 파일첨부 테이블 끝 -->
                                        </td>
                                    </tr>
                                    <!-- 팝업공지 -->
                    <% if("ID_SYSTEM_NOTICE".equals(boardGroupID)) { %>
                                    <tr>
                                        <td class="kecttep_tdmenu" style="width: 130px; height: 31px;">
                                            <span style="width: 130px; padding-left:20px;">팝업공지</span>
                                        </td>
                                        <td class="kecttep_last_graytd_bottom" style="vertical-align: middle; padding-left: 10px;">
                                            <input type="checkbox" disabled name="checkPopup" <% if("Y".equals(checkPopup)) { %> checked <% }%>> 
                                        </td>
                                    </tr>
                    <% } %>
                                    <%if("ID_QNA".equals(boardGroupID)) {%>
                                    <form name="dform" method="post" action="/servlet/kr.co.kihyun.beans.totsys.board.HttpBoardWrite">
                                    <input type="hidden" name="boardID" value="<%=boardID%>">
                                    <input type="hidden" name="userID" value="<%=usID%>">
                                    <input type="hidden" name="deptID" value="<%=dtID%>">
                                    <INPUT type="hidden" name="boardGroupID" value="<%= boardGroupID %>">
                                    <input type="hidden" name="strPage" value="<%= strPage%>">
                                    <INPUT type="hidden" name="fileCount">
                                    <INPUT type="hidden" name="usrFilenames">
                                    <INPUT type="hidden" name="svrFilenames">
                                    <INPUT type="hidden" name="fileInfos">
                                    <INPUT type="hidden" name="title">
                                    <INPUT type="hidden" name="tmp1" value="1">
                                    <%
                                        tx.begin();

                                        for(int i=replies.size()-1; i >=0; i--){

                                    %>
                                    <tr>
                                        <td class="kecttep_list_tdmenu" style="padding-top: 10px; width: 180px;">
                                            <img alt="글머리" src="/totsys/common/images/reg_icon.gif">
                                            <%=replies.get(i).getUser(pm).getUpperDept(pm).getName()%><br>
										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=replies.get(i).getUser(pm).getName(pm)%>
                                        </td>
                                        <td class="kecttep_last_graytd" style="padding-left: 10px; padding-top: 10px; padding-bottom: 10px; padding-right: 10px">
                                            <table>
                                                <tr>
                                                    <td style="padding-left: 10px; padding-right: 10px; " class="kecttep_last_graytd">
                                                        <span id="viewContents<%=i%>"><%=replies.get(i).getContents()%>
                                                        <%if(replies.get(i).getUser(pm).getId().equals(usID) || sysAuth == 9){%>
                                                            <a href="#" onClick='changeEditShow("<%=i%>");'>수정</a>&nbsp;<a href="#" onClick='conDelete("<%=replies.get(i).getId()%>");'>삭제</a>
                                                        <%}%>
                                                        </span>
                                                        <span id="editContents<%=i%>" style="display: none;" class="kecttep_last_graytd">
                                                            <input type="text" name="updateContents<%=i%>" value="<%=replies.get(i).getContents()%>" size="90">
                                                            <a href="#" onClick='conUpdate("<%=i%>","<%=replies.get(i).getId()%>");'>변경</a>
                                                            <a href="#" onClick='changeViewShow("<%=i%>");'>취소</a> </span>
                                                    </td>
                                                    <td style="padding-left: 10px; padding-right: 10px;" class="kecttep_last_graytd">
                                                        <%=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(replies.get(i).getWriteDate())%>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <%}
                                    tx.rollback();
                                    %>
                                    <tr class="vTop">
                                        <td width="150" class="kecttep_list_tdmenu" style="padding-top: 10px; width: 150px;">
                                            <img alt="글머리" src="/totsys/common/images/reg_icon.gif">의견
                                        </td>
                                        <td class="kecttep_last_graytd" style="padding-left: 10px; padding-right: 10px; padding-top: 10px; padding-bottom: 10x;">
                                        <!-- 파일첨부 테이블 시작 --> <input type="text" name="contents" size="90"><a href="#" onClick="conInsert();">&nbsp;<span
                                                style="width: 40px; cursor: hand;">입력</span></a> <!-- 파일첨부 테이블 끝 -->
                                        </td>
                                    </tr>
                                </form>
                                    <%}%>

					<!--  파일첨부 끝 -->
                            </table>
                        </td>
                        <td style="width: 10px;"></td>
                    </tr>
		</table>
            </td>
	</tr>
	<!-- top menu start -->
	<%@ include file="/totsys/common/inc/buttom/buttom.jsp"%>
	<!-- top menu end -->
</table>                                          
                                            
	<div class="tac mt_10">
		<!-- 버튼 (공지사항목록) -->
	 	<a class="" href="#" onclick="fn_goToList();" title="목록">
            <img src="/totsys/common/images/bt_list.gif" alt="목록" />
        </a>
        <%if(sysAuth == Moumi.SYSADM ||(sysAuth == Moumi.SUB_SYSADM && regID.equals(usID)) || (sysAuth == Moumi.TOTPER && regID.equals(usID))){%>
        <a class="" href="#" onclick="fn_goToModify('<%=regID%>');" title="수정">
            <img class="ml_5" src="/totsys/common/images/bt_modify.gif" alt="수정" />
        </a>
        <a class="" href="#" onclick="boardDel('<%=regID%>');" title="삭제">
            <img class="ml_5" src="/totsys/common/images/bt_del.gif" alt="삭제" />
        </a>
        <%}%>
	</div>
<iframe name='hiddenFrame' width=0 height=0 style='display:none;'></iframe>
</BODY>
</HTML>
<%
}catch(Exception ex){
        //38.오류메세지를 통한 정보 노출(getMessage)_CWE-209 : Update by YOUNGJUN,CHO
	//out.println(ex);//앤개
	ex.printStackTrace();
	//out.println("<html><body style='overflow=auto' bgcolor='white'><h1>Can't contact servlet runner</h1><br><br>Message : "+ex.getMessage()+"</body></html>");
	//out.println("<META HTTP-EQUIV='refresh' CONTENT='0.1; URL=/error/exception.jsp'>");
        //================================================
}finally{
	if(tx.isActive())
	tx.rollback();
	pm.close();
}
%>
