35 lines
810 B
PHP
35 lines
810 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
require __DIR__ . "/db.php";
|
|
|
|
$rows = $pdo->query("
|
|
SELECT uid, entradas, saidas, online, blocked,
|
|
TIMESTAMPDIFF(SECOND, last_seen, NOW()) AS ago
|
|
FROM contadores
|
|
ORDER BY online DESC, uid ASC
|
|
")->fetchAll();
|
|
|
|
// Totais
|
|
$sumEntradas = 0;
|
|
$sumSaidas = 0;
|
|
$onlineCount = 0;
|
|
$offlineCount = 0;
|
|
|
|
foreach ($rows as $r) {
|
|
$sumEntradas += (int)$r['entradas'];
|
|
$sumSaidas += (int)$r['saidas'];
|
|
if ($r['online'] == 1) $onlineCount++;
|
|
else $offlineCount++;
|
|
}
|
|
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
|
|
header("Pragma: no-cache");
|
|
header("Expires: 0");
|
|
|
|
echo json_encode([
|
|
"rows" => $rows,
|
|
"online" => $onlineCount,
|
|
"offline" => $offlineCount,
|
|
"entradas" => $sumEntradas,
|
|
"saidas" => $sumSaidas,
|
|
]);
|