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

//HTML 시작


$chiba_vpn="select count(*) as mkcount from servicedb where service_line = 'vpn' and service_status = 'o' and Client_Code = '$_GET[client_code]'";
$chivpn = @mysql_query($chiba_vpn , $db_connect) or die($db_q_error);
$datachivpn=mysql_fetch_assoc($chivpn);

$chiba_query="select 
(select count(*) from servicedb where service_line = 'normal' and service_status = 'o' and service_sw between 'C00%' and 'C49%' and Client_Code = '$_GET[client_code]') as chiba_01_normal,
(select count(*) from servicedb where service_line = 'defence' and service_status = 'o' and service_sw between 'C00%' and 'C49%' and Client_Code = '$_GET[client_code]') as chiba_01_defence,
(select count(*) from servicedb where service_line = 'solo' and service_status = 'o' and Client_Code = '$_GET[client_code]') as chiba_solo,
(select count(*) from servicedb where service_line = 'test' and service_status = 'o' and service_sw between 'C00%' and 'C49%' and Client_Code = '$_GET[client_code]') as chiba_01_test,
(select count(*) from servicedb where service_line = 'event' and service_status = 'o' and service_sw between 'C00%' and 'C49%' and Client_Code = '$_GET[client_code]') as chiba_01_event,
(select count(*) from servicedb where service_line = 'substitution' and service_status = 'o' and service_sw between 'C00%' and 'C49%' and Client_Code = '$_GET[client_code]') as chiba_01_substitution,

(select count(*) from servicedb where service_line = 'normal' and service_status = 'o' and service_sw between 'C50%' and 'C79%' and Client_Code = '$_GET[client_code]') as chiba_02_normal,
(select count(*) from servicedb where service_line = 'defence' and service_status = 'o' and service_sw between 'C50%' and 'C79%' and Client_Code = '$_GET[client_code]') as chiba_02_defence,
(select count(*) from servicedb where service_line = 'test' and service_status = 'o' and service_sw between 'C50%' and 'C79%' and Client_Code = '$_GET[client_code]') as chiba_02_test,
(select count(*) from servicedb where service_line = 'event' and service_status = 'o' and service_sw between 'C50%' and 'C79%' and Client_Code = '$_GET[client_code]') as chiba_02_event,
(select count(*) from servicedb where service_line = 'substitution' and service_status = 'o' and service_sw between 'C50%' and 'C79%' and Client_Code = '$_GET[client_code]') as chiba_02_substitution";

$chiba = @mysql_query($chiba_query , $db_connect) or die($db_q_error);
$data_chiba=mysql_fetch_assoc($chiba);

$tokyo_query="select
(select count(*) from servicedb where service_line = 'normal' and service_status = 'o' and service_sw between 'C80%' and 'C99%' and Client_Code = '$_GET[client_code]') as normal,
(select count(*) from servicedb where service_line = 'defence' and service_status = 'o' and service_sw between 'C80%' and 'C99%' and Client_Code = '$_GET[client_code]') as defence,
(select count(*) from servicedb where service_line = 'test' and service_status = 'o' and service_sw between 'C80%' and 'C99%' and Client_Code = '$_GET[client_code]') as test,
(select count(*) from servicedb where service_line = 'event' and service_status = 'o' and service_sw between 'C80%' and 'C99%' and Client_Code = '$_GET[client_code]') as event,
(select count(*) from servicedb where service_line = 'substitution' and service_status = 'o' and service_sw between 'C80%' and 'C99%' and Client_Code = '$_GET[client_code]') as substitution";

$tokyo = @mysql_query($tokyo_query , $db_connect) or die($db_q_error);
$data_tokyo=mysql_fetch_assoc($tokyo);

$coupon_query="select service_line, client_code , sum(coupon) From servicedb where service_line NOT IN ( 'vpn', 'test','soloLine','substitution','event' ) and client_code = '$_GET[client_code]'";
$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;}
?>
            <div class="col-lg-2 col-md-2 col-xs-4" style="padding:3px">
			  <table width="100%" border="0"align="left" class="table table-bordered table-condensed info_table" style="margin-bottom:0px" >
                <thead>
                  <tr>
                    <th>도쿄</th>
                    <th class=" ">치바</th>
                    <th class=" ">VPN</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td><?=$data_tokyo[normal]+$data_tokyo[defence]?></td>
                    <td><?=$data_chiba[chiba_01_normal]+$data_chiba[chiba_02_normal]+$data_chiba[chiba_01_defence]+$data_chiba[chiba_02_defence]+$data_chiba[chiba_solo]?></td>
                    <td><?=$datachivpn[mkcount]?></td>
                  </tr>
                </tbody>
              </table>
            </div>
            <div class="col-lg-2 col-md-4 col-xs-5" style="padding:3px">
              <table width="100%" cellpadding="0" cellspacing="0" border="0" class="table table-bordered table-condensed info_table" style="margin-bottom:0px">
                <thead>
                  <tr>
                    <th>일반</th>
                    <th class=" ">방어</th>
                    <th class=" ">전용</th>
                    <th class=" ">이벤트</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td><?=$data_tokyo[normal]+$data_chiba[chiba_01_normal]+$data_chiba[chiba_02_normal]?></td>
                    <td class=" "><?=$data_tokyo[defence]+$data_chiba[chiba_01_defence]+$data_chiba[chiba_02_defence]?></td>
                    <td class=" "><?=$data_chiba[chiba_solo]?></td>
                    <td class=" "><?=$data_tokyo[event]+$data_chiba[chiba_01_event]+$data_chiba[chiba_02_event]?></td>
                  </tr>
                </tbody>
              </table>
            </div>
            <div class="col-lg-2 col-md-3 col-xs-3" style="padding:3px">
              <table width="100%" cellpadding="0" cellspacing="0" border="0" class="table table-bordered table-condensed info_table" style="margin-bottom:0px">
                <thead>
                  <tr>
                    <th>테스트</th>
                    <th>대체</th>
                    <th>장기할인</th>
				    <th>쿠폰</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td><?=$data_tokyo[test]+$data_chiba[chiba_01_test]+$data_chiba[chiba_02_test]?></td>
                    <td class=" "><?=$data_tokyo[tokyo_substitution]+$data_chiba[chiba_01_substitution]+=$data_chiba[chiba_02_substitution]?></td>
<?
$discount_query="select * from servicedb where client_code='$_GET[client_code]' and service_line NOT IN ( 'vpn', 'test', 'event' ) order by service_open_date asc";
$discount = @mysql_query($discount_query , $db_connect) or die($db_q_error);
$data_discount=mysql_fetch_assoc($discount);

//$oneyears = date("Y-m-d", mktime(0,0,0,date(m),date(d),date(Y)-1));



$server_date= explode('-', $data_discount['service_open_date']);
$server_timestamp = mktime('0','0','0',$server_date[1],$server_date[2],$server_date[0]);
$today_timestamp = mktime();

$oneyears = $today_timestamp - 32676480;
$twoyears = $today_timestamp - 65352960;
$threeyears = $today_timestamp - 98029440;

//echo $today_timestamp;
//echo "/";
//echo $oneyears;
$mk_sum=$today_timestamp - $server_timestamp ;

if ( $mk_sum >= 163382400 ){$dis_cnt="30";} 
elseif ( $mk_sum >= 130705920 ){$dis_cnt="25";} 
elseif ( $mk_sum >= 98029440 ){$dis_cnt="20";} 
elseif ( $mk_sum >= 65352960 ) {$dis_cnt="15";}
elseif ( $mk_sum >= 32676480 ) {$dis_cnt="10";}
else {$dis_cnt="0";}

if ($server_timestamp == '0') {$dis_cnt="0";}

//if $data_discount['service_open_date']
?>

					<td><?=$dis_cnt?> %</td>
				    <td onclick="location.href='/IdcCouponUseMK.cup?client_code=<?=$coupon[client_code]?>'" style="cursor: pointer;"><?=$coupon['sum(coupon)']?></td>
                  </tr>
                </tbody>
              </table>
			</div>




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

