Auto commit: 2026-02-17T17:08:28.722Z
This commit is contained in:
parent
e4e4eb56af
commit
e6625de8bb
37
api/song_requests.php
Normal file
37
api/song_requests.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
require_once __DIR__ . '/../db/config.php';
|
||||||
|
|
||||||
|
$method = $_SERVER['REQUEST_METHOD'];
|
||||||
|
$db = db();
|
||||||
|
|
||||||
|
if ($method === 'POST') {
|
||||||
|
$artist = trim($_POST['artist'] ?? '');
|
||||||
|
$song = trim($_POST['song'] ?? '');
|
||||||
|
$requester = trim($_POST['requester'] ?? 'Anónimo');
|
||||||
|
|
||||||
|
if (empty($artist) || empty($song)) {
|
||||||
|
echo json_encode(['success' => false, 'error' => 'Falta artista o canción']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$stmt = $db->prepare("INSERT INTO song_requests (artist, song, requester) VALUES (?, ?, ?)");
|
||||||
|
$stmt->execute([$artist, $song, $requester]);
|
||||||
|
echo json_encode(['success' => true]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($method === 'GET') {
|
||||||
|
try {
|
||||||
|
$stmt = $db->query("SELECT * FROM song_requests ORDER BY created_at DESC LIMIT 10");
|
||||||
|
$requests = $stmt->fetchAll();
|
||||||
|
echo json_encode(['success' => true, 'requests' => $requests]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo json_encode(['success' => true, 'requests' => [], 'error' => $e->getMessage()]);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
1
db/migrations/20260217_create_song_requests.sql
Normal file
1
db/migrations/20260217_create_song_requests.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS song_requests (id INT AUTO_INCREMENT PRIMARY KEY, artist VARCHAR(255) NOT NULL, song VARCHAR(255) NOT NULL, requester VARCHAR(100) DEFAULT 'Anónimo', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
163
index.php
163
index.php
@ -977,6 +977,48 @@ $facebook_link = "https://www.facebook.com/profile.php?id=61587890927489";
|
|||||||
font-size: 1.1rem;
|
font-size: 1.1rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Song Requests Styles */
|
||||||
|
.request-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.8rem;
|
||||||
|
max-height: 300px;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding-right: 5px;
|
||||||
|
}
|
||||||
|
.request-item {
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
padding: 0.8rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
animation: fadeIn 0.5s ease;
|
||||||
|
}
|
||||||
|
.request-item .artist {
|
||||||
|
color: var(--primary-color);
|
||||||
|
font-weight: 800;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
.request-item .song {
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
margin: 2px 0;
|
||||||
|
}
|
||||||
|
.request-item .requester {
|
||||||
|
font-size: 0.7rem;
|
||||||
|
opacity: 0.6;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
.request-badge {
|
||||||
|
background: var(--primary-color);
|
||||||
|
color: white;
|
||||||
|
padding: 2px 6px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 0.6rem;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -1194,6 +1236,31 @@ $facebook_link = "https://www.facebook.com/profile.php?id=61587890927489";
|
|||||||
<emoji-picker id="emoji-picker" style="display: none; position: absolute; bottom: 50px; left: 0; z-index: 1000; --num-columns: 6; --category-button-size: 1.5rem; width: 300px; height: 350px;"></emoji-picker>
|
<emoji-picker id="emoji-picker" style="display: none; position: absolute; bottom: 50px; left: 0; z-index: 1000; --num-columns: 6; --category-button-size: 1.5rem; width: 300px; height: 350px;"></emoji-picker>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Song Requests Live List -->
|
||||||
|
<div class="glass-card mt-4" style="margin-top: 1.5rem;">
|
||||||
|
<h3 style="font-size: 1.2rem; margin-bottom: 1rem; color: var(--accent-color);">
|
||||||
|
<i class="bi bi-music-note-beamed"></i> PETICIONES EN VIVO
|
||||||
|
</h3>
|
||||||
|
<div class="interaction-form" style="margin-bottom: 1.5rem; background: rgba(255,255,255,0.03); padding: 1rem; border-radius: 16px; border: 1px solid rgba(255,255,255,0.05);">
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="req-artist">ARTISTA</label>
|
||||||
|
<input type="text" id="req-artist" placeholder="Ej: Bad Bunny">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="req-song">CANCIÓN</label>
|
||||||
|
<input type="text" id="req-song" placeholder="Ej: Tití Me Preguntó">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button onclick="submitSongRequest()" id="submit-req-btn" style="margin-top: 0.8rem; background: var(--primary-color); color: white; border: none; padding: 0.8rem; border-radius: 12px; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 0.5rem; width: 100%; transition: all 0.3s;">
|
||||||
|
<i class="bi bi-plus-circle-fill"></i> PEDIR CANCIÓN
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div id="song-requests-list" class="request-list">
|
||||||
|
<div style="opacity: 0.5; font-size: 0.85rem; text-align: center; padding: 2rem;">No hay peticiones recientes.</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -1754,6 +1821,102 @@ $facebook_link = "https://www.facebook.com/profile.php?id=61587890927489";
|
|||||||
setInterval(updatePhotoCounter, 30000); // Check limit status every 30s
|
setInterval(updatePhotoCounter, 30000); // Check limit status every 30s
|
||||||
// --- End Chat Functionality ---
|
// --- End Chat Functionality ---
|
||||||
|
|
||||||
|
// --- Song Request Functionality ---
|
||||||
|
async function fetchSongRequests() {
|
||||||
|
try {
|
||||||
|
const response = await fetch('api/song_requests.php');
|
||||||
|
const result = await response.json();
|
||||||
|
if (result.success) {
|
||||||
|
const list = document.getElementById('song-requests-list');
|
||||||
|
if (result.requests.length === 0) {
|
||||||
|
list.innerHTML = '<div style="opacity: 0.5; font-size: 0.85rem; text-align: center; padding: 2rem;">No hay peticiones recientes.</div>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
list.innerHTML = result.requests.map(req => `
|
||||||
|
<div class="request-item">
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px;">
|
||||||
|
<span class="artist">${req.artist}</span>
|
||||||
|
<span style="font-size: 0.6rem; opacity: 0.4;">${new Date(req.created_at).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}</span>
|
||||||
|
</div>
|
||||||
|
<div class="song">${req.song}</div>
|
||||||
|
<div class="requester"><i class="bi bi-person-fill"></i> ${req.requester}</div>
|
||||||
|
</div>
|
||||||
|
`).join('');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching requests:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitSongRequest() {
|
||||||
|
const artistInput = document.getElementById('req-artist');
|
||||||
|
const songInput = document.getElementById('req-song');
|
||||||
|
const artist = artistInput.value.trim();
|
||||||
|
const song = songInput.value.trim();
|
||||||
|
const requester = document.getElementById('user-name').value.trim() || 'Anónimo';
|
||||||
|
|
||||||
|
if (!artist || !song) {
|
||||||
|
alert('Por favor, ingresa el artista y el nombre de la canción.');
|
||||||
|
if (!artist) artistInput.style.borderColor = '#ff4444';
|
||||||
|
if (!song) songInput.style.borderColor = '#ff4444';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const btn = document.getElementById('submit-req-btn');
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.innerHTML = '<i class="bi bi-hourglass-split"></i> ENVIANDO...';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('artist', artist);
|
||||||
|
formData.append('song', song);
|
||||||
|
formData.append('requester', requester);
|
||||||
|
|
||||||
|
const response = await fetch('api/song_requests.php', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
});
|
||||||
|
const result = await response.json();
|
||||||
|
if (result.success) {
|
||||||
|
artistInput.value = '';
|
||||||
|
songInput.value = '';
|
||||||
|
artistInput.style.borderColor = '';
|
||||||
|
songInput.style.borderColor = '';
|
||||||
|
fetchSongRequests();
|
||||||
|
|
||||||
|
// Small visual feedback
|
||||||
|
btn.innerHTML = '<i class="bi bi-check-circle-fill"></i> ¡PEDIDA!';
|
||||||
|
btn.style.backgroundColor = 'var(--accent-color)';
|
||||||
|
|
||||||
|
confetti({
|
||||||
|
particleCount: 50,
|
||||||
|
spread: 60,
|
||||||
|
origin: { y: 0.8 },
|
||||||
|
colors: ['#38bdf8', '#00e676']
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.innerHTML = '<i class="bi bi-plus-circle-fill"></i> PEDIR CANCIÓN';
|
||||||
|
btn.style.backgroundColor = '';
|
||||||
|
}, 3000);
|
||||||
|
} else {
|
||||||
|
alert('Error: ' + (result.error || 'No se pudo enviar la petición'));
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.innerHTML = '<i class="bi bi-plus-circle-fill"></i> PEDIR CANCIÓN';
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error submitting request:', error);
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.innerHTML = '<i class="bi bi-plus-circle-fill"></i> PEDIR CANCIÓN';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initial fetch and poll for requests
|
||||||
|
fetchSongRequests();
|
||||||
|
setInterval(fetchSongRequests, 10000); // Update requests every 10s
|
||||||
|
// --- End Song Request Functionality ---
|
||||||
|
|
||||||
function openQRModal() {
|
function openQRModal() {
|
||||||
const modal = document.getElementById('qr-modal');
|
const modal = document.getElementById('qr-modal');
|
||||||
modal.style.display = 'flex';
|
modal.style.display = 'flex';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user