<?php

include "konak.php";
$sekarang = date('Y-m-d H:i:s');
date_default_timezone_set('asia/jakarta');


$serversupport = "";

if(!isset($_POST['cek'])){ 

    echo "cek server support not post";
    die(); 
}
$serversupport = $_POST['cek'];   
if ($serversupport== "") {
    echo "empty cek server support";
    die();
}
$limitcek = "";

if ($serversupport == "frp") {
    $limitcek =  'limitleftfrp';
}

if ($serversupport == "fdl") {
    $limitcek =  'limitleftfdl';
}

if ($serversupport == "flash") {
    $limitcek =  'limitleftedl';
}
if ($serversupport == "ubl") {
    $limitcek =  'limitleftubl';
}
$sekarang = date('Y-m-d H:i:s');
$data = mysqli_query($koneksi, "SELECT * FROM server WHERE status = 'ON' and delay <= '".$sekarang."' and serversupport LIKE '%".$serversupport."%' and $limitcek > 0 ");
$user = mysqli_fetch_array($data);
$jumlah = mysqli_num_rows($data);
if ($jumlah > 0 ) {
    $jsonarray = [
        "serversupport"    => $serversupport,
        "delay"    => $user["delay"],
        "limit" => $user[$limitcek],
        "status" => $user["status"]
    ];
    echo json_encode($jsonarray);
} else {
    $jsonarray = [
        "serversupport"    => $serversupport,
        "delay"    => $sekarang,
        "limit" => 0,
        "status" => "off"
    ];
    echo json_encode($jsonarray);
}
?>