<?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="align-middle mb-0 table table-borderless table-striped table-hover">
                                            <thead>
                                            <tr>
                                                <th class="text-center">#</th>
                                                <th class="text-center">Tài Khoản</th>
                                                <th class="text-center">Số Seri</th>
                                                <th class="text-center">Mã Thẻ</th>
                                                <th class="text-center">Mệnh Giá</th>
                                                <th class="text-center">Loại</th>
                                                <th class="text-center">Số Dư Trước</th>
                                                <th class="text-center">Số Dư Sau</th>
                                                <th class="text-center">Thời Gian</th>
												<th class="text-center">Tình Trạng</th>
                                            </tr>
                                            </thead>
                                            <tbody>
      <?php
              if($_REQUEST['query']){
                $phantich = explode('&',$_REQUEST['query']);
                for($i=0;$i<=count($phantich);$i++){
                        $phantichnew = explode('=',$phantich[$i]);
                        $_GET[''.$phantichnew[0].''] = $phantichnew[1];
                }
            } 
       $_GET['CauQuery'] = 'TimKiemQuery';
          include_once('../paginator.class.jquery.php'); 
		$condition		=	"";
        $qryStr		=	"select * from logscardnp where UserName like N'%".$_REQUEST['keyword']."%' or Seri like N'%".$_REQUEST['keyword']."%' or PassCard like N'%".$_REQUEST['keyword']."%' or Hash like N'%".$_REQUEST['keyword']."%' or Active like N'%".$_REQUEST['keyword']."%' order by ID DESC";      
		$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="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['Active'] == 0){
				$tinhtrang = '<label class="badge badge-info" aria-expanded="false" data-toggle="dropdown" onClick="loadRecharge(\''.$val['ID'].'\');">Đang chờ</label>';
			}
			if($val['Active'] == 1){
				$tinhtrang = '<label class="badge badge-success" aria-expanded="false" data-toggle="dropdown" onClick="loadRecharge(\''.$val['ID'].'\');">Thành công</label>';
			}			
			if($val['Active'] == 2){
				$tinhtrang = '<label class="badge badge-danger" aria-expanded="false" data-toggle="dropdown" onClick="loadRecharge(\''.$val['ID'].'\');">Bị hủy</label>';
			}
			if($val['Active'] == 3){
				$tinhtrang = '<label class="badge badge-warning" aria-expanded="false" data-toggle="dropdown" onClick="loadRecharge(\''.$val['ID'].'\');">Sai Mệnh giá</label>';
			}				
if($val['Hash'] == 'VCB' or $val['Hash'] == 'MoMo'){
$LoaiThanhToan = $val['Hash'];
$MaNap =  $config['site']['KeyNap']."-".$val['UserName'];
}	 else {
$LoaiThanhToan = $val['TypeCard'];
$MaNap = $val['PassCard'];
}			
                echo ' <tr>
                <td class="text-center text-muted">#'.$n.'</td>
                <td class="text-center text-muted">'.$val['UserName'].'</td>
                <td class="text-center text-muted">'.$val['Seri'].'</td>
                <td class="text-center text-muted">'.$MaNap.'</td>
                <td class="text-center">'.number_format($val['Money']).'</td>
                <td class="text-center">' . nameCardType($LoaiThanhToan) . '</td>
                <td class="text-center">' . number_format($val['SoDuTruoc']) . '</td>
                <td class="text-center">' . number_format($val['SoDuSau']) . '</td>
                <td class="text-center">
                    <div class="badge badge-warning">'.date('d/m/Y H:i:s',$val['Timer']).'</div>
                </td>            
                <td class="text-center">
                '.$tinhtrang.'
                </td>
            </tr>';
            $n++;
            }
        }
    ?>
                                            </tbody>
                                        </table>