up
This commit is contained in:
+8
-1
@@ -41,11 +41,18 @@ try {
|
|||||||
// Total de mensajes
|
// Total de mensajes
|
||||||
$totalconversations = $db->fetch("SELECT COUNT(*) as count FROM conversations")['count'];
|
$totalconversations = $db->fetch("SELECT COUNT(*) as count FROM conversations")['count'];
|
||||||
|
|
||||||
|
// Mensajes pendientes / no leídos: preferir columna is_read si existe, si no usar status = 'received'
|
||||||
|
$unreadResult = $db->fetch(
|
||||||
|
"SELECT COUNT(*) as count FROM conversations WHERE direction = 'incoming' AND ( (is_read IS NULL OR is_read = 0) OR status = 'received' )"
|
||||||
|
);
|
||||||
|
$unreadMessages = intval($unreadResult['count'] ?? 0);
|
||||||
|
|
||||||
$stats = [
|
$stats = [
|
||||||
'total_users' => (int)$totalUsers,
|
'total_users' => (int)$totalUsers,
|
||||||
'conversations_today' => (int)$conversationsToday,
|
'conversations_today' => (int)$conversationsToday,
|
||||||
'active_users' => (int)$activeUsers,
|
'active_users' => (int)$activeUsers,
|
||||||
'total_conversations' => (int)$totalconversations
|
'total_conversations' => (int)$totalconversations,
|
||||||
|
'unread_messages' => $unreadMessages
|
||||||
];
|
];
|
||||||
|
|
||||||
echo json_encode($stats);
|
echo json_encode($stats);
|
||||||
|
|||||||
+15
-1
@@ -6,9 +6,17 @@
|
|||||||
|
|
||||||
require_once '../config/config.php';
|
require_once '../config/config.php';
|
||||||
|
|
||||||
|
// Asegurar que errores no se impriman al cliente y se registren en logs
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
@ini_set('display_errors', 0);
|
||||||
|
@ini_set('log_errors', 1);
|
||||||
|
|
||||||
// Verificar autenticación
|
// Verificar autenticación
|
||||||
requireAuthentication();
|
requireAuthentication();
|
||||||
|
|
||||||
|
// Forzar buffer para poder limpiar salidas accidentales
|
||||||
|
if (ob_get_level() === 0) ob_start();
|
||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
header('Access-Control-Allow-Origin: *');
|
header('Access-Control-Allow-Origin: *');
|
||||||
header('Access-Control-Allow-Methods: POST');
|
header('Access-Control-Allow-Methods: POST');
|
||||||
@@ -23,7 +31,13 @@ if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|||||||
try {
|
try {
|
||||||
// Verificar que se subió un archivo
|
// Verificar que se subió un archivo
|
||||||
if (!isset($_FILES['file']) || $_FILES['file']['error'] !== UPLOAD_ERR_OK) {
|
if (!isset($_FILES['file']) || $_FILES['file']['error'] !== UPLOAD_ERR_OK) {
|
||||||
throw new Exception('No se recibió ningún archivo o hubo un error en la carga');
|
// Log for debugging
|
||||||
|
error_log('upload_media.php - FILES content: ' . print_r($_FILES, true));
|
||||||
|
// Make sure any buffered content is cleared before sending JSON
|
||||||
|
if (ob_get_length()) ob_clean();
|
||||||
|
http_response_code(400);
|
||||||
|
echo json_encode(['success' => false, 'error' => 'No se recibió ningún archivo o hubo un error en la carga']);
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = $_FILES['file'];
|
$file = $_FILES['file'];
|
||||||
|
|||||||
+2
-2
@@ -194,10 +194,10 @@ class WhatsAppBotManager {
|
|||||||
document.getElementById('active-users').textContent = stats.active_users || 0;
|
document.getElementById('active-users').textContent = stats.active_users || 0;
|
||||||
document.getElementById('total-conversations').textContent = stats.total_conversations || 0;
|
document.getElementById('total-conversations').textContent = stats.total_conversations || 0;
|
||||||
|
|
||||||
// Actualizar badge de conversaciones en el menú lateral
|
// Actualizar badge de conversaciones en el menú lateral (usar mensajes pendientes si existe)
|
||||||
const convBadge = document.getElementById('conversations-count');
|
const convBadge = document.getElementById('conversations-count');
|
||||||
if (convBadge) {
|
if (convBadge) {
|
||||||
const val = stats.total_conversations || 0;
|
const val = (typeof stats.unread_messages !== 'undefined') ? stats.unread_messages : (stats.total_conversations || 0);
|
||||||
convBadge.textContent = val;
|
convBadge.textContent = val;
|
||||||
convBadge.style.display = val > 0 ? 'inline-block' : 'none';
|
convBadge.style.display = val > 0 ? 'inline-block' : 'none';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -274,10 +274,10 @@ class SimpleWhatsAppManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Actualizar badge de conversaciones en el menú lateral (compatibilidad con versión simple)
|
// Actualizar badge de conversaciones en el menú lateral (usar mensajes pendientes si existe)
|
||||||
const convBadge = document.getElementById('conversations-count');
|
const convBadge = document.getElementById('conversations-count');
|
||||||
if (convBadge) {
|
if (convBadge) {
|
||||||
const val = stats.total_conversations || 0;
|
const val = (typeof stats.unread_messages !== 'undefined') ? stats.unread_messages : (stats.total_conversations || 0);
|
||||||
convBadge.textContent = val;
|
convBadge.textContent = val;
|
||||||
convBadge.style.display = val > 0 ? 'inline-block' : 'none';
|
convBadge.style.display = val > 0 ? 'inline-block' : 'none';
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -530,8 +530,11 @@ if (empty($user_id)) {
|
|||||||
}
|
}
|
||||||
return JSON.parse(text);
|
return JSON.parse(text);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// Incluir parte del cuerpo en el error para ayudar al diagnóstico (truncado)
|
||||||
console.error('apiCall parse error for', url, err);
|
console.error('apiCall parse error for', url, err);
|
||||||
throw new Error('Invalid JSON response from ' + url + ': ' + err.message);
|
const respText = await response.text().catch(() => '');
|
||||||
|
const snippet = (respText && respText.length > 0) ? respText.substr(0, 1000) : '<no body available>';
|
||||||
|
throw new Error('Invalid JSON response from ' + url + ': ' + err.message + ' -- response snippet: ' + snippet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user