diff --git a/api/save_menu.php b/api/save_menu.php index 6a9ef14..136eae2 100644 --- a/api/save_menu.php +++ b/api/save_menu.php @@ -87,6 +87,12 @@ try { // Mapear status a is_active: 'active' -> 1, cualquier otra cosa -> 0 $menuData['is_active'] = (($input['status'] ?? 'active') === 'active') ? 1 : 0; } + + // Guardar tipo de menú (main | no_advisor) + if (in_array('menu_type', $availableColumns)) { + $rawType = $input['menu_type'] ?? 'main'; + $menuData['menu_type'] = in_array($rawType, ['main', 'no_advisor'], true) ? $rawType : 'main'; + } if (in_array('order_position', $availableColumns) && !$isUpdate) { // Solo establecer order_position para menús nuevos diff --git a/api/set_advisor_mode.php b/api/set_advisor_mode.php new file mode 100644 index 0000000..448cc3d --- /dev/null +++ b/api/set_advisor_mode.php @@ -0,0 +1,70 @@ +fetch( + "SELECT config_value FROM system_config WHERE config_key = 'advisor_available' LIMIT 1" + ); + $available = $row ? (bool)(int)$row['config_value'] : true; + echo json_encode(['success' => true, 'available' => $available]); + exit; + } + + if ($_SERVER['REQUEST_METHOD'] !== 'POST') { + http_response_code(405); + echo json_encode(['success' => false, 'error' => 'Método no permitido']); + exit; + } + + $input = json_decode(file_get_contents('php://input'), true); + if (!isset($input['available'])) { + http_response_code(400); + echo json_encode(['success' => false, 'error' => 'Falta el campo "available"']); + exit; + } + + $value = $input['available'] ? '1' : '0'; + + // Upsert en system_config + $existing = $db->fetch( + "SELECT id FROM system_config WHERE config_key = 'advisor_available' LIMIT 1" + ); + + if ($existing) { + $db->update( + 'system_config', + ['config_value' => $value, 'updated_at' => date('Y-m-d H:i:s')], + 'config_key = :k', + ['k' => 'advisor_available'] + ); + } else { + $db->insert('system_config', [ + 'config_key' => 'advisor_available', + 'config_value' => $value, + 'description' => 'Indica si hay asesores disponibles (1=sí, 0=no).', + 'created_at' => date('Y-m-d H:i:s'), + ]); + } + + $label = $value === '1' ? 'disponible' : 'ausente'; + error_log("[AdvisorMode] Modo asesor cambiado a '{$label}' por usuario=" . ($_SESSION['user_id'] ?? 'unknown')); + + echo json_encode(['success' => true, 'available' => (bool)(int)$value, 'label' => $label]); + +} catch (Exception $e) { + error_log('[set_advisor_mode] Error: ' . $e->getMessage()); + http_response_code(500); + echo json_encode(['success' => false, 'error' => 'Error interno del servidor']); +} diff --git a/assets/js/app.js b/assets/js/app.js index 50b2d58..a271256 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -785,7 +785,8 @@ class WhatsAppBotManager { title: document.getElementById('menu-title').value, description: document.getElementById('menu-description').value, parent_id: document.getElementById('menu-parent').value || null, - is_active: document.getElementById('menu-active').checked ? 1 : 0 + is_active: document.getElementById('menu-active').checked ? 1 : 0, + menu_type: document.getElementById('menu-type')?.value || 'main' }; try { diff --git a/assets/js/app_simple.js b/assets/js/app_simple.js index e47b61a..0374f61 100644 --- a/assets/js/app_simple.js +++ b/assets/js/app_simple.js @@ -1147,7 +1147,8 @@ class SimpleWhatsAppManager { menu_key: document.getElementById('menu-key')?.value || '', description: document.getElementById('menu-description')?.value || '', welcome_message: document.getElementById('menu-welcome-message')?.value || '', - status: document.getElementById('menu-status')?.value || 'active' + status: document.getElementById('menu-status')?.value || 'active', + menu_type: document.getElementById('menu-type')?.value || 'main' }; // Validar campos requeridos @@ -3841,6 +3842,13 @@ function showEditMenuModal(menuData) { + + @@ -4007,13 +4015,14 @@ window.saveMenuEdit = async function() { const menuDescription = document.getElementById('editMenuDescription').value.trim(); const menuWelcome = document.getElementById('editMenuWelcome').value.trim(); const menuStatus = document.getElementById('editMenuStatus').value; + const menuType = document.getElementById('editMenuType')?.value || 'main'; if (!menuName || !menuKey) { window.whatsappManager.showError('Nombre y clave del menú son obligatorios'); return; } - console.log('Guardando menú editado:', { menuId, menuName, menuKey, menuStatus }); + console.log('Guardando menú editado:', { menuId, menuName, menuKey, menuStatus, menuType }); const menuData = { id: menuId, @@ -4021,7 +4030,8 @@ window.saveMenuEdit = async function() { menu_key: menuKey, description: menuDescription, welcome_message: menuWelcome, - status: menuStatus + status: menuStatus, + menu_type: menuType }; try { diff --git a/conversations.php b/conversations.php index aa4c0ab..5941ec3 100644 --- a/conversations.php +++ b/conversations.php @@ -879,6 +879,17 @@ if (!isUserLoggedIn()) { v1.4.0- + +