107 lines
5.6 KiB
PHP
107 lines
5.6 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
require_once 'db/config.php'; // Include the database configuration
|
|
|
|
// If user is not logged in or not a vendor, redirect
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'vendor') {
|
|
header("Location: login.php"); // Redirect to login or a suitable page
|
|
exit;
|
|
}
|
|
|
|
$user_id = $_SESSION['user_id'];
|
|
$user_name = $_SESSION['user_name'];
|
|
|
|
$pdo = db(); // Get the PDO connection
|
|
|
|
$items = []; // Initialize an empty array to hold items
|
|
|
|
// Fetch items listed by the current vendor
|
|
$query = "SELECT * FROM items WHERE owner_id = ?";
|
|
$params = [$user_id];
|
|
|
|
if (isset($_GET['search']) && !empty($_GET['search'])) {
|
|
$searchTerm = '%' . $_GET['search'] . '%';
|
|
$query .= " AND (name LIKE ? OR description LIKE ?)";
|
|
$params[] = $searchTerm;
|
|
$params[] = $searchTerm;
|
|
}
|
|
|
|
if (isset($_GET['status']) && !empty($_GET['status'])) {
|
|
$statusFilter = $_GET['status'];
|
|
$query .= " AND status = ?";
|
|
$params[] = $statusFilter;
|
|
}
|
|
|
|
$stmt = $pdo->prepare($query);
|
|
$stmt->execute($params);
|
|
$items = $stmt->fetchAll();
|
|
?>
|
|
<?php include 'header.php'; ?>
|
|
|
|
<div class="container mt-5">
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h4><?php echo htmlspecialchars($user_name); ?>'s Listings</h4>
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if (isset($_SESSION['success_message'])): ?>
|
|
<div class="alert alert-success">
|
|
<?php echo htmlspecialchars($_SESSION['success_message']); unset($_SESSION['success_message']); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if (isset($_SESSION['error_message'])): ?>
|
|
<div class="alert alert-danger">
|
|
<?php echo htmlspecialchars($_SESSION['error_message']); unset($_SESSION['error_message']); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<p>Manage your listed items here.</p>
|
|
|
|
<form action="my_listings.php" method="get" class="mb-4">
|
|
<div class="input-group">
|
|
<input type="text" class="form-control" placeholder="Search your listings..." name="search" value="<?php echo htmlspecialchars($_GET['search'] ?? ''); ?>">
|
|
<select class="form-select" name="status">
|
|
<option value="">All Statuses</option>
|
|
<option value="available" <?php echo (isset($_GET['status']) && $_GET['status'] === 'available') ? 'selected' : ''; ?>>Available</option>
|
|
<option value="rented" <?php echo (isset($_GET['status']) && $_GET['status'] === 'rented') ? 'selected' : ''; ?>>Rented</option>
|
|
<option value="unavailable" <?php echo (isset($_GET['status']) && $_GET['status'] === 'unavailable') ? 'selected' : ''; ?>>Unavailable</option>
|
|
</select>
|
|
<button class="btn btn-outline-secondary" type="submit">Filter</button>
|
|
</div>
|
|
</form>
|
|
|
|
<?php if (empty($items)): ?>
|
|
<p>You have not listed any items yet. <a href="add_item.php">Add a new item</a>.</p>
|
|
<?php else: ?>
|
|
<div class="row">
|
|
<?php foreach ($items as $item): ?>
|
|
<div class="col-md-4 mb-4">
|
|
<div class="card h-100">
|
|
<img src="<?php echo htmlspecialchars($item['image_url'] ?? 'https://via.placeholder.com/150'); ?>" class="card-img-top" alt="<?php echo htmlspecialchars($item['name']); ?>">
|
|
<div class="card-body d-flex flex-column">
|
|
<h5 class="card-title"><?php echo htmlspecialchars($item['name']); ?></h5>
|
|
<p class="card-text flex-grow-1"><?php echo htmlspecialchars($item['description']); ?></p>
|
|
<p class="card-text"><strong>Price:</strong> $<?php echo htmlspecialchars(number_format($item['price'], 2)); ?> per day</p>
|
|
<p class="card-text"><strong>Location:</strong> <?php echo htmlspecialchars($item['location']); ?></p>
|
|
<div class="mt-auto">
|
|
<a href="item_details.php?id=<?php echo htmlspecialchars($item['id']); ?>" class="btn btn-info btn-sm">View</a>
|
|
<a href="edit_item.php?id=<?php echo htmlspecialchars($item['id']); ?>" class="btn btn-warning btn-sm">Edit</a>
|
|
<a href="delete_item.php?id=<?php echo htmlspecialchars($item['id']); ?>" class="btn btn-danger btn-sm">Delete</a>
|
|
<p class="text-info mt-2">Status: <?php echo htmlspecialchars(ucfirst($item['status'])); ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'footer.php'; ?>
|