Auto commit: 2026-02-17T17:11:08.758Z
This commit is contained in:
parent
e6625de8bb
commit
3b91c65794
98
admin.php
98
admin.php
@ -96,6 +96,35 @@ $locations = $stmt->fetchAll();
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-4">
|
||||
<div class="col-md-12">
|
||||
<div class="card p-4">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h5><i class="bi bi-music-note-list text-success"></i> Moderación de Peticiones</h5>
|
||||
<button class="btn btn-sm btn-outline-success" onclick="fetchRequests()">Actualizar Lista</button>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-dark table-hover align-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Artista</th>
|
||||
<th>Canción</th>
|
||||
<th>Solicitado por</th>
|
||||
<th>Fecha</th>
|
||||
<th>Estado</th>
|
||||
<th>Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="requests-body">
|
||||
<tr>
|
||||
<td colspan="6" class="text-center text-secondary">Cargando peticiones...</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||
@ -113,6 +142,75 @@ $locations = $stmt->fetchAll();
|
||||
.bindPopup(`<b>${loc.country}</b><br>${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 = '<tr><td colspan="6" class="text-center text-secondary">No hay peticiones registradas</td></tr>';
|
||||
return;
|
||||
}
|
||||
|
||||
tbody.innerHTML = data.requests.map(req => `
|
||||
<tr>
|
||||
<td>${req.artist}</td>
|
||||
<td>${req.song}</td>
|
||||
<td><span class="badge bg-secondary">${req.requester}</span></td>
|
||||
<td><small>${new Date(req.created_at).toLocaleString()}</small></td>
|
||||
<td>
|
||||
<span class="badge ${req.status === 'played' ? 'bg-success' : 'bg-warning text-dark'}">
|
||||
${req.status === 'played' ? 'Reproducida' : 'Pendiente'}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group btn-group-sm">
|
||||
${req.status === 'pending' ? `
|
||||
<button class="btn btn-success" onclick="updateStatus(${req.id}, 'mark_played')" title="Marcar como reproducida">
|
||||
<i class="bi bi-play-fill"></i>
|
||||
</button>
|
||||
` : ''}
|
||||
<button class="btn btn-danger" onclick="updateStatus(${req.id}, 'delete')" title="Eliminar">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
`).join('');
|
||||
}
|
||||
} catch (error) {
|
||||
tbody.innerHTML = '<tr><td colspan="6" class="text-center text-danger">Error al cargar peticiones</td></tr>';
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
2
db/migrations/20260217_add_status_to_song_requests.sql
Normal file
2
db/migrations/20260217_add_status_to_song_requests.sql
Normal file
@ -0,0 +1,2 @@
|
||||
-- Add status column to song_requests table
|
||||
ALTER TABLE song_requests ADD COLUMN status ENUM('pending', 'played') DEFAULT 'pending';
|
||||
Loading…
x
Reference in New Issue
Block a user