prepare("SELECT subscription_status FROM agents WHERE id = ?"); $stmt->execute([$agent_id]); $agent = $stmt->fetch(); $is_active = ($agent && $agent['subscription_status'] === 'active'); $errors = []; $success_message = ''; // Handle Post Request if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['add_property'])) { if (!$is_active) { $errors[] = 'Necesitas una suscripción activa para añadir nuevas propiedades.'; } else { $title = trim($_POST['title']); $description = trim($_POST['description']); $price = filter_input(INPUT_POST, 'price', FILTER_VALIDATE_FLOAT); $location = trim($_POST['location']); $bedrooms = filter_input(INPUT_POST, 'bedrooms', FILTER_VALIDATE_INT); $bathrooms = filter_input(INPUT_POST, 'bathrooms', FILTER_VALIDATE_INT); $type = trim($_POST['type']); if (empty($title)) { $errors[] = 'El título es obligatorio.'; } if ($price === false || $price <= 0) { $errors[] = 'Se requiere un precio válido.'; } if (empty($location)) { $errors[] = 'La ubicación es obligatoria.'; } if (empty($type)) { $errors[] = 'El tipo es obligatorio.'; } if (empty($errors)) { $stmt = db()->prepare( "INSERT INTO properties (agent_id, title, description, price, location, bedrooms, bathrooms, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" ); if ($stmt->execute([$agent_id, $title, $description, $price, $location, $bedrooms, $bathrooms, $type])) { $success_message = '¡Propiedad agregada con éxito!'; } else { $errors[] = 'Error al guardar la propiedad.'; } } } } // Fetch properties for the logged-in agent $stmt = db()->prepare("SELECT * FROM properties WHERE agent_id = ? ORDER BY created_at DESC"); $stmt->execute([$agent_id]); $properties = $stmt->fetchAll(); require_once 'templates/header.php'; ?>

Gestionar Propiedades

Añadir Nueva Propiedad

$

Tus Anuncios

Aún no has publicado ninguna propiedad. Añade una usando el formulario de arriba.

Título Ubicación Precio Tipo Acciones
$ Editar Eliminar