diff --git a/api/get_online_users.php b/api/get_online_users.php index c00d697..613a75c 100644 --- a/api/get_online_users.php +++ b/api/get_online_users.php @@ -6,18 +6,34 @@ $db = db(); // Active in the last 15 minutes, has username and phone // Use GROUP BY to avoid duplicates if same session/user has multiple entries (though session_id should be unique-ish) $stmt = $db->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 + SELECT + v.username, + v.phone_number, + v.country_code, + v.last_activity, + f.points, + f.is_fan_of_month + FROM visitor_logs v + LEFT JOIN fans f ON v.username = f.name + WHERE v.last_activity > DATE_SUB(NOW(), INTERVAL 15 MINUTE) + AND v.username IS NOT NULL + AND v.phone_number IS NOT NULL + AND v.username != '' + AND v.phone_number != '' + GROUP BY v.username, v.phone_number + ORDER BY v.last_activity DESC LIMIT 20 "); $stmt->execute(); $users = $stmt->fetchAll(); -echo json_encode(['success' => true, 'users' => $users]); +// Get total active sessions (last 5 minutes) for a live counter +$stmtTotal = $db->prepare("SELECT COUNT(DISTINCT session_id) as total FROM visitor_logs WHERE last_activity > DATE_SUB(NOW(), INTERVAL 5 MINUTE)"); +$stmtTotal->execute(); +$totalActive = $stmtTotal->fetch()['total'] ?? 0; + +echo json_encode([ + 'success' => true, + 'users' => $users, + 'total_active' => $totalActive +]); diff --git a/index.php b/index.php index c3f77e6..f6642e6 100644 --- a/index.php +++ b/index.php @@ -2296,33 +2296,73 @@ $twitter_link = "https://twitter.com/"; }); } + function getUserColor(str) { + let hash = 0; + for (let i = 0; i < str.length; i++) { + hash = str.charCodeAt(i) + ((hash << 5) - hash); + } + const h = Math.abs(hash) % 360; + // Usamos colores vibrantes con buena saturación y luminosidad media + return `hsl(${h}, 65%, 55%)`; + } + + function timeAgo(dateString) { + const now = new Date(); + const past = new Date(dateString); + const diffInSeconds = Math.floor((now - past) / 1000); + + if (diffInSeconds < 60) return 'Hace un momento'; + if (diffInSeconds < 3600) return `Hace ${Math.floor(diffInSeconds / 60)} min`; + return 'Hace más de 1 hora'; + } + 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'); + const widgetTitle = document.querySelector('#online-users-list').previousElementSibling.previousElementSibling; + + if (widgetTitle && data.total_active !== undefined) { + widgetTitle.innerHTML = ` CLIENTES CONECTADOS ${data.total_active} OYENTES`; + } + if (data.users.length === 0) { list.innerHTML = '
+ ${fan.photo ?
+ `