Inmobiliaria 1 prueba
This commit is contained in:
parent
97f2a80a9e
commit
b9a427bb56
34
assets/css/custom.css
Normal file
34
assets/css/custom.css
Normal file
@ -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);
|
||||
}
|
||||
69
dashboard.php
Normal file
69
dashboard.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// If user is not logged in, redirect to login page
|
||||
if (!isset($_SESSION['agent_id'])) {
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
|
||||
$agent_id = $_SESSION['agent_id'];
|
||||
$agent_name = $_SESSION['agent_name'];
|
||||
|
||||
// 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();
|
||||
|
||||
include 'templates/header.php';
|
||||
?>
|
||||
|
||||
<div class="container mt-4">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1>Bienvenido, <?php echo htmlspecialchars($agent_name); ?></h1>
|
||||
<a href="properties.php" class="btn btn-primary">+ Agregar Propiedad</a>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3>Mis Propiedades</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (empty($properties)): ?>
|
||||
<p>Aún no has agregado ninguna propiedad. ¡<a href="properties.php">Crea la primera</a>!</p>
|
||||
<?php else: ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Título</th>
|
||||
<th>Precio</th>
|
||||
<th>Tipo</th>
|
||||
<th>Ubicación</th>
|
||||
<th>Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($properties as $prop): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($prop['title']); ?></td>
|
||||
<td>$<?php echo number_format($prop['price'], 2); ?></td>
|
||||
<td><?php echo htmlspecialchars(ucfirst($prop['type'])); ?></td>
|
||||
<td><?php echo htmlspecialchars($prop['location']); ?></td>
|
||||
<td>
|
||||
<a href="#" class="btn btn-sm btn-secondary">Editar</a>
|
||||
<a href="#" class="btn btn-sm btn-danger">Eliminar</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'templates/footer.php'; ?>
|
||||
15
db/migrations/001_create_agents_table.sql
Normal file
15
db/migrations/001_create_agents_table.sql
Normal file
@ -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
|
||||
);
|
||||
14
db/migrations/002_create_properties_table.sql
Normal file
14
db/migrations/002_create_properties_table.sql
Normal file
@ -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)
|
||||
);
|
||||
1
db/migrations/003_add_subscription_to_agents.sql
Normal file
1
db/migrations/003_add_subscription_to_agents.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE agents ADD COLUMN subscription_status VARCHAR(20) NOT NULL DEFAULT 'active';
|
||||
123
edit_profile.php
Normal file
123
edit_profile.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// If user is not logged in, redirect to login page
|
||||
if (!isset($_SESSION['agent_id'])) {
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
|
||||
$agent_id = $_SESSION['agent_id'];
|
||||
$errors = [];
|
||||
$success_message = '';
|
||||
|
||||
// Fetch current agent data
|
||||
$stmt = db()->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';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Editar Perfil</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-4 p-3 bg-light rounded border">
|
||||
<h6 class="mb-2 text-muted">Estado de la Suscripción</h6>
|
||||
<p class="mb-0">
|
||||
<?php if ($agent['subscription_status'] === 'active'): ?>
|
||||
<span class="badge bg-success fs-6">Activa</span>
|
||||
<?php else: ?>
|
||||
<span class="badge bg-warning text-dark fs-6">Inactiva</span>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p class="mb-0"><?php echo $error; ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($success_message): ?>
|
||||
<div class="alert alert-success">
|
||||
<p class="mb-0"><?php echo $success_message; ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="edit_profile.php" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Nombre Completo</label>
|
||||
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($agent['name']); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Correo Electrónico</label>
|
||||
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($agent['email']); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="phone" class="form-label">Teléfono</label>
|
||||
<input type="text" class="form-control" id="phone" name="phone" value="<?php echo htmlspecialchars($agent['phone'] ?? ''); ?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="bio" class="form-label">Biografía</label>
|
||||
<textarea class="form-control" id="bio" name="bio" rows="4"><?php echo htmlspecialchars($agent['bio'] ?? ''); ?></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Guardar Cambios</button>
|
||||
<a href="dashboard.php" class="btn btn-secondary">Cancelar</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
include 'templates/footer.php';
|
||||
?>
|
||||
157
index.php
157
index.php
@ -1,150 +1,13 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
session_start();
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
// If the agent is logged in, redirect to their dashboard.
|
||||
if (isset($_SESSION['agent_id'])) {
|
||||
header("Location: dashboard.php");
|
||||
exit;
|
||||
} else {
|
||||
// If not logged in, show the login page.
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
74
login.php
Normal file
74
login.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// If user is already logged in, redirect to dashboard
|
||||
if (isset($_SESSION['agent_id'])) {
|
||||
header("Location: dashboard.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$email = trim($_POST['email']);
|
||||
$password = $_POST['password'];
|
||||
|
||||
if (empty($email) || empty($password)) {
|
||||
$errors[] = 'El email y la contraseña son obligatorios.';
|
||||
} else {
|
||||
$stmt = db()->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';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-5">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Login de Agente</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p class="mb-0"><?php echo $error; ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="login.php" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Correo Electrónico</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Contraseña</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Iniciar Sesión</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
<p class="mb-0">¿No tienes una cuenta? <a href="register.php">Regístrate aquí</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'templates/footer.php'; ?>
|
||||
16
logout.php
Normal file
16
logout.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// Unset all of the session variables
|
||||
$_SESSION = [];
|
||||
|
||||
// Destroy the session.
|
||||
if (session_destroy()) {
|
||||
// Redirect to login page
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
} else {
|
||||
// Handle error, though session_destroy() rarely fails
|
||||
echo "Error: No se pudo cerrar la sesión.";
|
||||
}
|
||||
?>
|
||||
189
properties.php
Normal file
189
properties.php
Normal file
@ -0,0 +1,189 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// If user is not logged in, redirect to login page
|
||||
if (!isset($_SESSION['agent_id'])) {
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Fetch agent details, including subscription status
|
||||
$agent_id = $_SESSION['agent_id'];
|
||||
$stmt = db()->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';
|
||||
?>
|
||||
|
||||
<h1 class="mb-4">Gestionar Propiedades</h1>
|
||||
|
||||
<?php if ($success_message): ?>
|
||||
<div class="alert alert-success" role="alert">
|
||||
<?php echo htmlspecialchars($success_message); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($errors)):
|
||||
?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php foreach ($errors as $error):
|
||||
?>
|
||||
<p class="mb-0"><?php echo htmlspecialchars($error); ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<?php if ($is_active):
|
||||
?>
|
||||
<!-- Add Property Form -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
<h2 class="h5 mb-0">Añadir Nueva Propiedad</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="properties.php" method="POST">
|
||||
<input type="hidden" name="add_property" value="1">
|
||||
<div class="mb-3">
|
||||
<label for="title" class="form-label">Título <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="title" name="title" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="description" class="form-label">Descripción</label>
|
||||
<textarea class="form-control" id="description" name="description" rows="3"></textarea>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="price" class="form-label">Precio <span class="text-danger">*</span></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text">$</span>
|
||||
<input type="number" class="form-control" id="price" name="price" step="0.01" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="location" class="form-label">Ubicación <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="location" name="location" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="bedrooms" class="form-label">Habitaciones</label>
|
||||
<input type="number" class="form-control" id="bedrooms" name="bedrooms" min="0">
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="bathrooms" class="form-label">Baños</label>
|
||||
<input type="number" class="form-control" id="bathrooms" name="bathrooms" min="0">
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="type" class="form-label">Tipo <span class="text-danger">*</span></label>
|
||||
<select class="form-select" id="type" name="type" required>
|
||||
<option value="">Elegir...</option>
|
||||
<option value="Sale">En Venta</option>
|
||||
<option value="Rent">En Alquiler</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary"><i class="bi bi-plus-circle"></i> Añadir Propiedad</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="alert alert-warning" role="alert">
|
||||
<h4 class="alert-heading">Suscripción Inactiva</h4>
|
||||
<p>Tu suscripción no está activa. Por favor, contacta al administrador para activarla y poder añadir nuevas propiedades.</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<!-- Existing Properties List -->
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2 class="h5 mb-0">Tus Anuncios</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (empty($properties)):
|
||||
?>
|
||||
<p class="text-center text-muted">Aún no has publicado ninguna propiedad. Añade una usando el formulario de arriba.</p>
|
||||
<?php else: ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Título</th>
|
||||
<th>Ubicación</th>
|
||||
<th>Precio</th>
|
||||
<th>Tipo</th>
|
||||
<th>Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($properties as $property): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($property['title']); ?></td>
|
||||
<td><?php echo htmlspecialchars($property['location']); ?></td>
|
||||
<td>$<?php echo htmlspecialchars(number_format($property['price'], 2)); ?></td>
|
||||
<td><span class="badge bg-primary"><?php echo htmlspecialchars(ucfirst($property['type'])); ?></span></td>
|
||||
<td>
|
||||
<a href="#" class="btn btn-sm btn-outline-primary"><i class="bi bi-pencil-square"></i> Editar</a>
|
||||
<a href="#" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i> Eliminar</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once 'templates/footer.php'; ?>
|
||||
94
register.php
Normal file
94
register.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
$errors = [];
|
||||
$success_message = '';
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$name = trim($_POST['name']);
|
||||
$email = trim($_POST['email']);
|
||||
$password = $_POST['password'];
|
||||
|
||||
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.';
|
||||
}
|
||||
if (empty($password)) {
|
||||
$errors[] = 'La contraseña es obligatoria.';
|
||||
} elseif (strlen($password) < 6) {
|
||||
$errors[] = 'La contraseña debe tener al menos 6 caracteres.';
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
// Check if email already exists
|
||||
$stmt = db()->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 <a href="login.php">iniciar sesión</a>.';
|
||||
} else {
|
||||
$errors[] = 'Hubo un error al crear la cuenta. Por favor, inténtalo de nuevo.';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
include 'templates/header.php';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Registro de Agente</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p class="mb-0"><?php echo $error; ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($success_message): ?>
|
||||
<div class="alert alert-success">
|
||||
<p class="mb-0"><?php echo $success_message; ?></p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<form action="register.php" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Nombre Completo</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Correo Electrónico</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Contraseña</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Registrarse</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
<p class="mb-0">¿Ya tienes una cuenta? <a href="login.php">Inicia sesión aquí</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'templates/footer.php'; ?>
|
||||
4
templates/footer.php
Normal file
4
templates/footer.php
Normal file
@ -0,0 +1,4 @@
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
46
templates/header.php
Normal file
46
templates/header.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php session_start(); ?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title><?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Real Estate App'); ?></title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" href="assets/css/custom.css">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg bg-white border-bottom">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="index.php"><?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Real Estate'); ?></a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<?php if (isset($_SESSION['agent_id'])): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="dashboard.php">Dashboard</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="properties.php">Propiedades</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="edit_profile.php">Editar Perfil</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="logout.php">Cerrar Sesión</a>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="login.php">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="register.php">Registro</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container mt-4">
|
||||
Loading…
x
Reference in New Issue
Block a user