diff --git a/api/dj_actions.php b/api/dj_actions.php new file mode 100644 index 0000000..48e4855 --- /dev/null +++ b/api/dj_actions.php @@ -0,0 +1,73 @@ + false, 'error' => 'Datos incompletos']); + exit; +} + +try { + $db = db(); + + // Verify Guest DJ status + $stmt = $db->prepare("SELECT dj_day_until FROM fans WHERE name = ?"); + $stmt->execute([$username]); + $dj_day_until = $stmt->fetchColumn(); + + $isGuestDj = $dj_day_until && (strtotime($dj_day_until) > time()); + + if (!$isGuestDj) { + echo json_encode(['success' => false, 'error' => 'No tienes permisos de DJ Invitado activos']); + exit; + } + + if ($action === 'skip') { + // Log skip action + $stmt = $db->prepare("INSERT INTO radio_actions (action_type, performed_by, details) VALUES ('skip', ?, ?)"); + $stmt->execute([$username, "El DJ Invitado ha solicitado saltar la canción"]); + + // Announce in chat + $chatMsg = "🚨 [DJ INVITADO] **$username** ha usado su poder para SALTAR la canción actual. ⏭️"; + $stmt = $db->prepare("INSERT INTO messages (username, message, type) VALUES ('Sistema', ?, 'text')"); + $stmt->execute([$chatMsg]); + + echo json_encode(['success' => true, 'message' => 'Acción de saltar ejecutada y anunciada']); + + } elseif ($action === 'prioritize') { + if (!$requestId) { + echo json_encode(['success' => false, 'error' => 'ID de petición faltante']); + exit; + } + + $stmt = $db->prepare("UPDATE song_requests SET is_priority = 1 WHERE id = ?"); + $stmt->execute([$requestId]); + + // Get request details for announcement + $stmt = $db->prepare("SELECT artist, song FROM song_requests WHERE id = ?"); + $stmt->execute([$requestId]); + $req = $stmt->fetch(); + + if ($req) { + $chatMsg = "🔥 [DJ INVITADO] **$username** ha PRIORIZADO la canción: **{$req['artist']} - {$req['song']}**. ¡Sonará muy pronto! 🎵"; + $stmt = $db->prepare("INSERT INTO messages (username, message, type) VALUES ('Sistema', ?, 'text')"); + $stmt->execute([$chatMsg]); + } + + echo json_encode(['success' => true, 'message' => 'Petición priorizada con éxito']); + } else { + echo json_encode(['success' => false, 'error' => 'Acción no válida']); + } + +} catch (Exception $e) { + echo json_encode(['success' => false, 'error' => $e->getMessage()]); +} diff --git a/api/song_requests.php b/api/song_requests.php index 491f511..50f8e3c 100644 --- a/api/song_requests.php +++ b/api/song_requests.php @@ -152,9 +152,9 @@ if ($method === 'GET') { $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"); + $stmt = $db->query("SELECT * FROM song_requests ORDER BY is_priority DESC, created_at DESC LIMIT $limit"); } else { - $stmt = $db->prepare("SELECT * FROM song_requests WHERE status = ? ORDER BY created_at DESC LIMIT $limit"); + $stmt = $db->prepare("SELECT * FROM song_requests WHERE status = ? ORDER BY is_priority DESC, created_at DESC LIMIT $limit"); $stmt->execute([$status]); } diff --git a/db/migrations/20260219_dj_powers.sql b/db/migrations/20260219_dj_powers.sql new file mode 100644 index 0000000..657ea83 --- /dev/null +++ b/db/migrations/20260219_dj_powers.sql @@ -0,0 +1,11 @@ +-- Add priority support for Guest DJs +ALTER TABLE song_requests ADD COLUMN is_priority TINYINT(1) DEFAULT 0; + +-- Table for radio actions (skips, etc) +CREATE TABLE IF NOT EXISTS radio_actions ( + id INT AUTO_INCREMENT PRIMARY KEY, + action_type VARCHAR(50) NOT NULL, + performed_by VARCHAR(255) NOT NULL, + details TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/index.php b/index.php index 82abd06..1f5b8ad 100644 --- a/index.php +++ b/index.php @@ -1809,6 +1809,9 @@ $twitter_link = "https://twitter.com/";