<%@ 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>
var tableToExcel = (function(){
	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>
<script type="text/javascript">
$(function()
{
	//사용버튼/삭제
	$(".useCup").click(function()
	{
		var result = $(this).attr("val");
		if(result>0)
			window.location = $(this).attr("value")+"&token="+$("#token").val();
		else
			alert("사용할 쿠폰이 없습니다.");
	});
	//삭제, 수정
	$(".delBtn").click(function()
	{
		var temp= $(this).parents("tr").find("input");
		var a="&cupon_request_date="+$(temp[0]).val();
		var b="&cupon_current="+$(temp[1]).val();
		var c="&cupon_use="+$(temp[2]).val();
		var d="&cupon_result="+$(temp[3]).val();
		if($(temp[4]).prop("checked"))
		{
			e="&server_upgrade=o"
		}
		if($(temp[5]).prop("checked"))
		{
			e="&server_upgrade=x"
		}
		var f="&cupon_end_date="+$(temp[6]).val();
		var g="&cupon_note="+$(temp[7]).val();
		window.location = $(this).attr("value")+"&token="+$("#token").val()+a+b+c+d+e+f+g;
	});
});
</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="row">
					<div class="col-lg-2">
						<a class="btn btn-outline btn-default" href="IdcCuponWriteForm.cup">쿠폰등록</a>
						<a class="btn btn-outline btn-default"  onclick="tableToExcel('table','name')">엑셀</a>
					</div>
					<div class="col-lg-offset-8 col-lg-2">
						<form action="IdcCuponList.cup" method="POST">
							<div class="input-group">
								<input type="text" class="form-control" name="searchContent" placeholder="고객명 OR IP" value="${searchContent }">
								<span class="input-group-btn">
									<input type="submit" class="btn btn-info btn-outline" value="검색">
								</span>
							</div>
						</form>
					</div>
				</div>
	   			<div class="table-responsive" id="table">
	   				<input type="hidden" id="token">
					<table class="table table-bordered table-hover table-striped">
						<thead>
							<tr>
								<td>No</td>
								<td>상태</td>
								<td>고객코드</td>
								<td>서비스코드</td>
								<td>고객명</td>
								<td>장비명</td>
								<td>IP</td>
								<td>쿠폰발행기준</td>
								<td>쿠폰수량</td>
								<td>사용수량</td>
								<td>전체수량</td>
								<td>업그레이드</td>
								<td>만료일</td>
								<td>비고</td>
								<td>기타</td>
							</tr>
						</thead>
						<tbody>
							<c:forEach  items="${IdcCuponList}" var="temp">
								<tr>
									<td>${temp.num }</td>
									<td>${temp.service_status }</td>
									<td>${temp.client_code }</td>
									<td>
										${temp.service_code }</a>
									</td>
									<td>${temp.client_name }</td>
									<td>${temp.server_code }</td>
									<td>${temp.service_ip }</td>
									<td><input type="date" value="${temp.cupon_request_date }"></td>
									<td>
										<input size="1"type="text" value="${temp.cupon_current }">
										<a class="btn btn-success useCup" href="#" val="${temp.cupon_current }" 
											 value="IdcUseCupon.cup?num=${temp.cupon_num }">사용</a>
									</td>
									<td><input size="1"type="text" value="${temp.cupon_use }"></td>
									<td><input size="1"type="text" value="${temp.cupon_result }"></td>
									<td>
										<c:if test="${temp.server_upgrade=='o' }">
											<input type="radio" name="up${temp.num }"value="o" checked="checked">o
											<input type="radio" name="up${temp.num }"value="x" >x
										</c:if>
										<c:if test="${temp.server_upgrade=='x' }">
											<input type="radio" name="up${temp.num }"value="o">o
											<input type="radio" name="up${temp.num }"value="x"  checked="checked">x
										</c:if>
									</td>
									<td><input type="date"value="${temp.cupon_end_date }"></td>
									<td><input size="1"type="text" value="${temp.cupon_note }"></td>
									<td>
										<a class="btn btn-info delBtn"href="#" class="delBtn" value="IdcCuponModifyForm.cup?&num=${temp.cupon_num }">수정</a>
										<a class="btn btn-danger delBtn" href="#" value="IdcCuponDelete.cup?num=${temp.cupon_num }">삭제</a>
									</td>
								</tr>
							</c:forEach>
						</tbody>
						<tfoot>
						</tfoot>
					</table>
				</div>
				<!-- table-responsive -->
				<div>
					<ul class="pagination" style="margin:0px;">
						<li>
							<a class="btn btn-outline btn-default" href="IdcCuponList.cup?&searchContent=${searchContent}">
								<i class="fa fa-angle-double-left "></i>
							</a>
						</li>
						<li>
							<c:if test="${curPage!=1 }">
								<a class="btn btn-outline_btn-default" href="IdcCuponList.cup?curPage=${curPage-1 }&searchContent=${searchContent}">
									<i class="fa fa-angle-left"></i>
								</a>
							</c:if>
							<c:if test="${curPage==1 }">
								<a class="btn btn-outline_btn-default" href="IdcCuponList.cup?curPage=1&searchContent=${searchContent}">
									<i class="fa fa-angle-left"></i>
								</a>
							</c:if>
						</li>
						<c:forEach var="i" begin="${firstPage }" end="${pageCnt }">
						<li>
							<a class="btn btn-outline btn-defualt" href="IdcCuponList.cup?curPage=${i }&searchContent=${searchContent}">${i}</a>	
						</li>
						</c:forEach>
						<li>
							<c:if test="${curPage!=pageCnt }">
								<a class="btn btn-outline_btn-default" href="IdcCuponList.cup?curPage=${curPage+1 }&searchContent=${searchContent}">
									<i class="fa fa-angle-right"></i>
								</a>
							</c:if>
							<c:if test="${curPage==pageCnt }">
								<a class="btn btn-outline_btn-default" href="IdcCuponList.cup?curPage=${pageCnt }&searchContent=${searchContent}">
									<i class="fa fa-angle-right"></i>
								</a>
							</c:if>
						</li>
						<li>
							<a class="btn btn-outline btn-default" href="IdcCuponList.cup?curPage=${pageCnt }&searchContent=${searchContent}">
								<i class="fa fa-angle-double-right "></i>
							</a>
						</li>
					</ul>
					<!-- ul -->
				</div>
				<!-- UL DIV -->
			</div>
			<!-- panel-body -->
		</div>
		<!-- panel panel-default -->
	</div>
	<!-- col-lg-12 -->
</div>
<!-- row -->
<!-- /#page-wrapper -->
