"; echo "🧪 Datos de Prueba"; echo ""; echo "

🧪 CREADOR DE DATOS DE PRUEBA

"; try { require_once 'config/config.php'; $pdo = new PDO( "mysql:host=" . DB_HOST . ";port=" . DB_PORT . ";dbname=" . DB_NAME . ";charset=" . DB_CHARSET, DB_USER, DB_PASS, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION] ); echo "
✅ Conectado a la base de datos
"; // Verificar si ya hay datos $stmt = $pdo->query("SELECT COUNT(*) as count FROM users"); $userCount = $stmt->fetch()['count']; $stmt = $pdo->query("SELECT COUNT(*) as count FROM conversations"); $convCount = $stmt->fetch()['count']; echo "
"; echo "

📊 ESTADO ACTUAL

"; echo "
Usuarios existentes: $userCount
"; echo "
Conversaciones existentes: $convCount
"; echo "
"; if ($_POST && isset($_POST['create_data'])) { echo "
"; echo "

🔨 CREANDO DATOS DE PRUEBA...

"; // Datos de usuarios de muestra - PERSONALIZA AQUÍ $sampleUsers = [ ['phone' => '+573168950803', 'name' => 'Usuario Principal'] ]; $userIds = []; foreach ($sampleUsers as $user) { // Verificar si el usuario ya existe $stmt = $pdo->prepare("SELECT id FROM users WHERE phone_number = ?"); $stmt->execute([$user['phone']]); $existingUser = $stmt->fetch(); if ($existingUser) { $userIds[] = $existingUser['id']; echo "
⚠️ Usuario ya existe: {$user['name']} ({$user['phone']})
"; } else { $stmt = $pdo->prepare(" INSERT INTO users (phone_number, name, status, created_at) VALUES (?, ?, 'active', NOW()) "); $stmt->execute([$user['phone'], $user['name']]); $userIds[] = $pdo->lastInsertId(); echo "
✅ Usuario creado: {$user['name']} ({$user['phone']})
"; } } // Crear conversaciones de muestra $sampleconversations = [ ['text' => 'Hola, necesito información sobre sus servicios', 'direction' => 'incoming'], ['text' => '¡Hola! Claro, te ayudo con gusto. ¿Qué tipo de servicio te interesa?', 'direction' => 'outgoing'], ['text' => 'Estoy buscando precios de desarrollo web', 'direction' => 'incoming'], ['text' => 'Perfecto, tenemos varios paquetes disponibles. Te envío la información.', 'direction' => 'outgoing'], ['text' => 'Gracias, muy amables', 'direction' => 'incoming'], ['text' => 'Buenos días, ¿están disponibles?', 'direction' => 'incoming'], ['text' => '¡Buenos días! Sí, estamos aquí para ayudarte. ¿En qué podemos asistirte?', 'direction' => 'outgoing'], ['text' => 'Quería hacer una consulta sobre horarios', 'direction' => 'incoming'], ['text' => 'Hola! Me pueden ayudar con un problema técnico?', 'direction' => 'incoming'], ['text' => 'Por supuesto! Cuéntanos qué problema tienes', 'direction' => 'outgoing'] ]; $conversationsCreated = 0; foreach ($userIds as $index => $userId) { // Crear 2-3 mensajes por usuario $messageCount = rand(2, 4); for ($i = 0; $i < $messageCount; $i++) { $messageIndex = ($index * $messageCount + $i) % count($sampleconversations); $message = $sampleconversations[$messageIndex]; $messageData = [ 'user_id' => $userId, 'content' => $message['text'], 'direction' => $message['direction'], 'message_type' => 'text', 'status' => $message['direction'] === 'outgoing' ? 'delivered' : 'sent', 'created_at' => date('Y-m-d H:i:s', strtotime("-" . rand(1, 72) . " hours")) ]; // Intentar insertar en conversations try { $stmt = $pdo->prepare(" INSERT INTO conversations (user_id, content, direction, message_type, status, created_at) VALUES (?, ?, ?, ?, ?, ?) "); $stmt->execute([ $messageData['user_id'], $messageData['content'], $messageData['direction'], $messageData['message_type'], $messageData['status'], $messageData['created_at'] ]); $conversationsCreated++; } catch (Exception $e) { // Si falla, intentar en conversations try { $stmt = $pdo->prepare(" INSERT INTO conversations (user_id, message_text, direction, message_type, status, created_at) VALUES (?, ?, ?, ?, ?, ?) "); $stmt->execute([ $messageData['user_id'], $messageData['content'], $messageData['direction'], $messageData['message_type'], $messageData['status'], $messageData['created_at'] ]); $conversationsCreated++; } catch (Exception $e2) { echo "
❌ Error creando mensaje: " . $e2->getMessage() . "
"; } } } } echo "
✅ Usuarios creados: " . count($userIds) . "
"; echo "
✅ Mensajes/conversaciones creados: $conversationsCreated
"; echo "
🎉 ¡Datos de prueba creados exitosamente!
"; echo "
SIGUIENTE PASO:
"; echo "
• Visita: conversations.php
"; echo "
• O ve al panel: index.php
"; echo "
"; } } catch (Exception $e) { echo "
❌ Error: " . htmlspecialchars($e->getMessage()) . "
"; } if (!$_POST) { echo "
"; echo "

⚠️ CREAR DATOS DE PRUEBA

"; echo "
Esto creará usuarios y conversaciones de muestra para probar el sistema
"; echo "
Solo ejecuta esto si no tienes datos reales o quieres probar
"; echo "
"; echo ""; echo "
"; echo "
"; } echo ""; ?>