<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="ct" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

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

	
	/* 글 상세 화면 function */
	function fn_select(id) {
		document.listForm.seq.value = id;
		document.listForm.action = "<c:url value='/stats/view.do'/>";
	   	document.listForm.submit();
	}
	
	/* 글 목록 화면 function */
    function fn_selectList() {
       	document.searchForm.action = "<c:url value='/stats/list.do'/>";
       	document.searchForm.submit();
    }
	
	/* 글 등록 화면 function */
	function fn_addView() {
	   	document.menuForm.action = "<c:url value='/stats/addView.do'/>";
	   	document.menuForm.submit();
	}
	
	/* 글 선택 삭제 function */
	function fn_deleteSelectedBoard() {
		var confirmed = confirm('선택한 게시물 중 삭제권한이 있는 게시물을 삭제합니다.\n삭제하시겠습니까?');
		if(confirmed){
			document.listForm.method = "post";
		   	document.listForm.action = "<c:url value='/stats/selectedDelete.do'/>";
		   	document.listForm.submit();
		}
	}
	
	/* pagination 페이지 링크 function */
	function fn_link_page(pageNo) {
		document.searchForm.pageIndex.value = pageNo;
		document.searchForm.action = "<c:url value='/stats/list.do'/>";
		document.searchForm.submit();
	}
	/* 새로고침 function */
	function fn_reload() {
		location.reload();
	}
</script>
<form:form commandName="searchVO" name="searchForm" method="get">
	<div id="search">
		<div class="form_group">	
			<label class="hidden" for="searchCondition" style="visibility: hidden;"><spring:message code="search.keyword" /></label> 
			<form:select path="searchCondition" cssClass="use">
				<form:option value="1" label="작성자" />
				<form:option value="2" label="제목" />
			</form:select>
			<form:input path="searchKeyword" cssClass="txt" placeholder="검색어를 입력하세요."/>		
			<div class="inp_btn">
				<span class="btn_blue"><a href="javascript:fn_selectList();"><spring:message code="button.goSearch" /></a></span>
			</div>
		</div>
	</div>
	<form:hidden path="pageIndex" />
	<input type="hidden" name="category" value="${searchVO.category}" />
</form:form>

<div class="tabs">
	<ul>
		<!-- 전체 -->
		<c:if test="${searchVO.category eq ''}">
			<li class="selected"><a href="?id=${searchVO.id}&category="><spring:message code="stats.all" /></a></li>
		</c:if>
		<c:if test="${searchVO.category ne ''}">
			<li><a href="?id=${searchVO.id}&category="><spring:message code="stats.all" /></a></li>
		</c:if>
	
	<c:forEach var="item" items="${category}" varStatus="status">
		<c:if test="${searchVO.category eq item.code2}">
			<li class="selected"><a href="?id=${searchVO.id}&category=${item.code2}"><c:out value="${item.codenm}"/></a></li>
		</c:if>
		<c:if test="${searchVO.category ne item.code2}">
			<li><a href="?id=${searchVO.id}&category=${item.code2}"><c:out value="${item.codenm}"/></a></li>
		</c:if>
	</c:forEach>
	
	</ul>
</div>

<form:form name="listForm" method="get">
	<input type="hidden" name="seq" />
	<input type="hidden" name="id" value="${searchVO.id}" />
	<c:if test="${searchVO.category != ' '}">
		<input type="hidden" name="category" value="${searchVO.category}" />
	</c:if>
	<!-- List -->
	<div id="table">		
		<div class="pageinfo">
			<ct:pageInfo />
			<ul class="right btn-style">
				<li><a href="javascript:fn_deleteSelectedBoard();" class="btn_delete"></a></li>
				<li><a href="#" class="btn_reset" onclick="location.reload();"></a></li>
			</ul>	
		</div>
		<table class="tbl_list" width="100%" border="0" cellpadding="0" cellspacing="0" summary="게시판 목록을 확인 할 수 있습니다.">
			<caption class="hidden">게시판 목록</caption>
			<colgroup>
				<col width="50">
				<col width="50">
				<col width="420">
				<col width="150">
				<col width="100">
				<col width="120">
				<col width="50">
				<col width="60">
			</colgroup>
			<thead>
				<tr>
					<th align="center"><spring:message code="board.header.select" /></th>
					<th align="center"><spring:message code="board.header.no" /></th>
					<th align="center"><spring:message code="board.header.title" /></th>
					<th align="center"><spring:message code="board.header.place1" /></th>
					<th align="center"><spring:message code="board.header.writer" /></th>
					<th align="center"><spring:message code="board.header.regdate" /></th>
					<th align="center"><spring:message code="board.header.attach" /></th>
					<th align="center"><spring:message code="board.header.hit" /></th>
				</tr>
			</thead>
			<c:forEach var="result" items="${resultList}" varStatus="status">
				<tr>
					<td align="center"><input type="checkbox" name="deleteBoard" value="<c:out value="${result.seq}"/>" /></td>
					<td align="center"><c:out value="${result.seq}" /></td>
					<td align="left">
						<c:if test="${result.notice == '1'}">[공지]</c:if>
						<c:if test="${result.depth >= 1}">
						<c:forEach begin="1" end="${result.depth}">
									&nbsp;&nbsp;&nbsp;
						</c:forEach>
						답글 : <!-- 이미지처리할것 -->
						</c:if>
						<a href="javascript:fn_select('<c:out value="${result.seq}"/>')"><c:out value="${result.subject}" /></a></td>
					
					<td align="center"><c:out value="${result.data1}" /></td>
					<td align="center"><b><c:out value="${result.userName}" /></b><br>(<c:out value="${result.userId}" />)</td>
					<td align="center"><fmt:formatDate value="${result.regdate}" pattern="yyyy-MM-dd" />&nbsp;</td>
					<td align="center"><c:if test="${result.fileCnt > 0}">O</c:if></td>
					<td align="center"><c:out value="${result.hit}" /></td>
				</tr>
			</c:forEach>
		</table>
	</div>
	<!-- /List -->
	<div id="paging">
		<ui:pagination paginationInfo="${paginationInfo}" type="image" jsFunction="fn_link_page" />
	</div>
	<div class="board_buttom">
		<ul class="btn-style right">			
			<li><a href="javascript:fn_addView();" class="btn_create"><spring:message code="button.create" /></a></li>
		</ul>
	</div>	
</form:form>
<form:form commandName="searchVO" name="menuForm" method="get">
	<form:hidden path="id" />
	<c:if test="${searchVO.category != ' '}">
		<input type="hidden" name="category" value="${searchVO.category}" />
	</c:if>	
</form:form>