<%@ 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="validator" uri="http://www.springmodules.org/tags/commons-validator" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="ckeditor" uri="http://ckeditor.com" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib prefix="ct" tagdir="/WEB-INF/tags" %>

<div id="tbCondition" style="display: none">
	<form:form commandName="reportSearchVO" id="searchForm" name="searchForm" method="post">
		<form:hidden path="statsType"/>
	
		<form:hidden path="orderCol"/>
		<form:hidden path="orderAsc"/>
		
		<form:hidden path="myGroupCode" />
		<form:hidden path="pageIndex" />
		<form:hidden path="dateStart"/>
		<form:hidden path="dateEnd"/>
		<form:hidden path="writeName"/>
		<form:hidden path="writeId"/>
		<c:forEach var="item" items="${reportSearchVO.places}">
			<input type="hidden" name="places" value="${item}"/>
		</c:forEach>
		<c:forEach var="item" items="${reportSearchVO.judges}">
			<input type="hidden" name="judges" value="${item}"/>
		</c:forEach>
		<c:forEach var="item" items="${reportSearchVO.fullReport}">
			<input type="hidden" name="fullReport" value="${item}"/>
		</c:forEach>
		<c:forEach var="item" items="${reportSearchVO.policeType}">
			<input type="hidden" name="policeType" value="${item}"/>
		</c:forEach>
		<c:forEach var="item" items="${reportSearchVO.category1}">
			<input type="hidden" name="category1" value="${item}"/>
		</c:forEach>
		<c:forEach var="item" items="${reportSearchVO.category2}">
			<input type="hidden" name="category2" value="${item}"/>
		</c:forEach>
		<c:forEach var="item" items="${reportSearchVO.category3}">
			<input type="hidden" name="category3" value="${item}"/>
		</c:forEach>
		<c:forEach var="item" items="${reportSearchVO.category4}">
			<input type="hidden" name="category4" value="${item}"/>
		</c:forEach>
		<form:hidden path="searchCate1"/>
		<form:hidden path="searchCate2"/>
		<form:hidden path="searchCate3"/>
		<form:hidden path="searchCate4"/>

		<div class="table">
			<table class="tbl_add">			
			<tr>
				<th align="center"><spring:message code="report.search.period" /></th>
				<td colspan="7">
					<c:out value="${reportSearchVO.dateStart}"/> ~ <c:out value="${reportSearchVO.dateEnd}"/>
				</td>
			</tr>
			<tr>
				<th align="center"><spring:message code="report.search.reporter" /></th>
				<td colspan="3">
					<c:out value="${reportSearchVO.writeName}" />
				</td>
				<th align="center"><spring:message code="report.search.id" /></th>
				<td colspan="3">
					<c:out value="${reportSearchVO.writeId}"/>
				</td>
			</tr>
			<tr>
				<th align="center" rowspan="2"><spring:message code="report.search.place" /></th>
				<td rowspan="2" colspan="3">
					<ul><c:forEach var="place" items="${placeList}">
						<c:if test="${fn:contains(fn:join(reportSearchVO.places, ','), place.code2)}">
							<li style="width: 130px; float: left;"><c:out value="${place.codenm}"/></li>
						</c:if>
					</c:forEach></ul>
				</td>
				<th align="center" rowspan="2"><spring:message code="report.view.appraisal" /></th>
				<td rowspan="2">
					<c:forEach var="item" items="${judges}">
						<c:set var="judge">${item}</c:set>
						<p><c:out value="${judgeList[judge]}"/></p>
					</c:forEach>
				</td>
				<th align="center"><spring:message code="report.type.fullReport" /></th>
				<td valign="top">
					<c:if test="${fn:contains(fn:join(reportSearchVO.places, ','), 1)}"><p>경찰서상보</p></c:if>
					<c:if test="${fn:contains(fn:join(reportSearchVO.places, ','), 2)}"><p>지방청상보</p></c:if>
				</td>
			</tr>
			<tr>
				<th align="center"><spring:message code="report.view.division" /></th>
				<td valign="top">
					<c:if test="${fn:contains(fn:join(reportSearchVO.policeType, ','), 1)}"><p>외사경찰</p></c:if>
					<c:if test="${fn:contains(fn:join(reportSearchVO.policeType, ','), 2)}"><p>일반경찰</p></c:if>
				</td>
			</tr>
			<tr>
				<th align="center"><spring:message code="report.view.category1" /></th>
				<td valign="top">
					<c:forEach var="category" items="${reportSearchVO.category1}">
						<p><c:out value="${category1[category]}"/></p>
					</c:forEach>
				</td>
				<th align="center"><spring:message code="report.view.category2" /></th>
				<td valign="top">
					<c:forEach var="category" items="${reportSearchVO.category2}">
						<p><c:out value="${category2[category]}"/></p>
					</c:forEach>
				</td>
				<th align="center"><spring:message code="report.view.category3" /></th>
				<td valign="top">
					<c:forEach var="category" items="${reportSearchVO.category3}">
						<p><c:out value="${category3[category]}"/></p>
					</c:forEach>
				</td>
				<th align="center"><spring:message code="report.view.category4" /></th>
				<td valign="top">
					<c:forEach var="category" items="${reportSearchVO.category4}">
						<p><c:out value="${category4[category]}"/></p>
					</c:forEach>
				</td>
			</tr>
		</table>
		</div>
	</form:form>
</div>

<div class="pageinfo">
	<ul class="right btn-style-text">
		<li><a id="btnCondigion" href="#"><spring:message code="button.showCondition" /></a></li>
		<li><a href="javascript:searchAgain();"><spring:message code="button.searchAgain" /></a></li>
		<li><a href="javascript:fn_get_excel();"><spring:message code="button.getExcel" /></a></li>
		<li>
			<c:if test="${reportSearchVO.statsType eq 'C'}"><a href="javascript:fn_get_stats('J');"><spring:message code="report.stats.judge" /></a></c:if>
			<c:if test="${reportSearchVO.statsType eq 'J'}"><a href="javascript:fn_get_stats('C');"><spring:message code="report.stats.category" /></a></c:if>
		</li>
	</ul>	
</div>

<form:form name="listForm" method="get">	
	<div id="table">	
		<table class="tbl_listview3" border="0" cellpadding="0" cellspacing="0" summary="게시판 목록을 확인 할 수 있습니다." style="font-size:12px !important;">
			<colgroup>
				<col width="180">
			</colgroup>
			<caption class="hidden">게시판 목록</caption>		
			<c:if test="${reportSearchVO.statsType eq 'C'}">
				<thead>
					<tr>
						<th align="center" rowspan="2"><spring:message code="report.view.division" /></th>
						<th align="center" rowspan="2"><spring:message code="report.stats.total" /></th>
						<c:if test="${reportSearchVO.searchCate1}">
							<th align="center" colspan="<c:out value='${fn:length(searchVO.category1)}'/>">
								<spring:message code="report.view.category1" />
							</th>
						</c:if>
						<c:if test="${reportSearchVO.searchCate2}">
							<th align="center" colspan="<c:out value='${fn:length(searchVO.category2)}'/>">
								<spring:message code="report.view.category2" />
							</th>
						</c:if>
						<c:if test="${reportSearchVO.searchCate3}">
							<th align="center" colspan="<c:out value='${fn:length(searchVO.category3)}'/>">
								<spring:message code="report.view.category3" />
							</th>
						</c:if>
						<c:if test="${reportSearchVO.searchCate4}">
							<th align="center" colspan="<c:out value='${fn:length(searchVO.category4)}'/>">
								<spring:message code="report.view.category4" />
							</th>
						</c:if>
					</tr>
					<tr>
						<c:if test="${reportSearchVO.searchCate1}">	
							<c:forEach var="item" items="${searchVO.category1}">
								<th align="center"><c:out value="${category1[item]}"/></th>
							</c:forEach>
						</c:if>
						<c:if test="${reportSearchVO.searchCate2}">	
							<c:forEach var="item" items="${searchVO.category2}">
								<th align="center"><c:out value="${category2[item]}"/></th>
							</c:forEach>
						</c:if>
						<c:if test="${reportSearchVO.searchCate3}">	
							<c:forEach var="item" items="${searchVO.category3}">
								<th align="center"><c:out value="${category3[item]}"/></th>
							</c:forEach>
						</c:if>
						<c:if test="${reportSearchVO.searchCate4}">	
							<c:forEach var="item" items="${searchVO.category4}">
								<th align="center"><c:out value="${category4[item]}"/></th>
							</c:forEach>
						</c:if>
					</tr>
				</thead>
				
			 	<c:forEach var="stats" items="${statistics}" varStatus="status">
					<tr>
						<c:if test="${status.last}"><td align="center" style="font-weight:bold;"><c:out value="${stats.placename}"/></td></c:if>
						<c:if test="${!status.last}"><td align="left"><c:out value="${stats.placename}"/></td></c:if>
						<td align="center"><c:out value="${stats.total}"/></td>
						
						<c:if test="${reportSearchVO.searchCate1}">
							<c:forEach var="item" items="${searchVO.category1}">
								<c:set var="key" value="${item}_1"/>
								<td align="center"><c:out value="${stats[key]}"/></td>
							</c:forEach>
						</c:if>
						
						<c:if test="${reportSearchVO.searchCate2}">
							<c:forEach var="item" items="${searchVO.category2}">
								<c:set var="key" value="${item}_2"/>
								<td align="center"><c:out value="${stats[key]}"/></td>
							</c:forEach>
						</c:if>
						
						<c:if test="${reportSearchVO.searchCate3}">
							<c:forEach var="item" items="${searchVO.category3}">
								<c:set var="key" value="${item}_3"/>
								<td align="center"><c:out value="${stats[key]}"/></td>
							</c:forEach>
						</c:if>
						
						<c:if test="${reportSearchVO.searchCate4}">
							<c:forEach var="item" items="${searchVO.category4}">
								<c:set var="key" value="${item}_4"/>
								<td align="center"><c:out value="${stats[key]}"/></td>
							</c:forEach>
						</c:if>
					</tr>
				</c:forEach>
			</c:if>
			
			<c:if test="${reportSearchVO.statsType eq 'J'}">
				<thead>
					<tr>
						<th align="center" rowspan="2"><spring:message code="report.view.division" /></th>
						<th align="center" colspan="2"><spring:message code="report.type.fullReport" /></th>
						<th align="center" colspan="7"><spring:message code="report.stats.judgeResult" /></th>
						<th align="center" colspan="4"><spring:message code="report.stats.gradeResult" /></th>
					</tr>
					<tr>
						<th align="center"><spring:message code="report.type.fullReport1"/></th>
						<th align="center"><spring:message code="report.type.fullReport2"/></th>
						
						<th align="center"><spring:message code="report.type.newsflash"/></th>
						<th align="center"><spring:message code="report.type.judge"/></th>
						<th align="center"><spring:message code="report.type.middle"/></th>
						<th align="center"><spring:message code="report.type.notice"/></th>
						<th align="center"><spring:message code="report.type.record"/></th>
						<th align="center"><spring:message code="report.type.survey"/></th>
						<th align="center"><spring:message code="report.type.reference"/></th>
						
						<th align="center"><spring:message code="report.stats.AGrade"/></th>
						<th align="center"><spring:message code="report.stats.BGrade"/></th>
						<th align="center"><spring:message code="report.stats.CGrade"/></th>
						<th align="center"><spring:message code="report.stats.DGrade"/></th>
					</tr>
				</thead>
				
			 	<c:forEach var="stats" items="${statistics}" varStatus="status">
					<tr>
						<c:if test="${status.last}"><td align="center"><c:out value="${stats.placename}"/></td></c:if>
						<c:if test="${!status.last}"><td align="left"><c:out value="${stats.placename}"/></td></c:if>
						
						<td align="center"><c:out value="${stats.REPORT1}"/></td>
						<td align="center"><c:out value="${stats.REPORT2}"/></td>
						
						<td align="center"><c:out value="${stats.JU1}"/></td>
						<td align="center"><c:out value="${stats.JU2}"/></td>
						<td align="center"><c:out value="${stats.JU3}"/></td>
						<td align="center"><c:out value="${stats.JU4}"/></td>
						<td align="center"><c:out value="${stats.JU5}"/></td>
						<td align="center"><c:out value="${stats.JU6}"/></td>
						<td align="center"><c:out value="${stats.JU7}"/></td>
						
						<td align="center"><c:out value="${stats.AG}"/></td>
						<td align="center"><c:out value="${stats.BG}"/></td>
						<td align="center"><c:out value="${stats.CG}"/></td>
						<td align="center"><c:out value="${stats.DG}"/></td>
					</tr>
				</c:forEach>
			</c:if>
		</table>
	</div>	
</form:form>

<script type="text/javascript">
<!--
	$(document).ready(function(){
		// 조건보기
		$('#btnCondigion').click(function(){
			$('#tbCondition').toggle();
		});
	});

 	/* 다시 검색 */
	function searchAgain() {
		document.searchForm.action = "<c:out value='/report/statistics.do' />";
		document.searchForm.submit();
	}

	//분야별 통계
	function fn_get_stats(type) {
		document.searchForm.statsType.value = type;
		document.searchForm.action = "<c:out value='/report/statsResult.do' />";
		document.searchForm.submit();
	}

	//분야별 엑셀받기
	function fn_get_excel() {
		document.searchForm.statsType.value = "<c:out value='${reportSearchVO.statsType}'/>";
		document.searchForm.action = "<c:out value='/report/statsExcel.do' />";
		document.searchForm.submit();
	}
	
-->
</script>
