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/";
+ @@ -3087,28 +3090,106 @@ $twitter_link = "https://twitter.com/"; try { const response = await fetch('api/song_requests.php'); const result = await response.json(); + + // Check if current user is Guest DJ + const currentUserName = document.getElementById('user-name').value.trim(); + let isGuestDj = false; + + // We can check if the current user has the Guest DJ status from the online users data or another check + // For simplicity, let's do a quick local check if we've already fetched online users + const onlineUsersResponse = await fetch('api/get_online_users.php'); + const onlineData = await onlineUsersResponse.json(); + if (onlineData.success && currentUserName) { + const me = onlineData.users.find(u => u.username.toLowerCase() === currentUserName.toLowerCase()); + if (me && me.dj_day_until && (new Date(me.dj_day_until) > new Date())) { + isGuestDj = true; + } + } + + // Show/hide Skip button + const skipBtn = document.getElementById('dj-skip-btn'); + if (skipBtn) skipBtn.style.display = isGuestDj ? 'flex' : 'none'; + if (result.success) { const list = document.getElementById('song-requests-list'); if (result.requests.length === 0) { list.innerHTML = '
No hay peticiones recientes.
'; return; } - list.innerHTML = result.requests.map(req => ` -
+ list.innerHTML = result.requests.map(req => { + const isPriority = req.is_priority == 1; + return ` +
- ${req.artist} + ${isPriority ? '⭐ ' : ''}${req.artist} ${new Date(req.created_at).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}
${req.song}
-
${req.requester}
+
+
${req.requester}
+ ${isGuestDj && !isPriority ? ` + + ` : ''} + ${isPriority ? ' PRIORIDAD DJ' : ''} +
- `).join(''); + `; + }).join(''); } } catch (error) { console.error('Error fetching requests:', error); } } + async function djSkipSong() { + const username = document.getElementById('user-name').value.trim(); + if (!username) return; + + if (!confirm('¿Estás seguro de que quieres usar tu poder de DJ para SALTAR esta canción?')) return; + + try { + const response = await fetch('api/dj_actions.php', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ username: username, action: 'skip' }) + }); + const result = await response.json(); + if (result.success) { + alert('¡Canción saltada! Se ha anunciado en el chat.'); + fetchMessages(); + } else { + alert('Error: ' + result.error); + } + } catch (error) { + console.error('Error skipping song:', error); + } + } + + async function djPrioritizeSong(requestId) { + const username = document.getElementById('user-name').value.trim(); + if (!username) return; + + try { + const response = await fetch('api/dj_actions.php', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ username: username, action: 'prioritize', request_id: requestId }) + }); + const result = await response.json(); + if (result.success) { + alert('¡Petición priorizada! Sonará pronto.'); + fetchSongRequests(); + fetchMessages(); + } else { + alert('Error: ' + result.error); + } + } catch (error) { + console.error('Error prioritizing song:', error); + } + } + async function submitSongRequest() { const artistInput = document.getElementById('req-artist'); const songInput = document.getElementById('req-song');