D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
sg.encodersunlimited.com
/
sgadminpr
/
Filename :
show-listing.php
back
Copy
<?php include 'config.php'; // Handle the delete action if (isset($_GET['id'])) { $propertyId = $_GET['id']; // Delete property images associated with this property first $deleteImagesQuery = "DELETE FROM property_images WHERE property_id = ?"; $stmt = $conn->prepare($deleteImagesQuery); $stmt->bind_param("i", $propertyId); $stmt->execute(); // Delete the property $deletePropertyQuery = "DELETE FROM properties WHERE id = ?"; $stmt = $conn->prepare($deletePropertyQuery); $stmt->bind_param("i", $propertyId); if ($stmt->execute()) { $_SESSION['message'] = "Property deleted successfully!"; } else { $_SESSION['error'] = "Failed to delete property!"; } $stmt->close(); $conn->close(); // Redirect to the same page to show updated list header("Location: show-listing.php"); exit(); } ?> <!doctype html> <html lang="en"> <head> <?php include "../style2.php"; ?> </head> <body> <div id="preloader"> <div class="loader--border"></div> </div> <div class="dashboard__page--wrapper"> <?php include "sidebar.php"; ?> <div class="page__body--wrapper" id="dashbody__page--body__wrapper"> <?php include "../header2.php"; ?> <main class="main__content_wrapper"> <div class="dashboard__container dashboard__reviews--container"> <div class="reviews__heading mb-30"> <h2 class="reviews__heading--title">My Properties</h2> <p class="reviews__heading--desc">We are glad to see you again!</p> </div> <div class="container mt-5"> <h4 class="mb-4">Property Listings</h4> <?php if (isset($_SESSION['message'])): ?> <div class="alert alert-success"><?= $_SESSION['message']; unset($_SESSION['message']); ?></div> <?php endif; ?> <?php if (isset($_SESSION['error'])): ?> <div class="alert alert-danger"><?= $_SESSION['error']; unset($_SESSION['error']); ?></div> <?php endif; ?> <div class="table-responsive"> <table class="table table-bordered" style="color: white;"> <thead class="table-dark"> <tr> <th>Image</th> <th>Title</th> <th>Address</th> <th>Rooms</th> <th>Price</th> <th>Status</th> <th>Amenities</th> <th>Actions</th> </tr> </thead> <tbody> <?php $query = "SELECT p.*, (SELECT image_path FROM property_images WHERE property_id = p.id LIMIT 1) AS image FROM properties p ORDER BY created_at DESC"; $result = $conn->query($query); if ($result->num_rows > 0): while ($row = $result->fetch_assoc()): // Fetch amenities $amenities = []; $amenityQuery = "SELECT a.name FROM amenities a JOIN property_amenities pa ON a.id = pa.amenity_id WHERE pa.property_id = ? LIMIT 3"; $amenityStmt = $conn->prepare($amenityQuery); $amenityStmt->bind_param("i", $row['id']); $amenityStmt->execute(); $amenityResult = $amenityStmt->get_result(); while ($amenityRow = $amenityResult->fetch_assoc()) { $amenities[] = $amenityRow['name']; } $amenityStmt->close(); // Set default image if no image is available $imgPath = !empty($row['image']) ? $row['image'] : "../assets2/img/dashboard/properties-author1.png"; $status = ucfirst($row['status']); $statusClass = $status === 'Available' ? 'bg-success' : ($status === 'Sold' ? 'bg-danger' : 'bg-warning'); ?> <tr> <td> <img src="<?= $imgPath ?>" alt="Property" width="80" height="60" style="object-fit: cover;"> </td> <td><strong><?= htmlspecialchars($row['title']) ?></strong></td> <td><?= htmlspecialchars($row['address']) ?></td> <td><?= htmlspecialchars($row['rooms']) ?></td> <td>₹<?= number_format($row['price']) ?></td> <td><span class="badge <?= $statusClass ?> text-light"><?= $status ?></span></td> <td> <?php if (!empty($amenities)): ?> <ul class="list-unstyled mb-0"> <?php foreach ($amenities as $amenity): ?> <li><i class="bi bi-check2-circle text-success me-1"></i><?= htmlspecialchars($amenity) ?></li> <?php endforeach; ?> </ul> <?php else: ?> <span class="text-muted">N/A</span> <?php endif; ?> </td> <td> <div class="dropdown"> <button class="btn btn-primary btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown"> Actions </button> <ul class="dropdown-menu"> <li> <a class="dropdown-item" href="edit-listing.php?id=<?= $row['id'] ?>"> <i class="bi bi-pencil-square me-2"></i>Edit </a> </li> <li><hr class="dropdown-divider"></li> <li> <a class="dropdown-item text-danger" href="?id=<?= $row['id'] ?>" onclick="return confirm('Are you sure you want to delete this property?')"> <i class="bi bi-trash me-2"></i>Delete </a> </li> </ul> </div> </td> </tr> <?php endwhile; else: ?> <tr> <td colspan="8" class="text-center text-muted">No properties found.</td> </tr> <?php endif; $conn->close(); ?> </tbody> </table> </div> </div> </div> </main> </div> </div> <?php include 'footer.php'; ?> </body> </html>