<?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.');
}

?>                                        
                    <table class="table table-bordered" style="width: 100%; margin-bottom: 4rem; background-color: transparent;">
                      <thead>
                        <tr>
                          <th>
                            #
                          </th>
                          <th>
                            GiftCode
                          </th>
                          <th>
                           Máy chủ
                          </th>						  
                          <th>
                           Tài khoản
                          </th>
                          <th>
                           Nhân vật
                          </th>
                          <th>
                           Thời gian
                          </th>						  					  
                        </tr>
                      </thead>
                      <tbody id="listcode">
                                                <?php
                                             if($_REQUEST['query']){
                                                 $phantich = explode('&',$_REQUEST['query']);
                                                 for($i=0;$i<=count($phantich);$i++){
                                                         $phantichnew = explode('=',$phantich[$i]);
                                                         $_GET[''.$phantichnew[0].''] = $phantichnew[1];
                                                 }
                                                 if($_GET['keyword']){
                                                    $_REQUEST['keyword'] = $_GET['keyword'];
                                                 }
                                             }   
                                             $_GET['CauQuery'] = 'TimKiemQuery';

          include_once('../paginator.class.jquery.php'); 
		$keyword		=	$_REQUEST['keyword'];
        $qryStr		=	"select * From giftcode_code where EventID = '".$_REQUEST['idevent']."' and (GiftCode like '%$keyword%' or Account like '%$keyword%' or PlayerID like '%$keyword%')";  
        $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>';
		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){
            $n	=	1;
            while($val	=	mysqli_fetch_array($qry, MYSQLI_ASSOC)){ 
              if($val['Account']){
                if($val['PlayerID']){
                $CharNhan = '<font color="red">'.getNameChar($val['Server'],$val['PlayerID']).'</font>';						
                }
                $AccNhan = '<font color="green">'.$val['Account'].'</font>';			
                }
                echo '<tr>
                <td class="font-weight-medium">
                 '.$n.'
                </td>
                <td>
                  '.$val['GiftCode'].'
                </td>	
                <td>
                  '.getServerName($val['Server']).'
                </td>	
    <td>
                  '.$AccNhan.'
                </td>	
       <td>
                  '.$CharNhan.'
                </td>	
                <td>
                  '.$val['Timer'].'
                </td>						  						 
              </tr>';
            $n++;
            }
        }
    ?>
                                            </tbody>
                                        </table>
  
