prepare(" UPDATE contadores SET note = ? WHERE uid = ? "); $stmt->execute([$note, $uid]); header("Location: console.php"); exit; } // ===================================================== // REMOVER // ===================================================== if (isset($_GET['remove'])) { $uid = $_GET['remove']; $pdo->prepare(" DELETE FROM contadores WHERE uid = ? ")->execute([$uid]); header("Location: console.php"); exit; } // ===================================================== // BLOQUEAR / DESBLOQUEAR // ===================================================== if (isset($_GET['toggle'])) { $uid = $_GET['toggle']; $pdo->prepare(" UPDATE contadores SET blocked = 1 - blocked WHERE uid = ? ")->execute([$uid]); header("Location: console.php"); exit; } // ===================================================== // SORT // ===================================================== $sort = $_GET['sort'] ?? 'state'; $orderSql = ($sort === 'uid') ? "ORDER BY uid ASC" : "ORDER BY online DESC, uid ASC"; // ===================================================== // QUERY // ===================================================== $sql = " SELECT uid, note, entradas, saidas, online, blocked, current_broker, rssi, heap, uptime, last_seen, TIMESTAMPDIFF(SECOND, last_seen, NOW()) AS ago FROM contadores $orderSql "; $stmt = $pdo->query($sql); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); // ===================================================== // TOTAIS // ===================================================== $sumEntradas = 0; $sumSaidas = 0; $onlineCount = 0; $offlineCount = 0; foreach ($rows as $r) { $sumEntradas += (int)$r['entradas']; $sumSaidas += (int)$r['saidas']; if ((int)$r['online'] === 1) { $onlineCount++; } else { $offlineCount++; } } ?>
| UID | NOTA | ENTRADAS | SAÍDAS | ESTADO | BROKER | RSSI | HEAP | UPTIME | ÚLTIMO | AÇÕES |
|---|---|---|---|---|---|---|---|---|---|---|
| = htmlspecialchars($r['uid']) ?> | = (int)$r['entradas'] ?> | = (int)$r['saidas'] ?> | = $state ?> | = $broker ?> | = isset($r['rssi']) ? $r['rssi'] . " dBm" : "-" ?> | = isset($r['heap']) ? number_format((int)$r['heap']) : "-" ?> | = $lastSeen ?> |