<%
/**
 * <pre>
 * @Class Name : selectQnaArticle.jsp
 * 
 * @Description : 묻고답하기 상세내용을 조회한다.
 * 
 * 
 * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
 *
 * </pre>
 *
 * @ ------------    --------    ---------------------------
 * @ 수정일                     수정자             수정내용
 * @ ------------    --------    ---------------------------
 * @ 2021. 9. 16.    KNKIM       최초 생성
 *
 * 
 * @author 이씨플라자 * DIGITALSHIP KNKIM
 * @since 2021. 9. 16.
 * @version 1.0
 *
 */
 %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="validator" uri="http://www.springmodules.org/tags/commons-validator" %>

<c:set var="pageTitle">Q&A - 상세조회</c:set>

<!DOCTYPE html>
<html lang="ko">
<head>
<title>${pageTitle}</title>

<script type="text/javaScript" language="javascript">

// 목록으로 이동
function fn_list() {
    $("#articleForm").submit();
}

function fn_update() {
	$("#articleForm").attr("action", "${pageContext.request.contextPath}/bbs/updateQnaForm.do");
    $("#articleForm").submit();
}

function fn_delete() {
	if(!confirm("문의하신 글을 삭제하시겠습니까?")) return;
	
    $("#articleForm").attr("action", "${pageContext.request.contextPath}/bbs/deleteQnaArticle.do");
    $("#articleForm").submit();
}

// 파일 다운로드
function fn_downloadFile(fileMask, fileId, fileSeq, fileName) {

    if(fileMask == null || fileMask.trim().length < 1) {
        alert("파일정보를 확인해 주시기 바랍니다.[1]");
        return;
    }
    
    if(fileId == null || fileId.trim().length < 1) {
        alert("파일정보를 확인해 주시기 바랍니다.[2]");
        return;
    }

    if(fileSeq < 1) {
         alert("파일정보를 확인해 주시기 바랍니다.[3]");
         return;
    }
    
    if(fileName == null || fileName.trim().length < 1) {
         alert("파일정보를 확인해 주시기 바랍니다.[4]");
         return;
    }

    $("#fileMask").val(fileMask);
    $("#fileId").val(fileId);
    $("#fileSeq").val(fileSeq);
    $("#fileName").val(fileName);
    $("#downloadFileForm").submit();
    
}

</script>

</head>

<body>

<h1>${pageTitle }</h1>

메시지 : <span style="color:red;">${message }</span>
<br />

<form name="articleForm" id="articleForm"  
      action="${pageContext.request.contextPath}/bbs/listQnas.do" 
      method="post"> 
    
    <!-- HIDDEN 영역 : 시작 -->
    <input type="text" name="pageIndex"       id="pageIndex"       title="페이지번호"        value="${searchArticle.pageIndex}"       readonly />
    <input type="text" name="pageSize"        id="pageSize"        title="목록에 보여줄 글개수" value="${searchArticle.pageSize}"        readonly />
    <input type="text" name="searchType"      id="searchType"      title="검색구분"         value="${searchArticle.searchType}"     readonly />
    <input type="text" name="searchKeyword"   id="searchKeyword"   title="검색어"           value="${searchArticle.searchKeyword}"   readonly />
    <input type="text" name="articleId"       id="articleId"       title="선택글번호"        value="${searchArticle.articleId}"       readonly />
    <!-- HIDDEN 영역 : 종료 -->

    <table class="table_content" style="width:100% !important; margin-top: 20px;">
        <tr>
            <th>작성일</th>
            <td>${article.regDd }</td>
            <th>답변여부</th>
            <td>
                <c:if test='${article.answerYn == "Y"}'>답변완료</c:if>
                <c:if test='${article.answerYn != "Y"}'>답변대기중</c:if>
            </td>
        </tr>
        <tr>
            <th>비밀글여부</th>
            <td>
	            <c:if test='${article.secretYn == "Y"}'>비밀글</c:if>
	            <c:if test='${article.secretYn != "Y"}'>일반</c:if>
            </td>
            <th rowspan="1">제목</th>
            <td colspan="1">${article.title}</td>
        </tr>
        <tr>
            <th rowspan="1">질문자</th>
            <td colspan="3">${article.regNm}</td>
        </tr>
        <tr>
            <th rowspan="1">질문내용</th>
            <td colspan="3"><div id="divContent">${article.unescapedContent}</div></td>
        </tr>
        
        <c:if test='${article.secretYn == "Y"}'>
        <tr>
            <th rowspan="1">답변내용</th>
            <td colspan="3">${article.answer}</td>
        </tr>
        </c:if>
        
       <c:if test="${article.attachFileCnt > 0}">
        <tr>
            <td colspan="4">
                <%
                // 파일정보 : 저장파일ID=원파일명
                %>
                <c:forEach var="attachFile" items="${article.attachFiles }">
                    <a href="javascript:void(0);" onclick="fn_downloadFile('${attachFile.fileMask}', '${attachFile.fileId}', ${attachFile.fileSeq}, '${attachFile.fileName}')">${attachFile.fileName} (${attachFile.fileSize} byte(s))</a><br/>
                </c:forEach>
            </td>
        </tr>
        </c:if>
        <c:if test="${article.attachFileCnt < 1}">
            <td colspan="4">첨부파일 없음 
            </td>        
        </c:if>
        
    </table>        
    
    <br/>
    
    <!-- 관련 작업 버튼 -->
    <c:if test='${article.answerYn != "Y" and article.myQnaYn == "Y" }'>
	    <button type="button" name="btnUpdate" id="btnUpdate" class="float"
	        onclick="fn_update()">수정</button>
        <button type="button" name="btnDelete" id="btnDelete" class="float"
            onclick="fn_delete()">삭제</button>
    
    </c:if>
    
    <button type="button" name="btnList" id="btnList" class="float"
        onclick="fn_list()">목록</button>
        
</form>

<br />

<!-- 첨부파일 다운로드용 폼 -->
<form name="downloadFileForm" id="downloadFileForm"
      action="${pageContext.request.contextPath}/fileupload/downloadAttachFile.do"
      method="post">
      <input type="text" name="subPathKey" id="subPathKey" value="fileupload.bbs.qna.subpath" readonly />
      <input type="text" name="fileMask" id="fileMask" value="" readonly />
      <input type="text" name="fileId" id="fileId" value="" readonly />
      <input type="text" name="fileSeq" id="fileSeq" value="" readonly />
      <input type="text" name="fileName" id="fileName" value="" readonly />
</form>

</body>
</html>
