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

//해당 고객의 vpc만 보여줌
function vpcShow(client_code){
	location.href ="vpcInfoExcel.sev?csInfoFlag=true";	
}
//해당고객의 kcs만 보여줌
function kcsShow(client_code){
	location.href ="vpcInfoExcel.sev?csInfoFlag=false";
}
$(function()
{
	//kcs vpc등록중
	$("#selCS").change(function()
	{
		if($(this).val()!="")
		{
			window.location=$(this).val();
		}
	});
	//select 초기화
	$(document).ready(function()
	{
		$("#category").val($("#category").attr("value"));
	});
});

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>

<style>
table {table-layout:fixed;}
td {word-break:break-all; word-wrap:break-word;}
td { font-size: 12px;}

.ulc {overflow: auto;}
.lic {float: left;}

</style>
<!-- 여기가 본 페이지이다 -->
<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> CS정보</h4>
			</div>
			<div class="panel-body">
				<form action="vpcInfoExcel.sev" method="post">
					<div class="input-group col-lg-12">
						<span class="input-group-btn">
							<input type="hidden" name="client_code" id="client_code" value="${client_code}"/>
							<input type="hidden" name="csInfoFlag" id="csInfoFlag" value="${csInfoFlag}"/>	
							<a class="btn btn-outline btn-default" type="button" href="vpcInfo.sev">CS 정보</a>
							<input class="btn btn-outline btn-default" type="button" value="VPC-CS" onclick="vpcShow('${client_code}')">
							<input class="btn btn-outline btn-default" type="button" value="KT-CS" onclick="kcsShow('${client_code}')">
							
							<c:if test="${csInfoFlag eq 'true'}">
								<a class="btn btn-outline btn-default" type="button" onclick="tableToExcel('vpc','name')">엑셀 출력</a>
							</c:if>
							<c:if test="${csInfoFlag ne 'true'}">
								<a class="btn btn-outline btn-default" type="button" onclick="tableToExcel('kcs','name')">엑셀 출력</a>
							</c:if>
														
							<select class="btn btn-info" id="category" name="category" value="${category }">
								<option value="">선택</option>
								<option value="client_name">고객명</option>
								<option value="server_code">장비번호</option>
								<option value="csip">cs-ip</option>
								<option value="service_ip">서버-ip</option>
								<option value="cscode">CS장비</option>
								<option value="connect_domain">연결 도매인</option>
							</select>
						</span>
						<input type="text" class="form-control" id="searchContext" name="searchContext" value=${searchContext }>
						<span class="input-group-btn">
							<input type="submit" class="btn btn-default" value="검색">
						</span>
					</div>
				</form>
				<!-- row -->
				<c:if test="${csInfoFlag == 'true'}">	
		   			<div class="table-responsive">
						<table id="vpc" name="vpc" class="table table-bordered table-hover table-striped">
							<thead>
								<tr>
									<td class="col-md-1">No.</td>
									<td class="col-md-2">서비스 <br>구분</td>
									<td class="col-md-2">고객명</td>
									<td class="col-md-2">VPC-CS<br>장비</td>
									<td class="col-md-2">VPC-CS<br>IP</td>
									<td class="col-md-2">서버IP</td>
									<td class="col-md-2">장비번호</td>
									<td class="col-md-6">연결도메인</td>
									<td class="col-md-4">방화벽 설정</td>
									<td class="col-md-3">최종공격일</td>
									<td class="col-md-4">비고</td>							
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${vpcList}" var="dto">																									
									<tr>											
											<td>${dto.vpc_num}</td>
											<td>${dto.temp}</td>
											<td>${dto.client_name}</td>
											<td>${dto.vpc_code}</td>
											<td>${dto.vpc_csip}</td>
											<td>${dto.service_ip}</td>
											<td>${dto.server_code}</td>
											<td>${dto.vpc_connect_domain}</td>
											<td>${dto.vpc_fireWall}</td>
											<td>${dto.vpc_last_date}</td>
											<td>${dto.vpc_note}</td>																																										
									</tr>									
								</c:forEach>
							</tbody>
							<tfoot>
							</tfoot>
						</table>
					</div>
					<!-- table-responsive -->					
					<!-- UL DIV -->
				</c:if>
				<!-- c:if -->
				<c:if test="${csInfoFlag == 'false'}">	
					<div class="table-responsive">
						<table id="kcs" name="kcs" class="table table-bordered table-hover table-striped">
							<thead>
								<tr>
									<td class="col-md-2">No.</td>
									<td class="col-md-2">서비스<br>구분</td>
									<td class="col-md-2">서버 <br>계정</td>
									<td class="col-md-2">고객명</td>
									<td class="col-md-2">KCS-NO</td>
									<td class="col-md-2">KCS IP</td>
									<td class="col-md-2">서버 IP</td>
									<td class="col-md-2">장비번호</td>
									<td class="col-md-6">사용도메인</td>
									<td class="col-md-6">접속도메인</td>
									<td class="col-md-3">최종공격일</td>
									<td class="col-md-4">비고</td>
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${kcsList}" var="dto">
									<tr>
										<td>${dto.kcs_num}</td>
										<td>${dto.temp}</td>
										<td>${dto.service_admin}</td>
										<td>${dto.client_name}</td>
										<td>${dto.kcs_code}</td>
										<td>${dto.kcs_ip}</td>
										<td>${dto.service_ip}</td>
										<td>${dto.server_code}</td>
										<td>${dto.kcs_use_domain}</td>
										<td>${dto.kcs_connect_domain}</td>
										<td>${dto.kcs_last_date}</td>
										<td>${dto.kcs_note}</td>												
									</tr>
								</c:forEach>
							</tbody>
							<tfoot>
							</tfoot>
						</table>
					</div>
					<!-- table-responsive -->					
					<!-- UL DIV -->
				</c:if>
				<!-- c:if -->
			</div>
			<!-- panel-body -->
		</div>
		<!-- panel panel-default -->
	</div>
	<!-- col-lg-12 -->
</div>
<!-- row -->
<!-- /#page-wrapper -->
