From 3b91c65794bcd65813713516c2398be8acb93731 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Tue, 17 Feb 2026 17:11:08 +0000 Subject: [PATCH] Auto commit: 2026-02-17T17:11:08.758Z --- admin.php | 98 +++++++++++++++++++ api/song_requests.php | 41 +++++++- .../20260217_add_status_to_song_requests.sql | 2 + 3 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 db/migrations/20260217_add_status_to_song_requests.sql diff --git a/admin.php b/admin.php index 686714e..9c2e985 100644 --- a/admin.php +++ b/admin.php @@ -96,6 +96,35 @@ $locations = $stmt->fetchAll(); +
+
+
+
+
Moderación de Peticiones
+ +
+
+ + + + + + + + + + + + + + + + +
ArtistaCanciónSolicitado porFechaEstadoAcciones
Cargando peticiones...
+
+
+
+
@@ -113,6 +142,75 @@ $locations = $stmt->fetchAll(); .bindPopup(`${loc.country}
${loc.count} usuario(s)`); } }); + + async function fetchRequests() { + const tbody = document.getElementById('requests-body'); + try { + const response = await fetch('api/song_requests.php?status=all&limit=50'); + const data = await response.json(); + + if (data.success) { + if (data.requests.length === 0) { + tbody.innerHTML = 'No hay peticiones registradas'; + return; + } + + tbody.innerHTML = data.requests.map(req => ` + + ${req.artist} + ${req.song} + ${req.requester} + ${new Date(req.created_at).toLocaleString()} + + + ${req.status === 'played' ? 'Reproducida' : 'Pendiente'} + + + +
+ ${req.status === 'pending' ? ` + + ` : ''} + +
+ + + `).join(''); + } + } catch (error) { + tbody.innerHTML = 'Error al cargar peticiones'; + } + } + + async function updateStatus(id, action) { + if (action === 'delete' && !confirm('¿Estás seguro de eliminar esta petición?')) return; + + const formData = new FormData(); + formData.append('id', id); + formData.append('action', action); + + try { + const response = await fetch('api/song_requests.php', { + method: 'POST', + body: formData + }); + const data = await response.json(); + if (data.success) { + fetchRequests(); + } else { + alert('Error: ' + data.error); + } + } catch (error) { + alert('Error al procesar la solicitud'); + } + } + + fetchRequests(); + setInterval(fetchRequests, 15000); diff --git a/api/song_requests.php b/api/song_requests.php index 81f3f68..42ab7ec 100644 --- a/api/song_requests.php +++ b/api/song_requests.php @@ -6,6 +6,33 @@ $method = $_SERVER['REQUEST_METHOD']; $db = db(); if ($method === 'POST') { + if (isset($_POST['action'])) { + $action = $_POST['action']; + $id = (int)($_POST['id'] ?? 0); + + if ($id <= 0) { + echo json_encode(['success' => false, 'error' => 'ID inválido']); + exit; + } + + try { + if ($action === 'mark_played') { + $stmt = $db->prepare("UPDATE song_requests SET status = 'played' WHERE id = ?"); + $stmt->execute([$id]); + echo json_encode(['success' => true]); + } elseif ($action === 'delete') { + $stmt = $db->prepare("DELETE FROM song_requests WHERE id = ?"); + $stmt->execute([$id]); + echo json_encode(['success' => true]); + } else { + echo json_encode(['success' => false, 'error' => 'Acción no reconocida']); + } + } catch (Exception $e) { + echo json_encode(['success' => false, 'error' => $e->getMessage()]); + } + exit; + } + $artist = trim($_POST['artist'] ?? ''); $song = trim($_POST['song'] ?? ''); $requester = trim($_POST['requester'] ?? 'Anónimo'); @@ -27,11 +54,21 @@ if ($method === 'POST') { if ($method === 'GET') { try { - $stmt = $db->query("SELECT * FROM song_requests ORDER BY created_at DESC LIMIT 10"); + $status = $_GET['status'] ?? 'pending'; + $limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 10; + + if ($status === 'all') { + $stmt = $db->query("SELECT * FROM song_requests ORDER BY created_at DESC LIMIT $limit"); + } else { + $stmt = $db->prepare("SELECT * FROM song_requests WHERE status = ? ORDER BY created_at DESC LIMIT $limit"); + $stmt->execute([$status]); + } + $requests = $stmt->fetchAll(); echo json_encode(['success' => true, 'requests' => $requests]); } catch (Exception $e) { - echo json_encode(['success' => true, 'requests' => [], 'error' => $e->getMessage()]); + echo json_encode(['success' => false, 'requests' => [], 'error' => $e->getMessage()]); } exit; } + diff --git a/db/migrations/20260217_add_status_to_song_requests.sql b/db/migrations/20260217_add_status_to_song_requests.sql new file mode 100644 index 0000000..919a425 --- /dev/null +++ b/db/migrations/20260217_add_status_to_song_requests.sql @@ -0,0 +1,2 @@ +-- Add status column to song_requests table +ALTER TABLE song_requests ADD COLUMN status ENUM('pending', 'played') DEFAULT 'pending';