<?php
//ini_set('session.gc_maxlifetime', 86400);

//session_set_cookie_params(86400);
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.');
}
mysqli_query($conn, "UPDATE config_admin Set TimerOnline = '".date('d/m/Y H:i:s')."' WHERE Account = '".$_SESSION['UserName']."'");
$phantich = mysqli_query($conn, "Select * From config_server WHERE ServerID = '".$_REQUEST['sv']."'");
if(!mysqli_num_rows($phantich)){
die('<center>Máy chủ không tồn tại</center>');
}
$phantich_a = mysqli_fetch_assoc($phantich);


$url    = file_get_contents("http://14.225.17.145:8088/efunsendreward?serverCode=".$_REQUEST['sv']."&title={%22type%22:%22getrank%22}&content=FightPower");
$phantichList = explode('["',$url);
echo '<table class="table table-bordered" style="width: 100%; margin-bottom: 4rem; background-color: transparent;">
<thead>
  <tr>
    <th>Hạng</th>
    <th>ID Nhân Vật</th>
    <th>Nhân Vật</th>
    <th>Lực Chiến</th>
  </tr>
</thead>
<tbody>
';
for($i=1;$i<=count($phantichList)-1;$i++){
$phantichnew = explode('"]',$phantichList[$i]);
$phantich_AA = explode(',',$phantichnew[0]);
// =====> dwID:1048660,Name:Sáu-Bảnh,Rank:5,Number:8810347
$Number = explode(':',$phantich_AA[3]);
$ViTri = explode(':',$phantich_AA[2]);
$UserName = explode(':',$phantich_AA[1]);
$dwID = explode(':',$phantich_AA[0]);

if($ViTri[1] == 1){
        $phanthuong = '%3Bitem,210160,1';
} else if($ViTri[1] == 2){
        $phanthuong = '%3Bitem,210161,1';
} else if($ViTri[1] == 3){
        $phanthuong = '%3Bitem,210162,1';
} else if($ViTri[1] >= 4 and $ViTri[1] <= 10){
        $phanthuong = '%3Bitem,210163,1';
} else if($ViTri[1] >= 11 and $ViTri[1] <= 50){
        $phanthuong = '%3Bitem,210164,1';
}
if($ViTri[1] <= 10){
 echo '<tr>
 <td class="font-weight-medium">'.$ViTri[1].'</td>
 <td>'.$dwID[1].'</td>	
 <td>'.$UserName[1].'</td>
 <td>'.number_format($Number[1]).'</td>							  					 
</tr> ';
}
}
echo '</tbody></table>';