@@ -274,7 +339,32 @@ $locations = $stmt->fetchAll();
initChart();
async function fetchRequests() {
- // ... (keeping existing logic)
+ try {
+ const response = await fetch('api/song_requests.php?status=pending');
+ const data = await response.json();
+ if (data.success) {
+ const tbody = document.getElementById('requests-body');
+ if (data.requests.length === 0) {
+ tbody.innerHTML = '
| No hay peticiones pendientes |
';
+ } else {
+ tbody.innerHTML = data.requests.map(req => `
+
+ | ${req.artist} |
+ ${req.song} |
+ ${req.requester} |
+ ${new Date(req.created_at).toLocaleString()} |
+ ${req.status} |
+
+
+
+ |
+
+ `).join('');
+ }
+ }
+ } catch (error) {
+ console.error('Error fetching requests:', error);
+ }
}
async function fetchChatImages() {
@@ -384,6 +474,11 @@ $locations = $stmt->fetchAll();
if (data.locations) {
updateMap(data.locations);
}
+
+ if (data.requests_today !== undefined) {
+ const reqCounter = document.getElementById('requests-today-count');
+ if (reqCounter) reqCounter.innerText = data.requests_today;
+ }
}
} catch (error) {
console.error('Error fetching stats:', error);
@@ -413,6 +508,60 @@ $locations = $stmt->fetchAll();
}
}
+ async function announceOnAir() {
+ const title = document.getElementById('admin-track-title').innerText.trim();
+ const artist = document.getElementById('admin-track-artist').innerText.trim();
+ const currentSong = artist !== 'Lili Records' ? `${artist} - ${title}` : title;
+ const shareUrl = window.location.origin; // Link to the main radio page
+ const text = `🔴 *¡ESTAMOS AL AIRE!* 🎙️📻\n\nSintoniza ahora *Lili Records Radio* para escuchar la mejor música en vivo.\n\n🎵 *Sonando:* ${currentSong}\n\n👉 *Escúchanos aquí:* ${shareUrl}\n\n¡Te esperamos! 💃🕺\n\n#LiliRecords #RadioEnVivo #LaQueTeGusta`;
+
+ // Log the announcement
+ try {
+ await fetch('api/log_announcement.php', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ song_name: currentSong })
+ });
+ fetchAnnouncements();
+ } catch (error) {
+ console.error('Error logging announcement:', error);
+ }
+
+ const url = `https://wa.me/?text=${encodeURIComponent(text)}`;
+ window.open(url, '_blank');
+ }
+
+ async function fetchAnnouncements() {
+ try {
+ // Since we don't have a dedicated API for fetching history yet, we'll reload the relevant part or create one.
+ // For simplicity and following the project style, I'll create api/get_announcements.php
+ const response = await fetch('api/get_announcements.php');
+ const data = await response.json();
+ if (data.success) {
+ const tbody = document.getElementById('announcements-body');
+ if (data.announcements.length === 0) {
+ tbody.innerHTML = '| No hay anuncios registrados |
';
+ } else {
+ tbody.innerHTML = data.announcements.map(ann => `
+
+ | ${new Date(ann.created_at).toLocaleString()} |
+ ${ann.song_name} |
+ WhatsApp |
+ ${ann.announcer_name} |
+
+ `).join('');
+ }
+
+ if (data.count_24h !== undefined) {
+ const counter = document.getElementById('announcements-24h-count');
+ if (counter) counter.innerText = data.count_24h;
+ }
+ }
+ } catch (error) {
+ console.error('Error fetching announcements:', error);
+ }
+ }
+
async function updateNowPlaying() {
try {
const response = await fetch('https://www.radioking.com/widgets/api/v1/radio/828046/track/current');
@@ -443,10 +592,12 @@ $locations = $stmt->fetchAll();
fetchRequests();
fetchStats();
updateNowPlaying();
+ fetchAnnouncements();
setInterval(() => {
fetchRequests();
fetchStats();
updateNowPlaying();
+ fetchAnnouncements();
}, 15000);
diff --git a/api/get_announcements.php b/api/get_announcements.php
new file mode 100644
index 0000000..b38cc01
--- /dev/null
+++ b/api/get_announcements.php
@@ -0,0 +1,16 @@
+query("SELECT * FROM announcements_history ORDER BY created_at DESC LIMIT 10");
+ $announcements = $stmt->fetchAll();
+
+ $stmt = $db->query("SELECT COUNT(*) FROM announcements_history WHERE created_at > DATE_SUB(NOW(), INTERVAL 24 HOUR)");
+ $count_24h = $stmt->fetchColumn();
+
+ echo json_encode(['success' => true, 'announcements' => $announcements, 'count_24h' => $count_24h]);
+} catch (PDOException $e) {
+ echo json_encode(['success' => false, 'error' => $e->getMessage()]);
+}
diff --git a/api/log_announcement.php b/api/log_announcement.php
new file mode 100644
index 0000000..5578ae7
--- /dev/null
+++ b/api/log_announcement.php
@@ -0,0 +1,20 @@
+ false, 'error' => 'Datos incompletos']);
+ exit;
+}
+
+try {
+ $db = db();
+ $stmt = $db->prepare("INSERT INTO announcements_history (song_name) VALUES (?)");
+ $stmt->execute([$data['song_name']]);
+
+ echo json_encode(['success' => true]);
+} catch (PDOException $e) {
+ echo json_encode(['success' => false, 'error' => $e->getMessage()]);
+}
diff --git a/api/song_requests.php b/api/song_requests.php
index 1fc8e6f..f0032ed 100644
--- a/api/song_requests.php
+++ b/api/song_requests.php
@@ -88,12 +88,17 @@ if ($method === 'GET') {
$stmt = $db->query("SELECT country, country_code, lat, lon, COUNT(*) as count FROM visitor_logs WHERE last_activity > DATE_SUB(NOW(), INTERVAL 10 MINUTE) GROUP BY country_code");
$locations = $stmt->fetchAll();
+ // Total requests today
+ $stmt = $db->query("SELECT COUNT(*) FROM song_requests WHERE DATE(created_at) = CURDATE()");
+ $requests_today = $stmt->fetchColumn();
+
echo json_encode([
'success' => true,
'top_artists' => $top_artists,
'top_songs' => $top_songs,
'volume_stats' => $volume_stats,
- 'locations' => $locations
+ 'locations' => $locations,
+ 'requests_today' => $requests_today
]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
diff --git a/db/migrations/20260218_create_announcements_history.sql b/db/migrations/20260218_create_announcements_history.sql
new file mode 100644
index 0000000..5dc4ab8
--- /dev/null
+++ b/db/migrations/20260218_create_announcements_history.sql
@@ -0,0 +1,7 @@
+CREATE TABLE IF NOT EXISTS announcements_history (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ song_name VARCHAR(255) NOT NULL,
+ announcer_name VARCHAR(100) DEFAULT 'Admin',
+ platform VARCHAR(50) DEFAULT 'WhatsApp',
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+);