93 lines
4.4 KiB
PHP
93 lines
4.4 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
require_once 'db/config.php'; // Include the database configuration
|
|
|
|
// If user is not logged in, redirect to login page
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header("Location: login.php");
|
|
exit;
|
|
}
|
|
|
|
$user_id = $_SESSION['user_id'];
|
|
$user_name = $_SESSION['user_name'];
|
|
$user_role = $_SESSION['user_role'];
|
|
|
|
$pdo = db(); // Get the PDO connection
|
|
|
|
$items = []; // Initialize an empty array to hold items
|
|
|
|
if ($user_role === 'user') {
|
|
// Fetch items rented by the user
|
|
$stmt = $pdo->prepare("SELECT * FROM items WHERE renter_id = ? AND status = 'rented'");
|
|
$stmt->execute([$user_id]);
|
|
$items = $stmt->fetchAll();
|
|
} elseif ($user_role === 'vendor') {
|
|
// Fetch items listed by the vendor
|
|
$stmt = $pdo->prepare("SELECT * FROM items WHERE owner_id = ?");
|
|
$stmt->execute([$user_id]);
|
|
$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>Welcome, <?php echo htmlspecialchars($user_name); ?>!</h4>
|
|
</div>
|
|
<div class="card-body">
|
|
<p>Welcome to your RentEase dashboard.</p>
|
|
<p>Your role is: <strong><?php echo htmlspecialchars($user_role); ?></strong></p>
|
|
<?php if ($user_role === 'vendor'): ?>
|
|
<a href="add_item.php" class="btn btn-primary mb-3 me-2">Add New Item</a>
|
|
<a href="my_listings.php" class="btn btn-info mb-3">My Listings</a>
|
|
<?php endif; ?>
|
|
|
|
<hr>
|
|
|
|
<?php if ($user_role === 'user'): ?>
|
|
<h5>Your Rented Items</h5>
|
|
<?php elseif ($user_role === 'vendor'): ?>
|
|
<h5>Your Listed Items</h5>
|
|
<?php endif; ?>
|
|
|
|
<?php if (empty($items)): ?>
|
|
<p>No items found.</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-primary">View Details</a>
|
|
<?php if ($user_role === 'user' && $item['status'] === 'rented'): ?>
|
|
<p class="text-success mt-2">Rented until: <?php echo htmlspecialchars($item['rented_date'] ? date('Y-m-d', strtotime($item['rented_date'] . ' +' . $item['rental_duration'] . ' days')) : 'N/A'); ?></p>
|
|
<?php elseif ($user_role === 'vendor'): ?>
|
|
<p class="text-info mt-2">Status: <?php echo htmlspecialchars(ucfirst($item['status'])); ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<p><a href='logout.php'>Click here to log out.</a></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'footer.php'; ?>
|