91 lines
3.5 KiB
PHP
91 lines
3.5 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$secret_token = 'lili_admin_2026';
|
|
if (($_GET['token'] ?? '') !== $secret_token) {
|
|
die('Acceso denegado. Se requiere un token válido.');
|
|
}
|
|
|
|
$db = db();
|
|
|
|
// Get active users (last 10 minutes)
|
|
$stmt = $db->query("SELECT COUNT(*) FROM visitor_logs WHERE last_activity > DATE_SUB(NOW(), INTERVAL 10 MINUTE)");
|
|
$active_users = $stmt->fetchColumn();
|
|
|
|
// Get country distribution for active users
|
|
$stmt = $db->query("SELECT country, country_code, lat, lon, COUNT(*) as count FROM visitor_logs WHERE last_activity > DATE_SUB(NOW(), INTERVAL 10 MINUTE) GROUP BY country_code");
|
|
$locations = $stmt->fetchAll();
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="refresh" content="30">
|
|
<title>Admin Dashboard - Lili Records</title>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
|
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
|
|
<style>
|
|
body { background: #0f172a; color: white; font-family: 'Inter', sans-serif; }
|
|
.card { background: rgba(30, 41, 59, 0.7); border: 1px solid rgba(255,255,255,0.1); color: white; backdrop-filter: blur(10px); }
|
|
#map { height: 500px; border-radius: 15px; margin-top: 20px; }
|
|
.stat-value { font-size: 3rem; font-weight: bold; color: #00e676; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container py-5">
|
|
<div class="row mb-4">
|
|
<div class="col-md-12 text-center">
|
|
<h1>Panel de Administración Real-Time</h1>
|
|
<p class="text-secondary">Lili Records Radio Statistics</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-4">
|
|
<div class="card p-4 text-center">
|
|
<h5>Usuarios Conectados</h5>
|
|
<div class="stat-value"><?= $active_users ?></div>
|
|
<p class="text-secondary">En los últimos 10 minutos</p>
|
|
</div>
|
|
|
|
<div class="card p-4 mt-4">
|
|
<h5>Distribución por País</h5>
|
|
<ul class="list-group list-group-flush bg-transparent">
|
|
<?php foreach ($locations as $loc): ?>
|
|
<li class="list-group-item bg-transparent text-white border-secondary d-flex justify-content-between">
|
|
<span><?= htmlspecialchars($loc['country']) ?></span>
|
|
<span class="badge bg-primary"><?= $loc['count'] ?></span>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-8">
|
|
<div class="card p-3">
|
|
<h5>Mapa de Conexiones</h5>
|
|
<div id="map"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
|
<script>
|
|
const map = L.map('map').setView([20, 0], 2);
|
|
L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png', {
|
|
attribution: '© OpenStreetMap contributors'
|
|
}).addTo(map);
|
|
|
|
const locations = <?= json_encode($locations) ?>;
|
|
locations.forEach(loc => {
|
|
if (loc.lat && loc.lon) {
|
|
L.marker([loc.lat, loc.lon])
|
|
.addTo(map)
|
|
.bindPopup(`<b>${loc.country}</b><br>${loc.count} usuario(s)`);
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|