<?
// 기본 설정 로딩
require_once 'config.php';
require_once 'function.php';
require_once 'lib.php';
?>

<?

$client_code = $_GET[client_code];
$mkworker = $_GET[mkworker];
$mkid = $_GET[mkid];

$coupon_query = "select service_line, client_code , sum(coupon),clientdb.client_code,clientdb.client_name From servicedb Natural Join clientdb where service_line NOT IN ( 'vpn', 'test','soloLine','substitution' ) and client_code = '$client_code' and service_ip not like '27.125.204%'";
$data_coupon = @mysql_query($coupon_query, $db_connect) or die($db_q_error);
$coupon = mysql_fetch_assoc($data_coupon);
if ($coupon['sum(coupon)'] == null) {$coupon['sum(coupon)'] = 0;}

$query = "select servicedb.service_code, servicedb.client_code,servicedb.service_line,servicedb.server_code,servicedb.service_ip,servicedb.service_open_date,coupon,coupon_use,clientdb.client_code,clientdb.client_name From servicedb Natural Join clientdb where servicedb.service_line NOT IN ( 'vpn', 'test','soloLine','substitution' ) and servicedb.client_code = '$client_code' and service_ip not like '27.125.204%'";
$coupon_data = @mysql_query($query, $db_connect) or die($db_q_error);
$total = mysql_num_rows($coupon_data);

$list_no = (!$_GET[ea]) ? '30' : $_GET[ea];

if ($list_no > $total) {$list_no = $total;}
$total_page = ($total != '0') ? ceil($total / $list_no) : '0';

$page = $_GET[curPage];

if (!$page) {$page = 1;} elseif ($page >= $total_page) {$page = $total_page;} else { $page = $page;}

$next_page = ($page-'1') * $list_no;
$next_no = $next_page + $list_no;

$query = "select servicedb.service_code, servicedb.client_code,servicedb.service_line,servicedb.server_code,servicedb.service_ip,servicedb.service_open_date,coupon,coupon_use,clientdb.client_code,clientdb.client_name From servicedb Natural Join clientdb where servicedb.service_line NOT IN ( 'vpn', 'test','soloLine','substitution' ) and servicedb.client_code = '$client_code' and service_ip not like '27.125.204%' order by service_open_date asc limit " . $next_page . "," . $next_no;
$coupon_data = @mysql_query($query, $db_connect) or die($db_q_error);
?>
<h3>고객명 : <a href="/serviceDetail.sev?client_code=<?=$coupon[client_code]?>"><?=$coupon[client_name]?></a> / 쿠폰발급대상 : <?=$total?> 대 / 전체 남은 수량 : <?=$coupon['sum(coupon)']?> 개</h3>
				<div class="table-responsive" id="table">
	   				<input type="hidden" id="token">
					<table class="table table-bordered table-hover table-striped" style="text-align:center;">
						<thead>
							<tr>
								<th style="text-align:center;">No</th>
								<th style="text-align:center;">발급쿠폰</th>
								<th style="text-align:center;">남은수량</th>
								<th style="text-align:center;">사용완료</th>
<!--								<th>고객명</th>-->
								<th style="text-align:center;">서비스코드</th>
								<th style="text-align:center;">장비명</th>
								<th style="text-align:center;">서버IP</th>
								<th style="text-align:center;">서비스개시일</th>
								<th style="text-align:center;">회선종류</th>
								<th style="text-align:center;">사용</th>
							</tr>
						</thead>
						<tbody>
<?
for ($i = $next_page; $i < $next_no; $i++) {
    $coupon = mysql_fetch_assoc($coupon_data);
    $num = ($total) - $i;
    if ($coupon[coupon] != '0') {$coupon_color = "<font color=red><strong>";} else { $coupon_color = "<font color=blue>";}
    ?>
		<tr>
			<td><?=$num?></td>
			<td><?=$coupon[coupon] + $coupon[coupon_use]?></td>
			<td onclick="location.href='/IdcCouponBuyMK.cup?service_code=<?=$coupon[service_code]?>&client_name=<?=$coupon[client_name]?>&client_code=<?=$coupon[client_code]?>&server_code=<?=$coupon[server_code]?>&coupon=<?=$coupon[coupon]?>&mode=<?=$_GET[mode]?>&mkworker=<?=$mkworker?>&mkid=<?=$mkid?>'" style="cursor: pointer;"><?=$coupon_color?><?=$coupon[coupon]?></font></td>
<!--			<td><?=$coupon[client_name]?></td>-->
			<td><?=$coupon[coupon_use]?></td>
			<td><a href="/serviceDetailSolo.sev?client_code=<?=$coupon[client_code]?>&service_code=<?=$coupon[service_code]?>"><?=$coupon[service_code]?></td>
			<td><?=$coupon[server_code]?></td>
			<td><?=$coupon[service_ip]?></td>
			<td><?=$coupon[service_open_date]?></td>
			<td><?=$coupon[service_line]?></td>
			<td><a href=/IdcCouponBuyMK.cup?service_code=<?=$coupon[service_code]?>&client_name=<?=$coupon[client_name]?>&client_code=<?=$coupon[client_code]?>&server_code=<?=$coupon[server_code]?>&coupon=<?=$coupon[coupon]?>&mode=<?=$_GET[mode]?>&mkworker=<?=$mkworker?>&mkid=<?=$mkid?>>사용하기</a></td>
		</tr>
<?}?>
						</tbody>
						<tfoot>
						</tfoot>
					</table>
				</div>

<div align='center'>
<?
$setup_dir = "http://" . $_SERVER['HTTP_HOST'] . ":6752";
$page_scale = 10;
$page3 = floor(($total_page-'1') / $page_scale);
$n_page = floor(($page-'1') / $page_scale);

if ($n_page > 0) {

    $p_start = (($n_page - 1) * $page_scale)+'1';
    $link = "<a onfocus=blur() href='" . $setup_dir . "/IdcCouponUseMK.cup?client_code=$client_code&ea=$_GET[ea]&curPage=" . $p_start . "'>";
    $link .= "<<";
    $link .= "</a>";
    echo $link . " ";
}
$is = ($n_page * $page_scale)+'1';
for ($i = $is; $i < $is + $page_scale; $i++) {

    if ($i < $total_page+'1') {
        if ($i == $page) {$ib = "<b>$i</b>";} else { $ib = $i;}
        $link = "<a onfocus=blur() href='" . $setup_dir . "/IdcCouponUseMK.cup?client_code=$client_code&ea=$_GET[ea]&curPage=" . $i . "'>";
        $link .= $ib;
        $link .= "</a>";
        echo $link . " ";
    }
}
if ($n_page < $page3) {
    $link = "<a onfocus=blur() href='" . $setup_dir . "/IdcCouponUseMK.cup?client_code=$client_code&ea=$_GET[ea]&curPage=" . $i . "'>";
    $link .= ">>";
    $link .= "</a>";
    echo $link;
}

?>
</div>
<?
//DB닫기
mysql_close($db_connect);
?>
