Autosave: 20260218-233612
This commit is contained in:
parent
2b84812642
commit
55da3db7ad
80
admin.php
80
admin.php
@ -57,6 +57,11 @@ $requests_today = $stmt->fetchColumn();
|
|||||||
<img src="./assets/pasted-20260215-163754-def41f49.png" alt="Logo" style="width: 100px; height: 100px; border-radius: 50%; border: 4px solid #00e676; margin-bottom: 1rem; object-fit: cover; box-shadow: 0 0 25px rgba(0, 230, 118, 0.7);">
|
<img src="./assets/pasted-20260215-163754-def41f49.png" alt="Logo" style="width: 100px; height: 100px; border-radius: 50%; border: 4px solid #00e676; margin-bottom: 1rem; object-fit: cover; box-shadow: 0 0 25px rgba(0, 230, 118, 0.7);">
|
||||||
<h1>Panel de Administración Real-Time</h1>
|
<h1>Panel de Administración Real-Time</h1>
|
||||||
<p class="text-secondary">Lili Records Radio Statistics</p>
|
<p class="text-secondary">Lili Records Radio Statistics</p>
|
||||||
|
<div class="mb-4">
|
||||||
|
<a href="weekly_report.php?token=<?= $secret_token ?>&action=preview" target="_blank" class="btn btn-outline-info">
|
||||||
|
<i class="bi bi-file-earmark-bar-graph"></i> GENERAR REPORTE SEMANAL
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -76,6 +81,9 @@ $requests_today = $stmt->fetchColumn();
|
|||||||
<a href="https://chat.whatsapp.com/DkG96pTzAFO3hvLqmzwmTY" target="_blank" class="btn btn-success d-flex align-items-center gap-2">
|
<a href="https://chat.whatsapp.com/DkG96pTzAFO3hvLqmzwmTY" target="_blank" class="btn btn-success d-flex align-items-center gap-2">
|
||||||
<i class="bi bi-box-arrow-up-right"></i> IR AL GRUPO DE WHATSAPP
|
<i class="bi bi-box-arrow-up-right"></i> IR AL GRUPO DE WHATSAPP
|
||||||
</a>
|
</a>
|
||||||
|
<button class="btn btn-outline-success" onclick="showManualRequestModal()">
|
||||||
|
<i class="bi bi-plus-circle"></i> REGISTRAR PETICIÓN DE WHATSAPP
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -293,6 +301,38 @@ $requests_today = $stmt->fetchColumn();
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="modal fade" id="manualRequestModal" tabindex="-1" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content bg-dark border-success">
|
||||||
|
<div class="modal-header border-secondary">
|
||||||
|
<h5 class="modal-title text-success"><i class="bi bi-whatsapp"></i> Registrar Petición de WhatsApp</h5>
|
||||||
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form id="manual-request-form">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Nombre del Oyente</label>
|
||||||
|
<input type="text" class="form-control bg-secondary text-white border-0" id="manual-requester" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Artista</label>
|
||||||
|
<input type="text" class="form-control bg-secondary text-white border-0" id="manual-artist" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Canción</label>
|
||||||
|
<input type="text" class="form-control bg-secondary text-white border-0" id="manual-song" required>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer border-secondary">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
|
||||||
|
<button type="button" class="btn btn-success" onclick="submitManualRequest()">Guardar Petición</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||||
<script src="https://unpkg.com/leaflet.heat@0.2.0/dist/leaflet-heat.js"></script>
|
<script src="https://unpkg.com/leaflet.heat@0.2.0/dist/leaflet-heat.js"></script>
|
||||||
<script>
|
<script>
|
||||||
@ -534,7 +574,47 @@ $requests_today = $stmt->fetchColumn();
|
|||||||
});
|
});
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
|
function showManualRequestModal() {
|
||||||
|
const modal = new bootstrap.Modal(document.getElementById('manualRequestModal'));
|
||||||
|
modal.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitManualRequest() {
|
||||||
|
const requester = document.getElementById('manual-requester').value;
|
||||||
|
const artist = document.getElementById('manual-artist').value;
|
||||||
|
const song = document.getElementById('manual-song').value;
|
||||||
|
|
||||||
|
if (!requester || !artist || !song) {
|
||||||
|
alert('Por favor, rellena todos los campos.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('requester', requester);
|
||||||
|
formData.append('artist', artist);
|
||||||
|
formData.append('song', song);
|
||||||
|
formData.append('source', 'whatsapp');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('api/song_requests.php', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
if (data.success) {
|
||||||
|
bootstrap.Modal.getInstance(document.getElementById('manualRequestModal')).hide();
|
||||||
|
document.getElementById('manual-request-form').reset();
|
||||||
fetchRequests();
|
fetchRequests();
|
||||||
|
fetchTopRequesters();
|
||||||
|
} else {
|
||||||
|
alert('Error: ' + data.error);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
alert('Error al guardar la petición.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchRequests();
|
||||||
} else {
|
} else {
|
||||||
alert('Error: ' + data.error);
|
alert('Error: ' + data.error);
|
||||||
}
|
}
|
||||||
|
|||||||
219
weekly_report.php
Normal file
219
weekly_report.php
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/db/config.php';
|
||||||
|
require_once __DIR__ . '/mail/MailService.php';
|
||||||
|
|
||||||
|
$secret_token = 'lili_admin_2026';
|
||||||
|
if (($_GET['token'] ?? '') !== $secret_token) {
|
||||||
|
die('Acceso denegado.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = db();
|
||||||
|
$action = $_GET['action'] ?? 'preview';
|
||||||
|
|
||||||
|
// 1. Get stats for the last 7 days
|
||||||
|
$stats_query = "
|
||||||
|
SELECT
|
||||||
|
COUNT(*) as total_requests,
|
||||||
|
SUM(CASE WHEN source = 'whatsapp' THEN 1 ELSE 0 END) as whatsapp_requests,
|
||||||
|
SUM(CASE WHEN source != 'whatsapp' OR source IS NULL THEN 1 ELSE 0 END) as web_requests
|
||||||
|
FROM song_requests
|
||||||
|
WHERE created_at > DATE_SUB(NOW(), INTERVAL 7 DAY)
|
||||||
|
";
|
||||||
|
$totals = $db->query($stats_query)->fetch();
|
||||||
|
|
||||||
|
// 2. Top 10 Requesters
|
||||||
|
$top_requesters = $db->query("
|
||||||
|
SELECT requester, COUNT(*) as count
|
||||||
|
FROM song_requests
|
||||||
|
WHERE created_at > DATE_SUB(NOW(), INTERVAL 7 DAY)
|
||||||
|
AND requester IS NOT NULL AND requester != '' AND requester != 'Anónimo'
|
||||||
|
GROUP BY requester
|
||||||
|
ORDER BY count DESC
|
||||||
|
LIMIT 10
|
||||||
|
")->fetchAll();
|
||||||
|
|
||||||
|
// 3. Top 10 Songs (by requests)
|
||||||
|
$top_songs_requested = $db->query("
|
||||||
|
SELECT artist, song, COUNT(*) as count
|
||||||
|
FROM song_requests
|
||||||
|
WHERE created_at > DATE_SUB(NOW(), INTERVAL 7 DAY)
|
||||||
|
GROUP BY artist, song
|
||||||
|
ORDER BY count DESC
|
||||||
|
LIMIT 10
|
||||||
|
")->fetchAll();
|
||||||
|
|
||||||
|
// 4. Top 10 Songs (by likes)
|
||||||
|
$top_songs_liked = $db->query("
|
||||||
|
SELECT song_title, likes_count
|
||||||
|
FROM song_likes
|
||||||
|
WHERE last_liked_at >= DATE_SUB(NOW(), INTERVAL 7 DAY)
|
||||||
|
ORDER BY likes_count DESC
|
||||||
|
LIMIT 10
|
||||||
|
")->fetchAll();
|
||||||
|
|
||||||
|
$report_date = date('d/m/Y');
|
||||||
|
$week_start = date('d/m/Y', strtotime('-7 days'));
|
||||||
|
|
||||||
|
$html_content = "
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
body { font-family: 'Helvetica', Arial, sans-serif; color: #333; line-height: 1.6; }
|
||||||
|
.container { max-width: 800px; margin: 0 auto; padding: 20px; border: 1px solid #eee; }
|
||||||
|
.header { text-align: center; border-bottom: 2px solid #00e676; padding-bottom: 20px; margin-bottom: 30px; }
|
||||||
|
.logo { width: 80px; height: 80px; border-radius: 50%; }
|
||||||
|
h1 { color: #00e676; margin-bottom: 5px; }
|
||||||
|
.subtitle { color: #666; font-size: 0.9rem; }
|
||||||
|
.grid { display: flex; gap: 20px; margin-bottom: 30px; }
|
||||||
|
.stat-card { flex: 1; background: #f9f9f9; padding: 15px; border-radius: 10px; text-align: center; border: 1px solid #eee; }
|
||||||
|
.stat-card h3 { margin: 0; font-size: 0.8rem; color: #888; text-transform: uppercase; }
|
||||||
|
.stat-card .value { font-size: 1.8rem; font-weight: bold; color: #00e676; }
|
||||||
|
table { width: 100%; border-collapse: collapse; margin-bottom: 30px; }
|
||||||
|
th { background: #f4f4f4; text-align: left; padding: 10px; border-bottom: 2px solid #ddd; }
|
||||||
|
td { padding: 10px; border-bottom: 1px solid #eee; }
|
||||||
|
.crown { color: #ffca28; }
|
||||||
|
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 0.8rem; background: #eee; }
|
||||||
|
.badge-wa { background: #e8f5e9; color: #2e7d32; }
|
||||||
|
.badge-web { background: #e3f2fd; color: #1565c0; }
|
||||||
|
.footer { text-align: center; font-size: 0.8rem; color: #999; margin-top: 40px; border-top: 1px solid #eee; padding-top: 20px; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class='container'>
|
||||||
|
<div class='header'>
|
||||||
|
<h1>Reporte Semanal Lili Records Radio</h1>
|
||||||
|
<p class='subtitle'>Periodo: $week_start al $report_date</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class='grid'>
|
||||||
|
<div class='stat-card'>
|
||||||
|
<h3>Total Peticiones</h3>
|
||||||
|
<div class='value'>{$totals['total_requests']}</div>
|
||||||
|
</div>
|
||||||
|
<div class='stat-card'>
|
||||||
|
<h3>Vía WhatsApp</h3>
|
||||||
|
<div class='value'>{$totals['whatsapp_requests']}</div>
|
||||||
|
</div>
|
||||||
|
<div class='stat-card'>
|
||||||
|
<h3>Vía Web</h3>
|
||||||
|
<div class='value'>{$totals['web_requests']}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2>🏆 Top 10 Oyentes de la Semana</h2>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>#</th>
|
||||||
|
<th>Oyente</th>
|
||||||
|
<th>Peticiones</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>";
|
||||||
|
foreach ($top_requesters as $i => $r) {
|
||||||
|
$crown = ($i === 0) ? "<span class='crown'>👑</span> " : "";
|
||||||
|
$html_content .= "
|
||||||
|
<tr>
|
||||||
|
<td style='width: 40px;'>" . ($i + 1) . "</td>
|
||||||
|
<td>$crown" . htmlspecialchars($r['requester']) . "</td>
|
||||||
|
<td><b>" . $r['count'] . "</b></td>
|
||||||
|
</tr>";
|
||||||
|
}
|
||||||
|
$html_content .= "
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h2>🎵 Top Canciones (Más Pedidas)</h2>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Canción</th>
|
||||||
|
<th>Artista</th>
|
||||||
|
<th>Veces</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>";
|
||||||
|
foreach ($top_songs_requested as $s) {
|
||||||
|
$html_content .= "
|
||||||
|
<tr>
|
||||||
|
<td>" . htmlspecialchars($s['song']) . "</td>
|
||||||
|
<td>" . htmlspecialchars($s['artist']) . "</td>
|
||||||
|
<td><b>" . $s['count'] . "</b></td>
|
||||||
|
</tr>";
|
||||||
|
}
|
||||||
|
$html_content .= "
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h2>⭐ Top Canciones (Más Likes)</h2>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Canción</th>
|
||||||
|
<th>Likes</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>";
|
||||||
|
foreach ($top_songs_liked as $s) {
|
||||||
|
$html_content .= "
|
||||||
|
<tr>
|
||||||
|
<td>" . htmlspecialchars($s['song_title']) . "</td>
|
||||||
|
<td><span style='color: #ff4081;'>❤</span> " . $s['likes_count'] . "</td>
|
||||||
|
</tr>";
|
||||||
|
}
|
||||||
|
$html_content .= "
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div class='footer'>
|
||||||
|
Este es un reporte automático generado por el sistema de Lili Records Radio.<br>
|
||||||
|
© " . date('Y') . " Lili Records. Todos los derechos reservados.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
";
|
||||||
|
|
||||||
|
if ($action === 'send') {
|
||||||
|
$subject = "📊 Reporte de Actividad Semanal - Lili Records Radio ($report_date)";
|
||||||
|
$res = MailService::sendMail(null, $subject, $html_content);
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode($res);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default action: preview
|
||||||
|
echo $html_content;
|
||||||
|
if ($action === 'preview') {
|
||||||
|
echo "
|
||||||
|
<div style='position: fixed; bottom: 20px; right: 20px; display: flex; gap: 10px;'>
|
||||||
|
<button onclick='window.print()' style='background: #0d6efd; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; font-weight: bold;'>🖨️ Descargar PDF</button>
|
||||||
|
<button onclick='sendByEmail()' id='sendBtn' style='background: #00e676; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; font-weight: bold;'>📧 Enviar por Email</button>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
async function sendByEmail() {
|
||||||
|
const btn = document.getElementById('sendBtn');
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.innerText = 'Enviando...';
|
||||||
|
try {
|
||||||
|
const res = await fetch('weekly_report.php?token=$secret_token&action=send');
|
||||||
|
const data = await res.json();
|
||||||
|
if (data.success) {
|
||||||
|
alert('¡Reporte enviado con éxito!');
|
||||||
|
btn.innerText = '✅ Enviado';
|
||||||
|
} else {
|
||||||
|
alert('Error al enviar: ' + data.error);
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.innerText = '📧 Reintentar Envío';
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
alert('Error de conexión.');
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.innerText = '📧 Reintentar Envío';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
";
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user