-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperties.php
More file actions
83 lines (77 loc) · 4.01 KB
/
properties.php
File metadata and controls
83 lines (77 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php require 'config.php';
if (!isset($_SESSION['user'])) {
header('Location: login.php');
exit();
}
$user = $_SESSION['user'];
?>
<!DOCTYPE html>
<html>
<head>
<title>Available Properties - Apartment Rental</title>
<link rel="stylesheet" href="style.css">
<style>
.property-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); gap: 30px; padding: 40px 20px; }
.property-card { background: white; border-radius: 25px; overflow: hidden; box-shadow: 0 20px 50px rgba(93,64,55,0.2); transition: 0.4s; }
.property-card:hover { transform: translateY(-15px); box-shadow: 0 30px 70px rgba(93,64,55,0.3); }
.property-card img { width: 100%; height: 250px; object-fit: cover; }
.property-info { padding: 25px; }
.price { font-size: 1.8rem; color: #6d4c41; font-weight: bold; margin: 10px 0; }
.location { color: #8d6e63; font-weight: 500; }
.btn-view { background: #6d4c41; color: white; padding: 15px 30px; border-radius: 50px; text-decoration: none; display: inline-block; margin-top: 15px; font-weight: bold; }
.btn-view:hover { background: #8d6e63; transform: scale(1.05); }
.booked-badge { background: #f39c12; color: white; padding: 8px 15px; border-radius: 50px; font-size: 0.9rem; position: absolute; top: 20px; right: 20px; z-index: 10; }
</style>
</head>
<body>
<div class="header">
<h1>Find Your Perfect Home</h1>
<p style="color:#f5e6d3;">Welcome, <?= htmlspecialchars($user['name']) ?> • <?= ucfirst($user['role']) ?></p>
<a href="dashboard.php" style="color:white; margin:0 20px;">Dashboard</a>
<a href="my_bookings.php" style="color:white;">My Bookings</a>
<a href="chat.php" style="color:white;">Messages</a>
<a href="logout.php" class="logout-btn">Logout</a>
</div>
<div class="container">
<h2 style="text-align:center; color:#6d4c41; margin:40px 0; font-size:2.5rem;">
Available Properties in Uganda
</h2>
<div class="property-grid">
<?php
// SHOW ALL AVAILABLE PROPERTIES - EVEN IF TENANT HAS BOOKED BEFORE!
$sql = "SELECT p.*, pi.image_path,
(SELECT COUNT(*) FROM bookings b WHERE b.property_id = p.id AND b.tenant_id = {$user['id']} AND b.status != 'cancelled') as booked_by_me
FROM properties p
LEFT JOIN property_images pi ON p.id = pi.property_id AND pi.is_main = 1
WHERE p.status = 'available'
ORDER BY p.created_at DESC";
$result = $conn->query($sql);
if ($result->num_rows == 0) {
echo "<div style='grid-column:1/-1; text-align:center; padding:100px;'>
<h2>No properties available right now</h2>
<p>Check back soon – new listings daily!</p>
</div>";
}
while ($prop = $result->fetch_assoc()) {
$img = $prop['image_path'] ?? 'images/placeholder.jpg';
$already_booked = $prop['booked_by_me'] > 0;
echo "
<div class='property-card' style='position:relative;'>
" . ($already_booked ? "<div class='booked-badge'>You Booked</div>" : "") . "
<img src='$img' alt='Property'>
<div class='property-info'>
<h3>" . htmlspecialchars($prop['title']) . "</h3>
<p class='location'>📍 " . htmlspecialchars($prop['location']) . "</p>
<p>🛏️ {$prop['bedrooms']} Bed | 🚿 {$prop['bathrooms']} Bath | 📏 {$prop['size_sqft']} sqft</p>
<p class='price'>UGX " . number_format($prop['price']) . " <small>/month</small></p>
<a href='property_details.php?id={$prop['id']}' class='btn-view'>
" . ($already_booked ? "View Your Booking" : "View Details & Book") . "
</a>
</div>
</div>";
}
?>
</div>
</div>
</body>
</html>