<%
/**
 * <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&amp;A</c:set>

<script>

$( document ).ready(function() {
    
    if(!fn_isEmpty('${message}')) {
        alert("${message}");
    }    
});
    

//목록으로 이동
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(attachFileId, fileSn) {

 if(attachFileId == null || attachFileId.trim().length < 1) {
     alert("파일정보를 확인해 주시기 바랍니다.[1]");
     return;
 }
 
 if(fileSn < 1) {
      alert("파일정보를 확인해 주시기 바랍니다.[3]");
      return;
 }
 
 $("#attachFileId").val(attachFileId);
 $("#fileSn").val(fileSn);
 
 $("#downloadFileForm").submit();
 
}
</script>

    <!-- Q&amp;A 섹션 -->
    <div class="location qna-data">
        <h2 class="blind">Q&amp;A 섹션영역</h2>
        <div class="inner">
            <div class="row-top">
                <div class="location-box">
                    <ul class="loc">
                        <li>HOME</li>
                        <li>고객지원</li>
                        <li class="on">${pageTitle }</li>
                    </ul>
                    <ul class="tit">
                        <li><span>${pageTitle }</span></li>
                    </ul>
                </div>
                <div class="arr"><img src="/images/icon/icon-join-arr2.png" alt="화살표 아이콘"></div>
            </div>
            <div class="contents row-bottom">
                
                <div class="community qna">
                    <div class="contents-frame inner-center">
                        <div class="view-qna">
                            <div class="view-tit">
                                <h2>
                                    <span class="type">
                                    <c:if test='${article.answerYn == "Y"}'><span>답변완료</span></c:if>
                                    </span>
                                    ${article.title}
                                    <span>
                                    <c:if test='${article.secretYn == "Y"}'>
                                    <img src="/images/icon/icon-secret.png" alt="자물쇠 아이콘">
                                    </c:if>
                                    </span>
                                </h2>
                                <span class="v-info">
                                    <em>${article.regNm }</em>
                                    <em>${article.regDd }</em>
                                </span>
                            </div>
                            
                           <c:if test="${article.attachFileCnt > 0}">
                           <div class="file-box">
                                    <%
                                    // 파일정보 : 저장파일ID=원파일명
                                    %>
                                    <c:forEach var="attachFile" items="${article.attachFiles }">
                                        <div class="file-list">
                                            <span><img src="/images/icon/icon-file.png" alt="파일 아이콘"></span>
                                            <span>${attachFile.orignlFileNm}, ${attachFile.fileSize} byte(s)</span>
                                            <span><button type="button" onclick="fn_downloadFile('${attachFile.attachFileId}', ${attachFile.fileSn})">다운로드</button></span>
                                        </div>
                                    </c:forEach>
                            </div>
                            </c:if>
                            
                            <div class="view-body">
                                <div class="view-con">
                                    <div class="view-txt">
                                        <p>${article.unescapedContent}</p>
                                    </div>
                                </div>
                                <c:if test='${article.answerYn == "Y"}'>
                                <div class="answer">
                                    <div class="answer-top">
                                        <span class="left">답변</span>
                                        <span class="right">${article.modDd }</span>
                                    </div>
                                    <div class="answer-con">
                                        <p>${article.answer}</p>
                                    </div>
                                </div>
                                </c:if>
                            </div>
                            <div class="btn-box">
                                <div class="left">
								    <!-- 관련 작업 버튼 -->
								    <c:if test='${article.answerYn != "Y" and article.myQnaYn == "Y" }'>
								        <button type="button" name="btnUpdate" id="btnUpdate" class="btn btn-gray" 
								            onclick="fn_update()">수정</button>
								        <button type="button" name="btnDelete" id="btnDelete" class="btn btn-lightgray" 
								            onclick="fn_delete()">삭제</button>
								    </c:if>
                                </div>
                                <div class="right">
                                    <button type="button" class="btn btn-black" onclick="fn_list()">목록보기</button>
                                </div>
                            </div>
                        </div>
                    </div><!-- //contents-frame -->
                </div>
                
            </div>
        </div>
    </div>
        
    

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

<!-- 첨부파일 다운로드용 폼 -->
<form name="downloadFileForm" id="downloadFileForm"
      action="${pageContext.request.contextPath}/fileupload/downloadAttachFile.do"
      method="post">
      <input type="hidden" name="bdType" id="bdType" value="QNA" />
      <input type="hidden" name="attachFileId" id="attachFileId" value="" />
      <input type="hidden" name="streFileNm" id="streFileNm" value="" />
      <input type="hidden" name="fileSn" id="fileSn" value="" />
      <input type="hidden" name="orignlFileNm" id="orignlFileNm" value="" />
</form>