200 lines
8.7 KiB
PHP
200 lines
8.7 KiB
PHP
<?php
|
|
/**
|
|
* Test de conexión y estructura de menús
|
|
* Fecha: 12 de enero de 2026
|
|
*/
|
|
|
|
require_once 'config/config.php';
|
|
|
|
echo "<!DOCTYPE html>";
|
|
echo "<html><head><title>Test Menús - WhatsApp Bot</title>";
|
|
echo "<style>body{font-family:Arial;padding:20px;} .success{color:green;} .error{color:red;} .info{color:blue;} pre{background:#f5f5f5;padding:10px;}</style>";
|
|
echo "</head><body>";
|
|
|
|
echo "<h1>🔧 Test de Funcionalidad de Menús</h1>";
|
|
|
|
try {
|
|
$db = Database::getInstance();
|
|
echo "<div class='success'>✅ Conexión a base de datos: EXITOSA</div>";
|
|
|
|
// Verificar tabla menus
|
|
echo "<h2>📋 Verificando tabla 'menus'</h2>";
|
|
try {
|
|
$result = $db->fetchAll("SHOW TABLES LIKE 'menus'");
|
|
if (count($result) > 0) {
|
|
echo "<div class='success'>✅ Tabla 'menus' existe</div>";
|
|
|
|
// Mostrar estructura
|
|
$structure = $db->fetchAll("DESCRIBE menus");
|
|
echo "<h3>Estructura de tabla 'menus':</h3>";
|
|
echo "<pre>";
|
|
foreach ($structure as $column) {
|
|
echo "{$column['Field']} - {$column['Type']} - {$column['Null']} - {$column['Default']}\n";
|
|
}
|
|
echo "</pre>";
|
|
|
|
} else {
|
|
echo "<div class='error'>❌ Tabla 'menus' NO existe</div>";
|
|
echo "<div class='info'>💡 Creando tabla 'menus'...</div>";
|
|
|
|
$createMenusTable = "
|
|
CREATE TABLE IF NOT EXISTS menus (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(255) NOT NULL,
|
|
menu_key VARCHAR(100) NOT NULL,
|
|
description TEXT,
|
|
welcome_message TEXT,
|
|
status ENUM('active', 'inactive') DEFAULT 'active',
|
|
options_count INT DEFAULT 0,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
INDEX idx_menu_key (menu_key),
|
|
INDEX idx_status (status)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
|
|
|
|
$db->execute($createMenusTable);
|
|
echo "<div class='success'>✅ Tabla 'menus' creada</div>";
|
|
}
|
|
} catch (Exception $e) {
|
|
echo "<div class='error'>❌ Error verificando tabla 'menus': " . $e->getMessage() . "</div>";
|
|
}
|
|
|
|
// Verificar tabla menu_options
|
|
echo "<h2>📋 Verificando tabla 'menu_options'</h2>";
|
|
try {
|
|
$result = $db->fetchAll("SHOW TABLES LIKE 'menu_options'");
|
|
if (count($result) > 0) {
|
|
echo "<div class='success'>✅ Tabla 'menu_options' existe</div>";
|
|
|
|
// Mostrar estructura
|
|
$structure = $db->fetchAll("DESCRIBE menu_options");
|
|
echo "<h3>Estructura de tabla 'menu_options':</h3>";
|
|
echo "<pre>";
|
|
foreach ($structure as $column) {
|
|
echo "{$column['Field']} - {$column['Type']} - {$column['Null']} - {$column['Default']}\n";
|
|
}
|
|
echo "</pre>";
|
|
|
|
} else {
|
|
echo "<div class='error'>❌ Tabla 'menu_options' NO existe</div>";
|
|
echo "<div class='info'>💡 Creando tabla 'menu_options'...</div>";
|
|
|
|
$createMenuOptionsTable = "
|
|
CREATE TABLE IF NOT EXISTS menu_options (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
menu_id INT NOT NULL,
|
|
option_key VARCHAR(10) NOT NULL,
|
|
option_text VARCHAR(255) NOT NULL,
|
|
option_action ENUM('message', 'submenu', 'template', 'function') DEFAULT 'message',
|
|
option_value TEXT,
|
|
order_index INT DEFAULT 0,
|
|
is_active BOOLEAN DEFAULT true,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (menu_id) REFERENCES menus(id) ON DELETE CASCADE,
|
|
INDEX idx_menu_id (menu_id),
|
|
INDEX idx_option_key (option_key),
|
|
INDEX idx_order (order_index)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
|
|
|
|
$db->execute($createMenuOptionsTable);
|
|
echo "<div class='success'>✅ Tabla 'menu_options' creada</div>";
|
|
}
|
|
} catch (Exception $e) {
|
|
echo "<div class='error'>❌ Error verificando tabla 'menu_options': " . $e->getMessage() . "</div>";
|
|
}
|
|
|
|
// Verificar menús existentes
|
|
echo "<h2>📱 Menús existentes</h2>";
|
|
try {
|
|
$menus = $db->fetchAll("SELECT * FROM menus ORDER BY created_at DESC");
|
|
if (count($menus) > 0) {
|
|
echo "<div class='info'>📋 Se encontraron " . count($menus) . " menús:</div>";
|
|
echo "<pre>";
|
|
foreach ($menus as $menu) {
|
|
echo "ID: {$menu['id']} | Nombre: {$menu['name']} | Clave: {$menu['menu_key']} | Estado: {$menu['status']}\n";
|
|
}
|
|
echo "</pre>";
|
|
} else {
|
|
echo "<div class='info'>📋 No hay menús configurados aún</div>";
|
|
|
|
// Crear menú de ejemplo
|
|
echo "<div class='info'>💡 Creando menú de ejemplo...</div>";
|
|
|
|
$menuData = [
|
|
'name' => 'Menú Principal',
|
|
'menu_key' => 'main',
|
|
'description' => 'Menú principal del bot',
|
|
'welcome_message' => '¡Hola! Bienvenido a nuestro servicio. Por favor selecciona una opción:',
|
|
'status' => 'active',
|
|
'options_count' => 0
|
|
];
|
|
|
|
$menuId = $db->insert('menus', $menuData);
|
|
|
|
if ($menuId) {
|
|
echo "<div class='success'>✅ Menú de ejemplo creado (ID: {$menuId})</div>";
|
|
|
|
// Crear opciones de ejemplo
|
|
$options = [
|
|
['menu_id' => $menuId, 'option_key' => '1', 'option_text' => 'Información', 'option_action' => 'message', 'option_value' => 'Aquí tienes información sobre nuestros servicios', 'order_index' => 1],
|
|
['menu_id' => $menuId, 'option_key' => '2', 'option_text' => 'Soporte', 'option_action' => 'message', 'option_value' => 'Nuestro equipo de soporte te ayudará en breve', 'order_index' => 2],
|
|
['menu_id' => $menuId, 'option_key' => '0', 'option_text' => 'Salir', 'option_action' => 'message', 'option_value' => 'Gracias por contactarnos', 'order_index' => 3]
|
|
];
|
|
|
|
foreach ($options as $option) {
|
|
$db->insert('menu_options', $option);
|
|
}
|
|
|
|
// Actualizar contador de opciones
|
|
$db->execute("UPDATE menus SET options_count = 3 WHERE id = :id", ['id' => $menuId]);
|
|
|
|
echo "<div class='success'>✅ Opciones de menú creadas</div>";
|
|
}
|
|
}
|
|
} catch (Exception $e) {
|
|
echo "<div class='error'>❌ Error verificando menús: " . $e->getMessage() . "</div>";
|
|
}
|
|
|
|
// Test de API
|
|
echo "<h2>🔌 Test de API</h2>";
|
|
try {
|
|
$apiUrl = 'http://localhost:8000/api/get_menus.php';
|
|
echo "<div class='info'>📞 Probando API: {$apiUrl}</div>";
|
|
|
|
$context = stream_context_create([
|
|
'http' => [
|
|
'method' => 'GET',
|
|
'header' => 'Content-Type: application/json',
|
|
'timeout' => 10
|
|
]
|
|
]);
|
|
|
|
$response = @file_get_contents($apiUrl, false, $context);
|
|
|
|
if ($response !== false) {
|
|
$data = json_decode($response, true);
|
|
if ($data !== null) {
|
|
echo "<div class='success'>✅ API responde correctamente</div>";
|
|
echo "<pre>" . json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "</pre>";
|
|
} else {
|
|
echo "<div class='error'>❌ API responde pero JSON inválido</div>";
|
|
echo "<pre>" . htmlspecialchars($response) . "</pre>";
|
|
}
|
|
} else {
|
|
echo "<div class='error'>❌ No se pudo conectar a la API</div>";
|
|
}
|
|
} catch (Exception $e) {
|
|
echo "<div class='error'>❌ Error probando API: " . $e->getMessage() . "</div>";
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
echo "<div class='error'>❌ Error de conexión: " . $e->getMessage() . "</div>";
|
|
}
|
|
|
|
echo "<hr>";
|
|
echo "<p><strong>Estado del servidor:</strong> El servidor PHP está corriendo en <a href='http://localhost:8000' target='_blank'>http://localhost:8000</a></p>";
|
|
echo "<p><strong>Aplicación principal:</strong> <a href='http://localhost:8000/index.php' target='_blank'>WhatsApp Bot Manager</a></p>";
|
|
echo "<p><strong>Fecha de prueba:</strong> " . date('Y-m-d H:i:s') . "</p>";
|
|
|
|
echo "</body></html>";
|
|
?>
|