<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<script src="IDC/js/setToken.js"></script>
<script>

//방어존1보기
function deffence_zone1(){
	window.location = "deffenceInfoExcel.sev?";
}

//방어존2 보기
function deffence_zone2(){
	window.location = "deffenceInfoExcel.sev?deffence_case=2";
}

// 방어존3 보기
function deffence_zone3(){
	window.location = "deffenceInfoExcel.sev?deffence_case=3";
}

</script>
<script type="text/javascript">
$(function()
{
	//삭제시 하위 있으면 경고
	$(".delID").click(function()
	{
				
		var subC = ".sub"+$(this).attr("value");
		var sub = $(subC);
		if(sub.length>0){
			alert("방어존에 물려있는 방어서비스를 삭제한 후 삭제해 주십시오.");
		}else{			
			
			var result = confirm("정말 삭제하시겠습니까?");
			if(result == true){
				window.location = $(this).attr("uri")+"&token="+$("#token").val();	
			}else{
				return false;
			}
		}
		
	});
	
	//삭제시 경고
	$(".delID2").click(function()
	{
		var result = confirm("정말 삭제하시겠습니까?");
		if(result == true){			
			window.location = $(this).attr("uri")+"&token="+$("#token").val();
		}else{
			return false;
		}
	});
});

var tableToExcel = (function(){
	
	var specialElementHandlers = {
            '#bypassme': function (element, renderer) {
                return true;
            }
	};
	
	var uri = 'data:application/vnd.ms-excel;base64,'
	    , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></head><body><table>{table}</table></body></html>'
	    , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
	    , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }	    
	    
	  return function(table, name) {
	    if (!table.nodeType) table = document.getElementById(table)
	    var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
	    window.location.href = uri + base64(format(template, ctx))
	  }
})();

</script>
<!-- 여기가 본 페이지이다 -->
<div class="row">
	<div class="col-lg-12">
		<div class="panel panel-default">
			<div class="panel-heading">
				<h4><i class="fa fa-desktop fa-fw"></i>방어라인 정보</h4>
			</div>
			<div class="panel-body">
				<div class="btn-group">
					<!-- 윗줄 ㅇㅇ -->
						<input type="hidden" name="client_code" id="client_code" value="${client_code}"/>
						<a class="btn btn-outline btn-default" type="button" href="deffenceInfo.sev?deffence_case=${deffence_case}">방어라인 정보</a>	
						<input class="btn btn-outline btn-default" type="button" value="방어존1" onclick="deffence_zone1()">
						<input class="btn btn-outline btn-default" type="button" value="방어존2" onclick="deffence_zone2()">
						<input class="btn btn-outline btn-default" type="button" value="방어존3" onclick="deffence_zone3()">
						<a class="btn btn-outline btn-default" type="button" value="엑셀" onclick="tableToExcel('table','name')">엑셀 출력</a>												
				</div>
				<!-- row -->
				<input type="hidden" id="token">
	   			<div class="table-responsive">
					<table id="table" class="table table-bordered table-hover table-striped">
						<thead>
							<tr>
								<td>방어존</td>
								<td>ACL</td>
								<td>REAL</td>
								<td>포트</td>
								<td>업체명</td>
								<td>VPC_장비번호</td>
								<td>CS_IP</td>
								<td>장비번호</td>
								<td>연결IP</td>
								<td>도메인</td>
								<td>신청 일자</td>
								<td>신청 시간</td>
								<td>비고</td>			
							</tr>
						</thead>
						<tbody>							
							<c:forEach items="${dlist}" var="dto">
								<!-- 
								<c:if test="${dto.deffence_case eq deffence_case}">
								 -->									
									<tr>
										<td>${dto.deffence_zone}</td>
										<td>${dto.deffence_acl}</td>
										<td>${dto.deffence_real}</td>
										<td>${dto.deffence_port}</td>
										<td>${dto.client_name}</td>
										<td>${dto.vpc_code}</td>
										<td>${dto.vpc_csip}</td>
										<td>${dto.server_code}</td>
										<td>${dto.service_ip}</td>
										<td>${dto.deffence_domain}</td>
										<td>${dto.deffence_request_date}</td>
										<td>${dto.deffence_request_time}</td>
										<td>${dto.deffence_note}</td>														
									</tr>
									<c:forEach items="${subList}" var="sub">
										<c:if test="${dto.deffence_num == sub.deffence_num}">
										<tr>	
											<td colspan="3"></td>											
											<td>${sub.deffence_port}</td>
											<td>${sub.client_name}</td>
											<td>${sub.vpc_code}</td>
											<td>${sub.vpc_csip}</td>
											<td>${sub.server_code}</td>
											<td>${sub.service_ip}</td>
											<td>${sub.deffence_domain}</td>
											<td>${sub.deffence_request_date}</td>
											<td>${sub.deffence_request_time}</td>
											<td>${sub.deffence_note}</td>																						
										</tr>
										</c:if>
									</c:forEach>
								
								<!-- 	
								</c:if>
								 -->									
							</c:forEach>
						</tbody>
						<tfoot>
						</tfoot>
					</table>
				</div>
				<!-- table-responsive -->
				
				<!-- UL DIV -->
			</div>
			<!-- panel-body -->
		</div>
		<!-- panel panel-default -->
	</div>
	<!-- col-lg-12 -->
</div>
<!-- row -->
<!-- /#page-wrapper -->
