From 4326c4f9601d72e283ac5795c614135222a5e8c8 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Tue, 17 Feb 2026 17:13:55 +0000 Subject: [PATCH] Auto commit: 2026-02-17T17:13:55.696Z --- admin.php | 65 ++++++++++++++++++++++++++++++++++++++++++- api/song_requests.php | 26 +++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/admin.php b/admin.php index 9c2e985..16f0fa7 100644 --- a/admin.php +++ b/admin.php @@ -96,6 +96,25 @@ $locations = $stmt->fetchAll(); +
+
+
+
Top 5 Artistas Más Pedidos
+
+

Cargando estadísticas...

+
+
+
+
+
+
Top 5 Canciones Más Pedidas
+
+

Cargando estadísticas...

+
+
+
+
+
@@ -186,6 +205,46 @@ $locations = $stmt->fetchAll(); } } + async function fetchStats() { + const artistsDiv = document.getElementById('top-artists'); + const songsDiv = document.getElementById('top-songs'); + try { + const response = await fetch('api/song_requests.php?action=stats'); + const data = await response.json(); + + if (data.success) { + if (data.top_artists.length === 0) { + artistsDiv.innerHTML = '

Sin datos aún

'; + } else { + artistsDiv.innerHTML = '
' + + data.top_artists.map((item, index) => ` +
+ ${index + 1}. ${item.artist} + ${item.count} peticiones +
+ `).join('') + '
'; + } + + if (data.top_songs.length === 0) { + songsDiv.innerHTML = '

Sin datos aún

'; + } else { + songsDiv.innerHTML = '
' + + data.top_songs.map((item, index) => ` +
+
+ ${index + 1}. ${item.song}
+ ${item.artist} +
+ ${item.count} peticiones +
+ `).join('') + '
'; + } + } + } catch (error) { + console.error('Error fetching stats:', error); + } + } + async function updateStatus(id, action) { if (action === 'delete' && !confirm('¿Estás seguro de eliminar esta petición?')) return; @@ -210,7 +269,11 @@ $locations = $stmt->fetchAll(); } fetchRequests(); - setInterval(fetchRequests, 15000); + fetchStats(); + setInterval(() => { + fetchRequests(); + fetchStats(); + }, 15000); diff --git a/api/song_requests.php b/api/song_requests.php index 42ab7ec..11d0d00 100644 --- a/api/song_requests.php +++ b/api/song_requests.php @@ -53,7 +53,33 @@ if ($method === 'POST') { } if ($method === 'GET') { + $action = $_GET['action'] ?? 'list'; + + if ($action === 'stats') { + try { + // Top artists + $stmt = $db->query("SELECT artist, COUNT(*) as count FROM song_requests GROUP BY artist ORDER BY count DESC LIMIT 5"); + $top_artists = $stmt->fetchAll(); + + // Top songs + $stmt = $db->query("SELECT artist, song, COUNT(*) as count FROM song_requests GROUP BY artist, song ORDER BY count DESC LIMIT 5"); + $top_songs = $stmt->fetchAll(); + + echo json_encode([ + 'success' => true, + 'top_artists' => $top_artists, + 'top_songs' => $top_songs + ]); + } catch (Exception $e) { + echo json_encode(['success' => false, 'error' => $e->getMessage()]); + } + exit; + } + try { + // Auto-archive requests older than 2 hours (7200 seconds) + $db->query("UPDATE song_requests SET status = 'played' WHERE status = 'pending' AND created_at < (NOW() - INTERVAL 2 HOUR)"); + $status = $_GET['status'] ?? 'pending'; $limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 10;