From b9a427bb56c9c938df819824ff6249f3da07fad6 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 4 Dec 2025 03:23:32 +0000 Subject: [PATCH] Inmobiliaria 1 prueba --- assets/css/custom.css | 34 ++++ dashboard.php | 69 +++++++ db/migrations/001_create_agents_table.sql | 15 ++ db/migrations/002_create_properties_table.sql | 14 ++ .../003_add_subscription_to_agents.sql | 1 + edit_profile.php | 123 ++++++++++++ index.php | 157 +-------------- login.php | 74 +++++++ logout.php | 16 ++ properties.php | 189 ++++++++++++++++++ register.php | 94 +++++++++ templates/footer.php | 4 + templates/header.php | 46 +++++ 13 files changed, 689 insertions(+), 147 deletions(-) create mode 100644 assets/css/custom.css create mode 100644 dashboard.php create mode 100644 db/migrations/001_create_agents_table.sql create mode 100644 db/migrations/002_create_properties_table.sql create mode 100644 db/migrations/003_add_subscription_to_agents.sql create mode 100644 edit_profile.php create mode 100644 login.php create mode 100644 logout.php create mode 100644 properties.php create mode 100644 register.php create mode 100644 templates/footer.php create mode 100644 templates/header.php diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..86bd0ec --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,34 @@ +body { + background-color: #f8f9fa; + font-family: 'Inter', sans-serif; +} + +.card { + border: none; + box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15); +} + +.card-header { + background-color: #1D4ED8; + color: white; + text-align: center; + padding: 1.5rem; +} + +.btn-primary { + background-color: #1D4ED8; + border-color: #1D4ED8; +} + +.btn-primary:hover { + background-color: #1e40af; + border-color: #1e40af; +} + +.navbar { + box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15); +} + +.footer { + box-shadow: 0 -0.5rem 1rem rgba(0, 0, 0, 0.15); +} diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..bd39a0b --- /dev/null +++ b/dashboard.php @@ -0,0 +1,69 @@ +prepare("SELECT * FROM properties WHERE agent_id = ? ORDER BY created_at DESC"); +$stmt->execute([$agent_id]); +$properties = $stmt->fetchAll(); + +include 'templates/header.php'; +?> + +
+
+

Bienvenido,

+ + Agregar Propiedad +
+ +
+
+

Mis Propiedades

+
+
+ +

Aún no has agregado ninguna propiedad. ¡Crea la primera!

+ +
+ + + + + + + + + + + + + + + + + + + + + +
TítuloPrecioTipoUbicaciónAcciones
$ + Editar + Eliminar +
+
+ +
+
+
+ + \ No newline at end of file diff --git a/db/migrations/001_create_agents_table.sql b/db/migrations/001_create_agents_table.sql new file mode 100644 index 0000000..e97831b --- /dev/null +++ b/db/migrations/001_create_agents_table.sql @@ -0,0 +1,15 @@ +CREATE TABLE IF NOT EXISTS agents ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE, + phone VARCHAR(50), + agency VARCHAR(255), + password VARCHAR(255) NOT NULL, + photo VARCHAR(255), + slogan VARCHAR(255), + website VARCHAR(255), + facebook VARCHAR(255), + instagram VARCHAR(255), + linkedin VARCHAR(255), + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/db/migrations/002_create_properties_table.sql b/db/migrations/002_create_properties_table.sql new file mode 100644 index 0000000..638f419 --- /dev/null +++ b/db/migrations/002_create_properties_table.sql @@ -0,0 +1,14 @@ +CREATE TABLE IF NOT EXISTS properties ( + id INT AUTO_INCREMENT PRIMARY KEY, + agent_id INT NOT NULL, + title VARCHAR(255) NOT NULL, + description TEXT, + price DECIMAL(10, 2) NOT NULL, + location VARCHAR(255) NOT NULL, + bedrooms INT, + bathrooms INT, + type VARCHAR(100), + status VARCHAR(50) DEFAULT 'available', /* available, sold, rented */ + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (agent_id) REFERENCES agents(id) +); diff --git a/db/migrations/003_add_subscription_to_agents.sql b/db/migrations/003_add_subscription_to_agents.sql new file mode 100644 index 0000000..89f230a --- /dev/null +++ b/db/migrations/003_add_subscription_to_agents.sql @@ -0,0 +1 @@ +ALTER TABLE agents ADD COLUMN subscription_status VARCHAR(20) NOT NULL DEFAULT 'active'; diff --git a/edit_profile.php b/edit_profile.php new file mode 100644 index 0000000..e7e799e --- /dev/null +++ b/edit_profile.php @@ -0,0 +1,123 @@ +prepare("SELECT name, email, phone, bio, subscription_status FROM agents WHERE id = ?"); +$stmt->execute([$agent_id]); +$agent = $stmt->fetch(); + +if ($_SERVER["REQUEST_METHOD"] == "POST") { + // Note: Subscription status is not editable by the user. + $name = trim($_POST['name']); + $email = trim($_POST['email']); + $phone = trim($_POST['phone']); + $bio = trim($_POST['bio']); + + if (empty($name)) { + $errors[] = 'El nombre es obligatorio.'; + } + if (empty($email)) { + $errors[] = 'El email es obligatorio.'; + } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + $errors[] = 'El formato del email no es válido.'; + } + + // Check if email is being changed and if the new one already exists + if ($email !== $agent['email']) { + $stmt = db()->prepare("SELECT id FROM agents WHERE email = ?"); + $stmt->execute([$email]); + if ($stmt->fetch()) { + $errors[] = 'El nuevo email ya está en uso por otra cuenta.'; + } + } + + if (empty($errors)) { + $stmt = db()->prepare("UPDATE agents SET name = ?, email = ?, phone = ?, bio = ? WHERE id = ?"); + if ($stmt->execute([$name, $email, $phone, $bio, $agent_id])) { + $_SESSION['agent_name'] = $name; // Update session name + $success_message = 'Perfil actualizado con éxito.'; + // Re-fetch data to display updated values + $stmt = db()->prepare("SELECT name, email, phone, bio, subscription_status FROM agents WHERE id = ?"); + $stmt->execute([$agent_id]); + $agent = $stmt->fetch(); + } else { + $errors[] = 'Hubo un error al actualizar el perfil.'; + } + } +} + +include 'templates/header.php'; +?> + +
+
+
+
+
+

Editar Perfil

+
+
+
+
Estado de la Suscripción
+

+ + Activa + + Inactiva + +

+
+ + +
+ +

+ +
+ + +
+

+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + Cancelar +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/index.php b/index.php index 7205f3d..f5de3a3 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,13 @@ - - - - - - New Style - - - - - - - - - - - - - - - - - - - - - -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

-
-
- - - diff --git a/login.php b/login.php new file mode 100644 index 0000000..12d387c --- /dev/null +++ b/login.php @@ -0,0 +1,74 @@ +prepare("SELECT id, name, password FROM agents WHERE email = ?"); + $stmt->execute([$email]); + $agent = $stmt->fetch(); + + if ($agent && password_verify($password, $agent['password'])) { + // Password is correct, start session + $_SESSION['agent_id'] = $agent['id']; + $_SESSION['agent_name'] = $agent['name']; + header("Location: dashboard.php"); + exit; + } else { + $errors[] = 'Email o contraseña incorrectos.'; + } + } +} + +include 'templates/header.php'; +?> + +
+
+
+
+
+

Login de Agente

+
+
+ +
+ +

+ +
+ +
+
+ + +
+
+ + +
+ +
+
+ +
+
+
+
+ + \ No newline at end of file diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..999400f --- /dev/null +++ b/logout.php @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/properties.php b/properties.php new file mode 100644 index 0000000..052ee0c --- /dev/null +++ b/properties.php @@ -0,0 +1,189 @@ +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ítuloUbicaciónPrecioTipoAcciones
$ + Editar + Eliminar +
+
+ +
+
+ + diff --git a/register.php b/register.php new file mode 100644 index 0000000..924cb6b --- /dev/null +++ b/register.php @@ -0,0 +1,94 @@ +prepare("SELECT id FROM agents WHERE email = ?"); + $stmt->execute([$email]); + if ($stmt->fetch()) { + $errors[] = 'El email ya está registrado.'; + } else { + // Hash password and insert user + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + $stmt = db()->prepare("INSERT INTO agents (name, email, password) VALUES (?, ?, ?)"); + if ($stmt->execute([$name, $email, $hashed_password])) { + $success_message = '¡Registro exitoso! Ahora puedes iniciar sesión.'; + } else { + $errors[] = 'Hubo un error al crear la cuenta. Por favor, inténtalo de nuevo.'; + } + } + } +} + +include 'templates/header.php'; +?> + +
+
+
+
+
+

Registro de Agente

+
+
+ +
+ +

+ +
+ + +
+

+
+ +
+
+ + +
+
+ + +
+
+ + +
+ +
+ +
+ +
+
+
+
+ + \ No newline at end of file diff --git a/templates/footer.php b/templates/footer.php new file mode 100644 index 0000000..2c919c8 --- /dev/null +++ b/templates/footer.php @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/templates/header.php b/templates/header.php new file mode 100644 index 0000000..5baec39 --- /dev/null +++ b/templates/header.php @@ -0,0 +1,46 @@ + + + + + + + <?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Real Estate App'); ?> + + + + + + +
\ No newline at end of file