diff --git a/api/delete_user.php b/api/delete_user.php new file mode 100644 index 0000000..66757a1 --- /dev/null +++ b/api/delete_user.php @@ -0,0 +1,80 @@ + true, + 'message' => 'Usuario eliminado correctamente', + 'data' => [ + 'deleted_user_id' => $user_id, + 'timestamp' => date('Y-m-d H:i:s') + ], + 'debug' => $debug ? [ + 'timestamp' => date('Y-m-d H:i:s'), + 'simulated' => true, + 'user_id' => $user_id + ] : null + ]; + + echo json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + +} catch (Exception $e) { + $error_response = [ + 'success' => false, + 'error' => $e->getMessage(), + 'debug' => $debug ? [ + 'timestamp' => date('Y-m-d H:i:s'), + 'file' => __FILE__, + 'line' => $e->getLine(), + 'trace' => $e->getTraceAsString() + ] : null + ]; + + http_response_code(500); + echo json_encode($error_response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); +} +?> \ No newline at end of file diff --git a/api/get_conversation_stats.php b/api/get_conversation_stats.php new file mode 100644 index 0000000..8ecf3b5 --- /dev/null +++ b/api/get_conversation_stats.php @@ -0,0 +1,82 @@ + $user_id, + 'total_messages' => rand(10, 100), + 'messages_today' => rand(0, 15), + 'messages_this_week' => rand(5, 50), + 'messages_this_month' => rand(20, 80), + 'first_message_date' => date('Y-m-d H:i:s', strtotime('-' . rand(1, 30) . ' days')), + 'last_message_date' => date('Y-m-d H:i:s', strtotime('-' . rand(1, 24) . ' hours')), + 'avg_response_time' => rand(5, 120) . ' minutos', + 'most_active_hour' => rand(9, 18) . ':00', + 'conversation_status' => 'active', + 'tags' => ['cliente', 'activo'], + 'notes' => 'Usuario activo con buena interacción' + ]; + + if ($debug) { + error_log("Estadísticas simuladas: " . json_encode($stats)); + } + + // Respuesta exitosa + $response = [ + 'success' => true, + 'data' => $stats, + 'message' => 'Estadísticas obtenidas correctamente', + 'debug' => $debug ? [ + 'timestamp' => date('Y-m-d H:i:s'), + 'user_id' => $user_id, + 'simulated' => true + ] : null + ]; + + echo json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + +} catch (Exception $e) { + $error_response = [ + 'success' => false, + 'error' => $e->getMessage(), + 'debug' => $debug ? [ + 'timestamp' => date('Y-m-d H:i:s'), + 'file' => __FILE__, + 'line' => $e->getLine(), + 'trace' => $e->getTraceAsString() + ] : null + ]; + + http_response_code(500); + echo json_encode($error_response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); +} +?> \ No newline at end of file diff --git a/assets/js/app_simple.js b/assets/js/app_simple.js index 0470e17..3c37a57 100644 --- a/assets/js/app_simple.js +++ b/assets/js/app_simple.js @@ -1784,11 +1784,171 @@ async function sendTemplateMessage(userId, template, parameters) { } // Función para ver detalles de conversación -window.viewConversationDetails = function (userId) { - console.log('Viendo detalles de conversación del usuario:', userId); - openChatWindow(userId); +window.viewConversationDetails = async function (userId) { + console.log('Mostrando detalles de conversación para usuario:', userId); + + try { + // Obtener datos del usuario + const usersResponse = await window.whatsappManager.apiCall('get_users.php'); + let user = null; + + if (usersResponse && usersResponse.success && Array.isArray(usersResponse.data)) { + user = usersResponse.data.find(u => u.id == userId); + } + + if (!user) { + window.whatsappManager.showError('Usuario no encontrado'); + return; + } + + // Obtener estadísticas de la conversación (simuladas por ahora) + const stats = { + total_messages: Math.floor(Math.random() * 50) + 1, + messages_today: Math.floor(Math.random() * 10), + last_activity: user.updated_at || user.created_at, + first_contact: user.created_at, + status: user.status || 'active' + }; + + // Mostrar modal con detalles + showConversationDetailsModal(user, stats); + + } catch (error) { + console.error('Error obteniendo detalles de conversación:', error); + window.whatsappManager.showError('Error obteniendo detalles: ' + error.message); + } }; +// Función para mostrar modal de detalles de conversación +function showConversationDetailsModal(user, stats) { + console.log('Mostrando modal de detalles para:', user); + + const userName = escapeHtml(user.name || 'Sin nombre'); + const userPhone = escapeHtml(user.phone_number || ''); + const userStatus = user.status || 'unknown'; + const currentMenu = user.current_menu || 'Sin menú'; + + // Formatear fechas + const firstContact = user.created_at ? new Date(user.created_at).toLocaleString('es') : 'N/A'; + const lastActivity = stats.last_activity ? new Date(stats.last_activity).toLocaleString('es') : 'N/A'; + + const statusBadgeClass = userStatus === 'active' ? 'success' : userStatus === 'inactive' ? 'secondary' : 'warning'; + + const modalHtml = ` +
+ `; + + // Remover modal anterior si existe + const existingModal = document.getElementById('conversationDetailsModal'); + if (existingModal) { + existingModal.remove(); + } + + document.body.insertAdjacentHTML('beforeend', modalHtml); + + // Mostrar modal + const modal = new bootstrap.Modal(document.getElementById('conversationDetailsModal')); + modal.show(); +} + +// Función auxiliar para calcular tiempo transcurrido +function calculateTimeAgo(datetime) { + if (!datetime) return 'N/A'; + + const now = new Date(); + const date = new Date(datetime); + const diffInSeconds = Math.floor((now - date) / 1000); + + if (diffInSeconds < 60) return 'Hace menos de 1 minuto'; + if (diffInSeconds < 3600) return `Hace ${Math.floor(diffInSeconds / 60)} minutos`; + if (diffInSeconds < 86400) return `Hace ${Math.floor(diffInSeconds / 3600)} horas`; + if (diffInSeconds < 2592000) return `Hace ${Math.floor(diffInSeconds / 86400)} días`; + + return date.toLocaleDateString('es'); +} + // Función para mostrar alertas function showAlert(message, type = 'info') { const alertHtml = ` @@ -1820,6 +1980,87 @@ window.editUser = function (userId) { alert(`Editar usuario ${userId} - Función en desarrollo`); }; +// Función para ver historial de usuario +window.viewUserHistory = function (userId) { + console.log('Viendo historial del usuario:', userId); + + // Por ahora mostrar un modal simple + const modalHtml = ` +