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

<div id ="divPrintTitle" style="display: none;margin: 10px 0 10px 0;">
	<spring:message code="report.title" />
</div>

<fmt:parseNumber var="num1" type="number" value="${reportVO.inStateCode.charAt(0)}" />
<fmt:parseNumber var="num2" type="number" value="${reportVO.inStateCode.charAt(1)}" />

<form:form commandName="reportVO" name="formReprotModify" enctype="multipart/form-data" method="post">
	<form:hidden path="inSeq"/>
	<form:hidden path="inFsseq"/>
	<form:hidden path="inStateCode"/>
	
	<form:hidden path="inType" value="${reportVO.inType}"/>
	<form:hidden path="inAgencyCode" value="${reportVO.inAgencyCode}"/>
	<form:hidden path="inPlaceCode" value="${reportVO.inPlaceCode}"/>
	<form:hidden path="inPlaceName" value="${reportVO.inPlaceName}"/>
	<form:hidden path="inPlaceNum" value="${reportVO.inPlaceNum}"/>
	
	<div id="table">		
		<c:if test="${reportVO.inType eq '1'}"><spring:message code="member.type.fa" var="userType"/></c:if>
		<c:if test="${reportVO.inType eq '2'}"><spring:message code="member.type.nofa" var="userType"/></c:if>		
		<div class="doc_no hidden">
			<c:if test="${reportVO.inStateCode eq '99'}"><spring:message code="report.view.saveDocNo" /></c:if>
			<c:if test="${reportVO.inStateCode ne '99'}"><spring:message code="report.view.num" arguments="${reportVO.inPlaceName},${reportVO.inPlaceNum}"/></c:if>
		</div>
		<div class="pageinfo">
			<ul class="right btn-style">
				<li>
					<a class="btn_print" href="<c:url value="/report/print.do"><c:param name="inSeq" value="${reportVO.inSeq}" /></c:url>" target="_blank">
						<spring:message code="button.goPrint" />
					</a>
				</li>
			</ul>
		</div>
		<table class="tbl_add">
			<colgroup>
	   			<col width="100"/>
	   			<col width="150"/>
	   			<col width="100"/>
	   			<col width="150"/>	   			
	   			<col width="100"/>
	   			<col width="150"/>	   			
	   			<col width="100"/>
	   			<col width=""/>
	   		</colgroup>
	   		<tr>
	   			<th><spring:message code="report.list.num"/></th>
   				<td colspan="3"><spring:message code="report.view.num" arguments="${reportVO.inPlaceName},${reportVO.inPlaceNum}"/></td>
	   			<th><spring:message code="report.view.name" /></th>
	   			<td align="left" colspan="3">
					<c:out value="${userType} ${reportVO.inDuty} ${reportVO.inName}"/>
				</td>
	   		</tr>
  			<c:choose>
			<c:when test="${viewDoc eq true}">
				<th>소속</th>
				<td class="form_select" colspan="3">
					<c:out value="${reportVO.inDocPlace}" />
				</td>
				<th><spring:message code="report.view.category1" /></th>
				<td align="left">
					<c:forEach var="cate" items="${category1}">
						<c:if test="${cate.key eq reportVO.inCategory1}"><c:out value="${cate.value}" /></c:if>
					</c:forEach>
				</td>
				<th><spring:message code="report.view.category2" /></th>
				<td align="left">
					<c:forEach var="cate" items="${category2}">
						<c:if test="${cate.key eq reportVO.inCategory2}"><c:out value="${cate.value}" /></c:if>
					</c:forEach>
				</td>				
			</c:when>
			<c:otherwise>
			<tr>
				<th>소속</th>
				<td class="form_select" colspan="3">
					<form:input path="inDocPlace" />
				</td>
				<th><spring:message code="report.view.category1" /></th>
				<td class="form_select">
					<form:select path="inCategory1">
						<c:forEach var="cate" items="${category1}">
							<form:option value="${cate.key}" label="${cate.value}" />
						</c:forEach>
					</form:select>
				</td>
				<th><spring:message code="report.view.category2" /></th>
				<td class="form_select">
					<form:select path="inCategory2">
						<c:forEach var="cate" items="${category2}">
							<form:option value="${cate.key}" label="${cate.value}" />
						</c:forEach>
					</form:select>
				</td>				
			</tr>							
			</c:otherwise>
			</c:choose>
			<tr>
				<th><spring:message code="report.view.memo" /></th>
				<td colspan="7">
					<c:if test="${viewDoc eq true}"><c:out value="${reportVO.inMemo}"/></c:if>
					<c:if test="${viewDoc eq false}"><form:input path="inMemo"/></c:if>
				</td>
			</tr>
			<tr>
				<th><spring:message code="board.header.title"/></th>
				<td colspan="7">					
					<c:if test="${viewDoc eq true}"><c:out value="${reportVO.inSubject}"/></c:if>
					<c:if test="${viewDoc eq false}">
						<form:input id="title" path="inSubject" maxlength="150" cssClass="txt"/>						
					</c:if>					
				</td>
			</tr>
			<tr>
	   			<th>
	   				<spring:message code="board.view.content" />
	   			</th>
	   			<td colspan="7">
	            	<c:if test="${viewDoc eq true}">
	            		<c:out value="${reportVO.inContent}" escapeXml="false"/>
	            	</c:if>
	            	<c:if test="${viewDoc eq false}">
			            <form:textarea path="inContent" rows="5" cols="58" htmlEscape="false"/>&nbsp;<form:errors path="inContent" />
	   					<ckeditor:replace replace="inContent" basePath="${pageContext.request.contextPath}/ckeditor/" />
	   					<span><spring:message code="etc.editor.descript"/></span>
		   			</c:if>
	            </td>
	   		</tr>
			<tr>
	   			<th>
	   				<spring:message code="board.view.attach" />1
	   			</th>
	            <td colspan="7">
					<c:if test="${not empty fn:trim(reportVO.inFile1)}">
						<p>
							<a href="/report/download.do?seq=<c:out value="${reportVO.inSeq}"/>&no=1" target="_blank">
					       		<c:out value="${reportVO.inFile1}"/>
					       	</a>
					       	<c:if test="${viewDoc eq false}">
								<!-- <input type="checkbox" name="deleteFile" value="1"/>삭제 -->
								<c:set var="existOrder" value="${true}"/>
							</c:if>
						</p>
					</c:if>
					<c:if test="${viewDoc eq false}">
						<p><input type="file" name="fileObj1" class="input_file" size="60" /></p>
					</c:if>
	            </td>
			</tr>
			<tr>
	   			<th>
	   				<spring:message code="board.view.attach" />2
	   			</th>
	            <td colspan="7"> 
					<c:if test="${not empty fn:trim(reportVO.inFile2)}">
						<p>
							<a href="/report/download.do?seq=<c:out value="${reportVO.inSeq}"/>&no=2" target="_blank">
					       		<c:out value="${reportVO.inFile2}"/>
					       	</a>
					       	<c:if test="${viewDoc eq false}">
								<!-- <input type="checkbox" name="deleteFile" value="2"/>삭제 -->
								<c:set var="existOrder" value="${true}"/>
							</c:if>
						</p>
					</c:if>
					<c:if test="${viewDoc eq false}">
						<p><input type="file" name="fileObj2" class="input_file" size="60" /></p>
					</c:if>
				</td>
			</tr>
			<tr>
	   			<th>
	   				<spring:message code="board.view.attach" />3
	   			</th>
	            <td colspan="7">
					<c:if test="${not empty fn:trim(reportVO.inFile3)}">
						<p>
							<a href="/report/download.do?seq=<c:out value="${reportVO.inSeq}"/>&no=3" target="_blank">
					       		<c:out value="${reportVO.inFile3}"/>
					       	</a>
					       	<c:if test="${viewDoc eq false}">
								<!-- <input type="checkbox" name="deleteFile" value="3"/>삭제 -->
								<c:set var="existOrder" value="${true}"/>
							</c:if>
						</p>
					</c:if>
					<c:if test="${viewDoc eq false}">
						<input type="file" name="fileObj3" class="input_file" size="60" />
					</c:if>
				</td>
			</tr>
			<tr>
				<th>
					<spring:message code="report.view.infodate" />
				</th>
				<td colspan="7">
					<c:if test="${viewDoc eq true}">
						<c:out value="${reportVO.inInfodate}"/>
					</c:if>
					<c:if test="${viewDoc eq false}">
		   				<form:input path="strInfodate" cssClass="txt" readonly="true" value="${reportVO.inInfodate}" />
					</c:if>
				</td>
			</tr>
			<tr>
				<th>
					<spring:message code="report.view.state"/>
				</th>
				<td colspan="7">
					<span class="save"><c:out value="${reportVO.stateCodeName}" /></span>
					<span style="color:#c8c8c8;">(<c:out value="${reportVO.inStateCode}"/>)</span>
				</td>
			</tr>
			<c:if test="${!empty reportVO.inOfflineUserid}">
				<tr>
					<th>
						<spring:message code="menu.report.manage.offline_write"/>
					</th>
					<td colspan="7">
						<c:out value="${offUser.place1Str} " />
						<c:out value="${offUser.dutyStr} " />
						<c:out value="${offUser.name}" />(<c:out value="${offUser.userid}" />)
					</td>
				</tr>
			</c:if>			
		</table>
		
		<c:if test="${reportVO.stateCodeName eq '결재 완료'}">
			<table class="tbl_add">
				<colgroup>
					<col width="200" />
					<col width="200" />	
					<col width="200" />	
					<col width="200" />	
					<col width="200" />	
					<col width="200" />	
					<col width="200" />	
					<col width="200" />					
				</colgroup>
				<tr class="th-bg">
					<th style="text-align:center;"><spring:message code="report.type.newsflash" /></th>
					<th style="text-align:center;"><spring:message code="report.type.judge" /></th>
					<th style="text-align:center;"><spring:message code="report.type.middle" /></th>
					<th style="text-align:center;"><spring:message code="report.type.notice" /></th>
					<th style="text-align:center;"><spring:message code="report.type.record" /></th>
					<th style="text-align:center;"><spring:message code="report.type.survey" /></th>
					<th style="text-align:center;"><spring:message code="report.type.reference" /></th>
				</tr>
				<tr>
					<td align="center"><c:if test="${reportVO.inJudge eq 1}">○</c:if></td>
					<td align="center"><c:if test="${reportVO.inJudge eq 2}">○</c:if></td>
					<td align="center"><c:if test="${reportVO.inJudge eq 3}">○</c:if></td>
					<td align="center"><c:if test="${reportVO.inJudge eq 4}">○</c:if></td>
					<td align="center"><c:if test="${reportVO.inJudge eq 5}">○</c:if></td>
					<td align="center"><c:if test="${reportVO.inJudge eq 6}">○</c:if></td>
					<td align="center"><c:if test="${reportVO.inJudge eq 7}">○</c:if></td>
				</tr>
			</table>
		</c:if>
		 
		<c:if test="${reportVO.inStateCode ne '99'}">
				
			<%-- 본청 --%>
			<c:if test="${num1 eq 3 && num2 >= 2}">
				<table class="tbl_add">
					<colgroup>
						<col width="125">
						<col width="125">
						<col width="125">
						<col width="125">
						<col width="125">
						<col width="125">
						<col width="125">
						<col width="125">						
					</colgroup>
					<tr class="th-bg">
						<th>본청</th>
						<th style="text-align:center;"><spring:message code="report.type.newsflash"/></th>
						<th style="text-align:center;"><spring:message code="report.type.judge"/></th>
						<th style="text-align:center;"><spring:message code="report.type.middle"/></th>
						<th style="text-align:center;"><spring:message code="report.type.notice"/></th>
						<th style="text-align:center;"><spring:message code="report.type.record"/></th>
						<th style="text-align:center;"><spring:message code="report.type.survey"/></th>
						<th style="text-align:center;"><spring:message code="report.type.reference"/></th>
					</tr>
					<tr>
						<td align="center">
							<c:choose>
								<c:when test="${fn:trim(juSection.juPlace1) ne ''}"><c:out value="${juSection.juPlace1}" /></c:when>
								<c:when test="${fn:trim(juHead.juPlace1) ne ''}"><c:out value="${juHead.juPlace1}" /></c:when>
								<c:when test="${docGroupCode eq 3}"><c:out value="${reportVO.inPlace1}" /></c:when>
								<c:otherwise><spring:message code="msg.noInfo"/></c:otherwise>
							</c:choose>
						</td>	
						<c:choose>
							<c:when test="${myDutiesCode eq 3 && viewDoc eq false}">
								<td align="center"><form:radiobutton path="inJudge" value="1" /></td>
								<td align="center"><form:radiobutton path="inJudge" value="2" /></td>
								<td align="center"><form:radiobutton path="inJudge" value="3" /></td>
								<td align="center"><form:radiobutton path="inJudge" value="4" /></td>
								<td align="center"><form:radiobutton path="inJudge" value="5" /></td>
								<td align="center"><form:radiobutton path="inJudge" value="6" /></td>
								<td align="center"><form:radiobutton path="inJudge" value="7" /></td>
							</c:when>
							<c:otherwise>
								<td align="center"><c:if test="${reportVO.inJudge eq 1}">○</c:if></td>
								<td align="center"><c:if test="${reportVO.inJudge eq 2}">○</c:if></td>
								<td align="center"><c:if test="${reportVO.inJudge eq 3}">○</c:if></td>
								<td align="center"><c:if test="${reportVO.inJudge eq 4}">○</c:if></td>
								<td align="center"><c:if test="${reportVO.inJudge eq 5}">○</c:if></td>
								<td align="center"><c:if test="${reportVO.inJudge eq 6}">○</c:if></td>
								<td align="center"><c:if test="${reportVO.inJudge eq 7}">○</c:if></td>
							</c:otherwise>
						</c:choose>					
					</tr>
					<%-- <c:if test="${myDutiesCode eq '2' or myDutiesCode eq '3'}">
						<tr>
							<td><spring:message code="report.state.chiefApproval"/></td>
							<td align="center"><c:if test="${reportVO.inJudge eq 1}">○</c:if></td>
							<td align="center"><c:if test="${reportVO.inJudge eq 2}">○</c:if></td>
							<td align="center"><c:if test="${reportVO.inJudge eq 3}">○</c:if></td>
							<td align="center"><c:if test="${reportVO.inJudge eq 4}">○</c:if></td>
							<td align="center"><c:if test="${reportVO.inJudge eq 5}">○</c:if></td>
							<td align="center"><c:if test="${reportVO.inJudge eq 6}">○</c:if></td>
							<td align="center"><c:if test="${reportVO.inJudge eq 7}">○</c:if></td>
						</tr>
					</c:if> --%>
					<c:if test="${!empty juSection}">
						<tr>
							<th><spring:message code="report.view.appraiser" /></th>
							<td colspan="8">
								<c:out value="${juSection.juDuty}" />
								<c:out value="${juSection.juName}" />
								<c:if test="${juSection.juDutyCode eq '2'}"><spring:message code="member.view.rptPermission.section" /></c:if>
								<c:if test="${juSection.juDutyCode eq '3'}"><spring:message code="member.view.rptPermission.head" /></c:if>
							</td>
						</tr>
						<tr>
							<th><spring:message code="report.view.opinion" /></th>
							<td colspan="8"><c:out value="${juSection.juMessage}" /></td>
						</tr>
						<tr>
							<th><spring:message code="report.view.reportDate" /></th>
							<td colspan="8"><c:out value="${juSection.juChkdate}" /></td>
						</tr>
					</c:if>
					<c:if test="${!empty juHead}">
						<tr>
							<th><spring:message code="report.view.appraiser" /></th>
							<td colspan="8">
								<c:out value="${juHead.juDuty}" />
								<c:out value="${juHead.juName}" />
								<c:if test="${juHead.juDutyCode eq '2'}"><spring:message code="member.view.rptPermission.section" /></c:if>
								<c:if test="${juHead.juDutyCode eq '3'}"><spring:message code="member.view.rptPermission.head" /></c:if>
							</td>
						</tr>
						<tr>
							<th><spring:message code="report.view.opinion" /></th>
							<td colspan="8"><c:out value="${juHead.juMessage}" /></td>
						</tr>
						<tr>
							<th><spring:message code="report.view.reportDate" /></th>
							<td colspan="8"><c:out value="${juHead.juChkdate}" /></td>
						</tr>
					</c:if>
				</table>
			</c:if>
		</c:if>
	</div>

	<div class="boardviewinfo">
		<ul class="right btn-style mb-checkbox">
			<c:if test="${viewDoc eq false}">
				<c:if test="${reportVO.inStateCode eq '99'}">
					<li>
						<a href="javascript:fn_report();"><spring:message code="button.goReport" /></a>
					</li>
					<li>
						<a href="javascript:fn_save();"><spring:message code="button.goSaveTemp" /></a>
					</li>
				</c:if>
				
					<c:if test="${num1 < 3 && num2 eq 4}">
						<input type="checkbox" name="inReport" id="checkReport" value="1"/><label for="checkReport"><spring:message code="report.type.fullReport" /></label>
					</c:if>
					<li>
						<a href="javascript:fn_update();"><spring:message code="button.goModify" /></a>
					</li>
				<!-- 20180504 임시저장이랑 결재 완료 되었을때 안보이게 하려구 99(임시저장) 34(결재완료) -->
				<c:if test="${reportVO.inStateCode ne '99' and reportVO.inStateCode ne '34'}">
					<li>
						<input type="hidden" name="seletedSeq" value="${reportVO.inSeq}"/>
						<a href="javascript:fn_delete();"><spring:message code="button.goDelete" /></a>
					</li>
				</c:if>
			</c:if>
			<li>
				<a href="javascript:history.back();"><spring:message code="button.goBack" /></a>
			</li>
		</ul>
		<%-- myDutiesCode : <input type="text" value="${myDutiesCode}"> <br/>
		inStateCode : <input type="text" value="${inStateCode}"><br/>
		num1 : <input type="text" value="${num1}"><br/>
		viewDoc : <input type="text" value="${viewDoc}"> --%>
	</div>
</form:form>

<script type="text/javascript" src="<c:url value='/validator.do'/>"></script>
<validator:javascript formName="reportVO" staticJavascript="false" xhtml="true" cdata="false"/>
<script type="text/javaScript" defer="defer">
	$(function(){
		$('#strInfodate').datepicker({dateFormat: 'yy-mm-dd'});
		
		var result = "<c:out value="${submitResultMsg}"/>";
		if (result != "") {
			alert(result);
		}
	});

	function fn_report() {
		if (confirm("보고하시겠습니까?")){
			frm = document.formReprotModify;
			var stateCode = "<c:out value="${inStateCode}"/>";
			if (stateCode == "" || stateCode == "99")
				frm.inStateCode.value = "${myGroupCode}" + "1";
			frm.inContent.value = encodeURIComponent(CKEDITOR.instances.inContent.getData());
			
			if(!validateReportVO(frm)){
		        return;
		    }else{
		    	frm.action = "<c:out value='/report/updateReport.do'/>";
		       	frm.submit();
		    }
		}
	}
	function fn_update() {
		frm = document.formReprotModify;
		frm.inContent.value = encodeURIComponent(CKEDITOR.instances.inContent.getData());
		if(!validateReportVO(frm)){
	        return;
	    }else{
	    	frm.action = "<c:out value='/report/update.do'/>";
	       	frm.submit();
	    }
	}
	function fn_save() {
		frm = document.formReprotModify;
	
		frm.inContent.value = encodeURIComponent(CKEDITOR.instances.inContent.getData());
		
		if(!validateReportVO(frm)){
	        return;
	    }else{
	    	frm.action = "<c:out value='/report/update.do'/>";
	       	frm.submit();
	    }
	}
	function fn_delete() {
		if (confirm("<spring:message code="confirm.msg.askDel" />")){
			document.formReprotModify.action = "<c:out value='/report/deleteAndSaveList.do' />";
			document.formReprotModify.submit();
		}
	}
</script>