query("SELECT id,titulo FROM landing_pages WHERE id={$landing_id}")->fetch_assoc(); if (!$landing) { die('Landing no existe'); } $msg = $err = ''; $action = $_GET['action'] ?? ''; $id = (int)($_GET['id'] ?? 0); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $hid = (int)($_POST['id'] ?? 0); $nombre= trim($_POST['nombre'] ?? ''); $endpoint = trim($_POST['endpoint'] ?? ''); $method = $_POST['method'] ?? 'POST'; $secret = trim($_POST['secret'] ?? ''); $active = isset($_POST['active']) ? 1 : 0; if ($nombre === '' || $endpoint === '' || !in_array($method, ['POST','GET'], true)) { $err = 'Nombre, endpoint y método (POST/GET) son obligatorios.'; } else { try { if ($hid > 0) { $st = $conn->prepare("UPDATE landing_crm_hooks SET nombre=?, endpoint=?, method=?, secret=?, active=? WHERE id=? AND landing_id=?"); $st->bind_param("ssssiii", $nombre, $endpoint, $method, $secret, $active, $hid, $landing_id); $st->execute(); $msg = 'Hook actualizado.'; } else { $st = $conn->prepare("INSERT INTO landing_crm_hooks (landing_id, nombre, endpoint, method, secret, active) VALUES (?,?,?,?,?,?)"); $st->bind_param("issssi", $landing_id, $nombre, $endpoint, $method, $secret, $active); $st->execute(); $msg = 'Hook creado.'; } } catch (Throwable $e) { $err = $e->getMessage(); } } } if ($action === 'delete' && $id > 0) { try { $st = $conn->prepare("DELETE FROM landing_crm_hooks WHERE id=? AND landing_id=?"); $st->bind_param("ii", $id, $landing_id); $st->execute(); $msg = 'Hook eliminado.'; } catch (Throwable $e) { $err = $e->getMessage(); } $id = 0; } $edit = null; if ($action === 'edit' && $id > 0) { $st = $conn->prepare("SELECT * FROM landing_crm_hooks WHERE id=? AND landing_id=?"); $st->bind_param("ii", $id, $landing_id); $st->execute(); $edit = $st->get_result()->fetch_assoc(); } $list = $conn->query("SELECT * FROM landing_crm_hooks WHERE landing_id={$landing_id} ORDER BY id DESC"); ?>