diff --git a/index.php b/index.php
index 2e5e827..6f0423b 100644
--- a/index.php
+++ b/index.php
@@ -1803,9 +1803,9 @@ $twitter_link = "https://twitter.com/";
-
- WHATSAPP
-
+
@@ -1942,9 +1942,14 @@ $twitter_link = "https://twitter.com/";
-
+
No hay peticiones recientes.
@@ -2556,10 +2561,14 @@ $twitter_link = "https://twitter.com/";
});
}
- function sendToWhatsApp() {
+ async function sendToWhatsApp() {
const name = document.getElementById('user-name').value.trim();
const phone = document.getElementById('user-phone').value.trim();
const message = document.getElementById('user-message').value.trim();
+
+ const reqArtist = document.getElementById('req-artist').value.trim();
+ const reqSong = document.getElementById('req-song').value.trim();
+
const phoneRegex = /^\+?[0-9]{7,15}$/;
if (name.length < 3) {
@@ -2585,13 +2594,38 @@ $twitter_link = "https://twitter.com/";
const refId = Math.floor(1000 + Math.random() * 9000);
const currentSong = document.getElementById('track-title').innerText.replace(/\s{2,}/g, ' ').trim();
+ let requestDetails = "";
+ if (reqArtist && reqSong) {
+ requestDetails = `*Petición:* ${reqArtist} - ${reqSong}\n`;
+ }
+
const text = `*PETICIÓN RADIO* (Ref: #${refId})\n\n` +
`*Nombre:* ${name}\n` +
`*Móvil:* ${phone}\n` +
`*Fecha:* ${dateTime}\n` +
+ requestDetails +
`*Sonando ahora:* ${currentSong}\n\n` +
`*Mensaje:* ${message || 'Sin mensaje específico'}`;
+ // Register in database
+ try {
+ const formData = new FormData();
+ formData.append('artist', reqArtist || 'WhatsApp');
+ formData.append('song', reqSong || message || 'Petición Directa');
+ formData.append('requester', name);
+ formData.append('source', 'whatsapp');
+
+ await fetch('api/song_requests.php', {
+ method: 'POST',
+ body: formData
+ });
+
+ if (typeof fetchSongRequests === 'function') fetchSongRequests();
+ if (typeof fetchLeaderboard === 'function') fetchLeaderboard();
+ } catch (e) {
+ console.error("Error registering WhatsApp request:", e);
+ }
+
const url = `https://wa.me/= str_replace('+', '', $whatsapp_number) ?>?text=${encodeURIComponent(text)}`;
window.open(url, '_blank');
}