<?php
session_start();
include_once('../../config/#Config.php');
if(!$_SESSION['UserName']){
die('<script>window.location.href=\''.$config['site']['url'].'index.php\';</script>');
}
$get_AD = mysqli_query($conn, "Select * From config_admin WHERE Account = '".$_SESSION['UserName']."'");
if(!mysqli_num_rows($get_AD)){
	die('Không đủ quyền.');
}
$getinfo = mysqli_query($conn, "Select * from giftcode WHERE IDEvent = '".$_POST['idevent']."'");
?>
<style>
.discount {
    position: absolute;
    margin-left: 30px;
    margin-top: -25px;
    border: 2px solid #f15a21;
    border-radius: 100px 0 0 100px;
    padding: 2px;
    width: 50px;
    height: 23.5px;
}
.discount p {
    background: #f15a21;
    border-radius: 100px 0 0 100px;
    text-align: center;
    line-height: 0!important;
    font-size: .9em!important;
    padding: 7px;
}
.discount span {
    color: #fff;
    font-size: 11px;
    text-align: center;
    display: inline-block;
    font-weight: 700;
}
</style>
<div class="input-group">
                                                        <div class="input-group-prepend">
                                                            <button class="btn btn-outline-secondary">Tìm Kiếm</button>
                                                            <button type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="dropdown-toggle dropdown-toggle-split btn btn-outline-secondary"><span class="sr-only">Toggle Dropdown</span></button>
                                                        </div>
                                                        <input placeholder="and..." id="textcode" onkeyup="texttimkiemcode();" type="text" class="form-control">
                                                        <div class="input-group-append">
                                                            <button class="btn btn-secondary">Tìm Kiếm</button>
                                                        </div>
                                                    </div>
                                                    <br/>
                                                    <div class="table-responsive" id="tablecode">
                    <table class="table table-bordered" style="width: 100%; margin-bottom: 4rem; background-color: transparent;">
                      <thead>
                        <tr>
                          <th>
                           Mã Code
                          </th>						  
                          <th>
                          Máy Chủ
                          </th>
                          <th>
                           Giới Hạn
                          </th>
						  <th>
                           Bang
                          </th>
                          <th>
                           Thời gian
                          </th>						  					  
                        </tr>
                      </thead>
                      <tbody id="listcode">
      <?php
       $_GET['CauQuery'] = 'TimKiemQuery';
          include_once('../paginator.class.jquery.php'); 
     $qryStr		=	"Select * From giftcode_code WHERE EventID = '".$_POST['idevent']."'";  
		$country	=	mysqli_query($conn,$qryStr);
		$count		=	mysqli_num_rows($country);
		
        $pages = new Paginator($count,9);
        echo '<nav class="" aria-label="Page navigation example"> <ul class="pagination">';
        echo $pages->display_pages();
        echo '</ul></nav>';
        echo '<div class="col-sm-6 text-right">';
        echo "<span class=\"form-inline\">".$pages->display_jump_menu().$pages->display_items_per_page()."</span>";
        echo '</div>';
        echo '<div class="clearfix"></div>';
		$limit	= $pages->limit_start.','.$pages->limit_end;
        $qry 	=	mysqli_query($conn, $qryStr.' LIMIT '.$limit);
        if($count>0){
            while($val	=	mysqli_fetch_array($qry, MYSQLI_ASSOC)){ 
                echo '<tr>
                <td>
                  '.$val['GiftCode'].'
                </td>	
                <td>
                  '.getServerName($val['Server']).'
                </td>	
    <td>
                  '.number_format($val['LimitNhap']).'
                </td>	
       <td>
                  '.$val['dwIDKin'].'
                </td>	
                <td>
                  '.$val['Timer'].'
                </td>						  						 
              </tr>';
        }
		}
    ?>
                      </tbody>
                    </table>		
      </div>	
                    <script>
                                         function TimKiemQuery(caulenh){
                                               $.post('ajax/ajax-search-code.php', {query:caulenh,keyword:$('#textcode').val(),idevent:'<?=$_REQUEST['idevent']?>'},function(data){
                                                $('.table-responsive').html(data);
                                               });
                                        }
                                                function texttimkiemcode(){
                                                    $.post('ajax/ajax-search-code.php', {keyword:$('#textcode').val(),idevent:'<?=$_REQUEST['idevent']?>'}, function(data){
                                                            $('#tablecode').html(data);
                                                    });

                                                }
                                            </script>            
													   