<?php
header('Content-Type: application/json');
include('../class/include.php');
if (!Account::isAuthentified() || !CSRF::isAjaxRequest())
{
    die("Bad request");
}

$all_server_predata = Server::GetAllServer();
$list = [];

foreach ($all_server_predata as $data)
{
	if ($data['last_update'] + 60 > time())
	{
	    $button_payload = '<button style="padding: 0; border: none; background: none; color: gray;" href="./viewserver?id='.$data['id'].'">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x-circle table-link"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path><circle cx="12" cy="12" r="3"></circle></svg></button>';

	    $ip_data = explode(':', $data['server_ip']);

	    array_push($list, ["DT_RowId" => "server-".$data['id'], $data['server_name'], $ip_data[0], $ip_data[1], $data['server_rcon'], $data['server_users'], date('d/m/Y à H:i:s', $data['last_update']), "&nbsp;".$button_rcon."&nbsp;".$button_payload]);
	}
}

echo json_encode(['data' => $list]);
?>
