69 lines
2.6 KiB
PHP
69 lines
2.6 KiB
PHP
<?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'; ?>
|