diff --git a/api/get_online_users.php b/api/get_online_users.php new file mode 100644 index 0000000..c00d697 --- /dev/null +++ b/api/get_online_users.php @@ -0,0 +1,23 @@ +prepare(" + SELECT username, phone_number, country_code, last_activity + FROM visitor_logs + WHERE last_activity > DATE_SUB(NOW(), INTERVAL 15 MINUTE) + AND username IS NOT NULL + AND phone_number IS NOT NULL + AND username != '' + AND phone_number != '' + GROUP BY username, phone_number + ORDER BY last_activity DESC + LIMIT 20 +"); +$stmt->execute(); +$users = $stmt->fetchAll(); + +echo json_encode(['success' => true, 'users' => $users]); diff --git a/api/save_user_info.php b/api/save_user_info.php new file mode 100644 index 0000000..3656d56 --- /dev/null +++ b/api/save_user_info.php @@ -0,0 +1,39 @@ +prepare("SELECT id FROM visitor_logs WHERE session_id = ? ORDER BY id DESC LIMIT 1"); + $stmt->execute([$session_id]); + $visitor = $stmt->fetch(); + + if ($visitor) { + if ($username && $phone) { + $stmt = $db->prepare("UPDATE visitor_logs SET username = ?, phone_number = ?, last_activity = CURRENT_TIMESTAMP WHERE id = ?"); + $stmt->execute([$username, $phone, $visitor['id']]); + } elseif ($username) { + $stmt = $db->prepare("UPDATE visitor_logs SET username = ?, last_activity = CURRENT_TIMESTAMP WHERE id = ?"); + $stmt->execute([$username, $visitor['id']]); + } else { + $stmt = $db->prepare("UPDATE visitor_logs SET phone_number = ?, last_activity = CURRENT_TIMESTAMP WHERE id = ?"); + $stmt->execute([$phone, $visitor['id']]); + } + echo json_encode(['success' => true]); + } else { + echo json_encode(['success' => false, 'error' => 'No session found']); + } +} else { + echo json_encode(['success' => false, 'error' => 'Invalid data']); +} diff --git a/index.php b/index.php index 88fc783..c3f77e6 100644 --- a/index.php +++ b/index.php @@ -1666,12 +1666,12 @@ $twitter_link = "https://twitter.com/";
- +
- +
@@ -1817,6 +1817,17 @@ $twitter_link = "https://twitter.com/"; + +
+

+ CLIENTES CONECTADOS +

+

Habla directamente con otros oyentes por WhatsApp.

+
+
Cargando usuarios...
+
+
+

@@ -2272,6 +2283,56 @@ $twitter_link = "https://twitter.com/"; }); } + function saveUserInfo() { + const name = document.getElementById('user-name').value.trim(); + const phone = document.getElementById('user-phone').value.trim(); + + if (!name && !phone) return; + + fetch('api/save_user_info.php', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ username: name, phone: phone }) + }); + } + + async function fetchOnlineUsers() { + try { + const response = await fetch('api/get_online_users.php'); + const data = await response.json(); + if (data.success) { + const list = document.getElementById('online-users-list'); + if (data.users.length === 0) { + list.innerHTML = '
No hay otros usuarios con móvil registrado ahora.
'; + return; + } + + list.innerHTML = data.users.map(user => ` +
+
+
+ ${user.username.charAt(0).toUpperCase()} +
+
+
${user.username}
+
Conectado
+
+
+ + + +
+ `).join(''); + } + } catch (error) { + console.error('Error fetching online users:', error); + } + } + + // Fetch online users every 30 seconds + setInterval(fetchOnlineUsers, 30000); + setTimeout(fetchOnlineUsers, 2000); // Initial fetch + function savePhone(phone) { const phoneInput = document.getElementById('user-phone'); const phoneRegex = /^\+?[0-9]{7,15}$/;