<%@ 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"%>

<div id="divPrintArea">
	<div id ="divPrintTitle" style="display: none;margin: 10px 0 10px 0;"><spring:message code="equip.useState" /></div>
	<div>
		<h3>
			<c:out value="${approveVO.year}" /> 년도
			<c:out value="${approveVO.quater}" /> / 4 분기
			<c:out value="${loginUserVO.place1Str}" />
		</h3>
	</div>
	<div class="pageinfo">
		<ul class="right btn-style">					
			<li><a class="btn_print" href="javascript:fn_print();"></a></li>
		</ul>	
	</div>		
	<!-- List -->
	<div id="table">			
		<table class="tbl_listview" width="100%" border="1" cellpadding="0" cellspacing="0" summary="사용실적 결재정보를 조회할 수 있습니다.">
			<colgroup>
				<col width="200">
				<col width="*">
				<col width="*">
			</colgroup>
			<thead>
				<tr>
					<th align="center"><spring:message code="equip.useState.division" /></th>
					<th align="center"><spring:message code="equip.useState.cnt" /></th>
					<th align="center"><spring:message code="equip.useState.detail" /></th>
					<th align="center"><spring:message code="equip.useState.check" /></th>
					<th align="center"><spring:message code="equip.useState.state" /></th>
				</tr>
			</thead>
			<tbody>
			<c:choose>
			<c:when test="${fn:length(useStateList) > 0}">
			<c:forEach var="result" items="${useStateList}" varStatus="status">
				<tr>
					<td align="center"><c:out value="${result.CODENM}" /></td>
					<td align="center"><c:out value="${result.EU_CNT}" /></td>
					<td align="center"><c:out value="${empty fn:trim(result.EU_DETAIL) ? '해당사항 없음.' : result.EU_DETAIL}" /></td>
					<td align="center"><c:out value="${result.EU_CHECK}" /></td>
					<td align="center"><c:out value="${empty fn:trim(result.EU_STATE) ? '-' : result.EU_STATE}" /></td>
				</tr>
			</c:forEach>
			</c:when>
			<c:otherwise>
				<tr>
					<td align="center" colspan="5">
						<spring:message code="msg.nodata" />
					</td>
				</tr>
			</c:otherwise>
			</c:choose>
			</tbody>
		</table>
	</div>
	<!-- /List -->
	<form:form commandName="approveVO" name="inputForm" method="post">	
		<c:choose>
		<c:when test="${approveVO.seq > 0}">
			<table class="tbl_add mt-20" width="100%" border="0" cellpadding="0" cellspacing="0" >
				<tr>
					<th><spring:message code="equip.approve.name" /></th>
					<td><c:out value="${approveVO.position}" /> <c:out value="${approveVO.name}" /></td>
					<td>
						<!-- 
							기존 PHP 소스에서 서명 이미지 파일이 있으면 해당 파일을 표현하고자 하는 코드를 작성하였는데,
							해당 테이블에 서명 이미지 경로를 저장하는 필드가 없어 항상 결재권자의 이름이 표현되었다.
						-->
						<c:out value="${approveVO.name}" />
					</td>
				</tr>
				<tr>
					<th><spring:message code="equip.approve.message" /></th>
					<td colspan="2"><c:out value="${approveVO.message}" /></td>
				</tr>
				<tr>
					<th><spring:message code="equip.approve.checkDate" /></th>
					<td colspan="2"><fmt:formatDate value="${approveVO.checkDate}" pattern="yyyy-MM-dd"/></td>
				</tr>
			</table>		
		</c:when>
		<c:otherwise>
			<c:if test="${loginUserVo.authHead eq 1 or loginUserVO.isAdmin eq true}">
			<form:hidden path="place1" value="${headVO.place1}" />
			<form:hidden path="place1Str" value="${headVO.place1Str}" />
			<form:hidden path="position" value="${headVO.position}" />
			<form:hidden path="positionStr" value="${headVO.positionStr}" />
			<form:hidden path="name" value="${headVO.name}" />
			<form:hidden path="userId" value="${headVO.userid}" />
			<form:hidden path="proxyId" value="${loginUserVO.userid}" />
			<table class="tbl_add mt-20" width="100%">
				<tr>
					<th><spring:message code="equip.approve.name" /></th>
					<td>
						<c:out value="${headVO.positionStr}" /> <c:out value="${headVO.name}" /> 과장
						<c:if test="${headVO.userid ne loginUserVO.userid}">
							<span class="text_blue">(${loginUserVO.name} 과장 대행)</span>
						</c:if>
					</td>
				</tr>
				<tr>
					<th><spring:message code="equip.approve.message" /></th>
					<td><form:input path="message" /></td>
				</tr>
			</table>
			</c:if>
		</c:otherwise>
		</c:choose>
	</form:form>	
</div>
<!-- /PrintArea -->

<div class="boardviewinfo">
	<ul class="right btn-style">
		<c:if test="${approveVO.seq < 1 && (loginUserVO.authHead eq 1 || loginUserVO.isAdmin eq true)}">
		<li>
	     	<a href="javascript:fn_submit();"><spring:message code="button.goApproval" /></a>
	    </li>
	    </c:if>
	    <li>	
			<a href="javascript:history.back();"><spring:message code="button.goList" /></a>
	    </li>
	</ul>
</div>

<script type="text/javascript" defer="defer">
	function fn_submit() {
		if (confirm("<spring:message code="confirm.msg.askApprove" />")){
			document.inputForm.submit();
		}
	}
	
	/* 출력 */
	function fn_print(){
		var divPrintTitle = document.getElementById("divPrintTitle");
		divPrintTitle.style.display = "inline";
		printDiv($("#divPrintArea").html());
		divPrintTitle.style.display = "none";
	}
</script>