Auto commit: 2026-02-18T20:42:02.833Z
This commit is contained in:
parent
b0cf83ac7b
commit
d30c75493b
23
api/get_online_users.php
Normal file
23
api/get_online_users.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/../db/config.php';
|
||||
|
||||
$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
|
||||
LIMIT 20
|
||||
");
|
||||
$stmt->execute();
|
||||
$users = $stmt->fetchAll();
|
||||
|
||||
echo json_encode(['success' => true, 'users' => $users]);
|
||||
39
api/save_user_info.php
Normal file
39
api/save_user_info.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/../db/config.php';
|
||||
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
$username = $input['username'] ?? null;
|
||||
$phone = $input['phone'] ?? null;
|
||||
$session_id = session_id();
|
||||
|
||||
if (!empty($session_id) && ($username || $phone)) {
|
||||
$db = db();
|
||||
|
||||
// Check if entry exists for this session
|
||||
$stmt = $db->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']);
|
||||
}
|
||||
65
index.php
65
index.php
@ -1666,12 +1666,12 @@ $twitter_link = "https://twitter.com/";
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="user-name">NOMBRE</label>
|
||||
<input type="text" id="user-name" placeholder="Tu nombre..." oninput="this.style.borderColor='rgba(255, 255, 255, 0.2)'; if(this.value.length >= 3) fetchLeaderboard();">
|
||||
<input type="text" id="user-name" placeholder="Tu nombre..." oninput="this.style.borderColor='rgba(255, 255, 255, 0.2)'; if(this.value.length >= 3) { fetchLeaderboard(); saveUserInfo(); }">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="user-phone">MOVIL</label>
|
||||
<input type="tel" id="user-phone" placeholder="Tu número..." oninput="this.style.borderColor='rgba(255, 255, 255, 0.2)'" onchange="savePhone(this.value)">
|
||||
<input type="tel" id="user-phone" placeholder="Tu número..." oninput="this.style.borderColor='rgba(255, 255, 255, 0.2)'" onchange="saveUserInfo()">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1817,6 +1817,17 @@ $twitter_link = "https://twitter.com/";
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Online Users Widget -->
|
||||
<div class="glass-card mt-4" style="margin-top: 1.5rem; background: linear-gradient(135deg, rgba(37, 211, 102, 0.05), rgba(0, 0, 0, 0.1)); border: 1px solid rgba(37, 211, 102, 0.2);">
|
||||
<h3 style="font-size: 1.2rem; margin-bottom: 0.5rem; color: #25D366;">
|
||||
<i class="bi bi-people-fill"></i> CLIENTES CONECTADOS
|
||||
</h3>
|
||||
<p style="font-size: 0.75rem; opacity: 0.7; margin-bottom: 1rem;">Habla directamente con otros oyentes por WhatsApp.</p>
|
||||
<div id="online-users-list" style="display: flex; flex-direction: column; gap: 0.8rem;">
|
||||
<div style="opacity: 0.5; font-size: 0.85rem; text-align: center; padding: 1rem;">Cargando usuarios...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Gallery Widget -->
|
||||
<div class="glass-card mt-4" style="margin-top: 1.5rem;">
|
||||
<h3 style="font-size: 1.2rem; margin-bottom: 0.5rem; color: #ffca28;">
|
||||
@ -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 = '<div style="opacity: 0.5; font-size: 0.85rem; text-align: center; padding: 1rem;">No hay otros usuarios con móvil registrado ahora.</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
list.innerHTML = data.users.map(user => `
|
||||
<div style="display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,0.03); padding: 10px 15px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.05); transition: all 0.3s;">
|
||||
<div style="display: flex; align-items: center; gap: 10px;">
|
||||
<div style="width: 35px; height: 35px; background: var(--primary-color); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.9rem; color: #000;">
|
||||
${user.username.charAt(0).toUpperCase()}
|
||||
</div>
|
||||
<div>
|
||||
<div style="font-weight: 700; font-size: 0.9rem;">${user.username}</div>
|
||||
<div style="font-size: 0.7rem; opacity: 0.6;"><i class="bi bi-geo-alt-fill"></i> Conectado</div>
|
||||
</div>
|
||||
</div>
|
||||
<a href="https://wa.me/${user.phone_number.replace(/\D/g, '')}" target="_blank" style="background: #25D366; color: white; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; text-decoration: none; box-shadow: 0 4px 10px rgba(37, 211, 102, 0.3); transition: transform 0.2s;" onmouseover="this.style.transform='scale(1.1)'" onmouseout="this.style.transform='scale(1)'">
|
||||
<i class="bi bi-whatsapp"></i>
|
||||
</a>
|
||||
</div>
|
||||
`).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}$/;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user