Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b450e7e6df | ||
|
|
2c6fd9a176 | ||
|
|
adfbb6f750 | ||
|
|
02be882af7 | ||
|
|
ff24217c73 | ||
|
|
79aa26cf52 | ||
|
|
dd86cddf44 | ||
|
|
1d182fef38 |
109
add_item.php
Normal file
109
add_item.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Ensure user is logged in and is a vendor
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'vendor') {
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$vendor_id = $_SESSION['user_id'];
|
||||
$name = $description = $price_per_day = $location = "";
|
||||
$errors = [];
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$name = trim($_POST['name']);
|
||||
$description = trim($_POST['description']);
|
||||
$price_per_day = trim($_POST['price_per_day']);
|
||||
$location = trim($_POST['location']);
|
||||
|
||||
if (empty($name)) {
|
||||
$errors[] = "Item name is required.";
|
||||
}
|
||||
if (empty($price_per_day) || !is_numeric($price_per_day)) {
|
||||
$errors[] = "A valid price is required.";
|
||||
}
|
||||
if (empty($location)) {
|
||||
$errors[] = "Location is required.";
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$sql = "INSERT INTO items (vendor_id, name, description, price_per_day, location) VALUES (:vendor_id, :name, :description, :price_per_day, :location)";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([
|
||||
':vendor_id' => $vendor_id,
|
||||
':name' => $name,
|
||||
':description' => $description,
|
||||
':price_per_day' => $price_per_day,
|
||||
':location' => $location
|
||||
]);
|
||||
header("Location: dashboard.php?item_added=true");
|
||||
exit();
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Add New Item - RentEase</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php include 'header.php'; ?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Add a New Rental Item</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p><?php echo $error; ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="add_item.php" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Item Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($name); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="description" class="form-label">Description</label>
|
||||
<textarea class="form-control" id="description" name="description" rows="3"><?php echo htmlspecialchars($description); ?></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="price_per_day" class="form-label">Price per Day ($)</label>
|
||||
<input type="number" class="form-control" id="price_per_day" name="price_per_day" step="0.01" value="<?php echo htmlspecialchars($price_per_day); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="location" class="form-label">Location (e.g., City, State)</label>
|
||||
<input type="text" class="form-control" id="location" name="location" value="<?php echo htmlspecialchars($location); ?>" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Add Item</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'footer.php'; ?>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
105
assets/css/custom.css
Normal file
105
assets/css/custom.css
Normal file
@ -0,0 +1,105 @@
|
||||
/* Google Fonts */
|
||||
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&family=Lato:wght@400;700&display=swap');
|
||||
|
||||
:root {
|
||||
--primary-color: #1E90FF;
|
||||
--secondary-color: #007BFF;
|
||||
--background-color: #F8F9FA;
|
||||
--surface-color: #FFFFFF;
|
||||
--text-color: #212529;
|
||||
--border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Lato', sans-serif;
|
||||
background-color: var(--background-color);
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
|
||||
font-family: 'Poppins', sans-serif;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: var(--primary-color);
|
||||
border-color: var(--primary-color);
|
||||
border-radius: var(--border-radius);
|
||||
padding: 0.75rem 1.5rem;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background-color: var(--secondary-color);
|
||||
border-color: var(--secondary-color);
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-family: 'Poppins', sans-serif;
|
||||
font-weight: 700;
|
||||
color: var(--primary-color) !important;
|
||||
}
|
||||
|
||||
.hero {
|
||||
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
|
||||
color: white;
|
||||
padding: 8rem 0 6rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.hero h1 {
|
||||
font-size: 3.5rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
max-width: 600px;
|
||||
margin: 2rem auto 0;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
height: 3.5rem;
|
||||
border-radius: var(--border-radius);
|
||||
border: none;
|
||||
}
|
||||
|
||||
.search-button {
|
||||
height: 3.5rem;
|
||||
border-radius: var(--border-radius);
|
||||
}
|
||||
|
||||
.section {
|
||||
padding: 4rem 0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
text-align: center;
|
||||
margin-bottom: 3rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.how-it-works-icon {
|
||||
font-size: 3rem;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.card {
|
||||
border: none;
|
||||
border-radius: var(--border-radius);
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
footer {
|
||||
background-color: var(--surface-color);
|
||||
padding: 2rem 0;
|
||||
border-top: 1px solid #e9ecef;
|
||||
}
|
||||
13
assets/js/main.js
Normal file
13
assets/js/main.js
Normal file
@ -0,0 +1,13 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const searchForm = document.getElementById('locationSearchForm');
|
||||
if (searchForm) {
|
||||
searchForm.addEventListener('submit', function(event) {
|
||||
event.preventDefault();
|
||||
const locationInput = document.getElementById('locationInput');
|
||||
const location = locationInput.value.trim();
|
||||
if (location) {
|
||||
window.location.href = `listings.php?location=${encodeURIComponent(location)}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
BIN
assets/pasted-20251211-195118-48f4531d.png
Normal file
BIN
assets/pasted-20251211-195118-48f4531d.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
BIN
assets/pasted-20251211-200142-74256b9a.png
Normal file
BIN
assets/pasted-20251211-200142-74256b9a.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
BIN
assets/pasted-20251211-200358-96530f55.png
Normal file
BIN
assets/pasted-20251211-200358-96530f55.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
94
dashboard.php
Normal file
94
dashboard.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
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 vendor_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'; ?>
|
||||
14
debug_schema.php
Normal file
14
debug_schema.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->query("DESCRIBE items");
|
||||
$columns = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
echo "<pre>";
|
||||
print_r($columns);
|
||||
echo "</pre>";
|
||||
} catch (Exception $e) {
|
||||
echo "Error: " . $e->getMessage();
|
||||
}
|
||||
?>
|
||||
41
delete_item.php
Normal file
41
delete_item.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Ensure user is logged in and is a vendor
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'vendor') {
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$vendor_id = $_SESSION['user_id'];
|
||||
$item_id = $_GET['id'] ?? null;
|
||||
|
||||
$pdo = db();
|
||||
|
||||
if ($item_id) {
|
||||
try {
|
||||
// Verify ownership before deleting
|
||||
$stmt = $pdo->prepare("SELECT id FROM items WHERE id = ? AND owner_id = ?");
|
||||
$stmt->execute([$item_id, $vendor_id]);
|
||||
$item = $stmt->fetch();
|
||||
|
||||
if ($item) {
|
||||
// Item belongs to the vendor, proceed with deletion
|
||||
$stmt = $pdo->prepare("DELETE FROM items WHERE id = ? AND owner_id = ?");
|
||||
$stmt->execute([$item_id, $vendor_id]);
|
||||
|
||||
$_SESSION['success_message'] = "Item deleted successfully!";
|
||||
} else {
|
||||
$_SESSION['error_message'] = "Item not found or you don't have permission to delete it.";
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$_SESSION['error_message'] = "Database error: " . $e->getMessage();
|
||||
}
|
||||
} else {
|
||||
$_SESSION['error_message'] = "No item ID provided.";
|
||||
}
|
||||
|
||||
header("Location: my_listings.php");
|
||||
exit();
|
||||
?>
|
||||
150
edit_item.php
Normal file
150
edit_item.php
Normal file
@ -0,0 +1,150 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Ensure user is logged in and is a vendor
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'vendor') {
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$vendor_id = $_SESSION['user_id'];
|
||||
$item_id = $_GET['id'] ?? null;
|
||||
$item = null;
|
||||
$errors = [];
|
||||
$success_message = "";
|
||||
|
||||
$pdo = db();
|
||||
|
||||
// Fetch item details if ID is provided
|
||||
if ($item_id) {
|
||||
$stmt = $pdo->prepare("SELECT * FROM items WHERE id = ? AND owner_id = ?");
|
||||
$stmt->execute([$item_id, $vendor_id]);
|
||||
$item = $stmt->fetch();
|
||||
|
||||
if (!$item) {
|
||||
$errors[] = "Item not found or you don't have permission to edit it.";
|
||||
$item_id = null; // Invalidate item_id if not found or unauthorized
|
||||
}
|
||||
} else {
|
||||
$errors[] = "No item ID provided.";
|
||||
}
|
||||
|
||||
// Handle form submission for updating the item
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && $item_id) {
|
||||
$name = trim($_POST['name']);
|
||||
$description = trim($_POST['description']);
|
||||
$price_per_day = trim($_POST['price_per_day']);
|
||||
$location = trim($_POST['location']);
|
||||
$image_url = trim($_POST['image_url']);
|
||||
|
||||
if (empty($name)) {
|
||||
$errors[] = "Item name is required.";
|
||||
}
|
||||
if (empty($price_per_day) || !is_numeric($price_per_day)) {
|
||||
$errors[] = "A valid price is required.";
|
||||
}
|
||||
if (empty($location)) {
|
||||
$errors[] = "Location is required.";
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
try {
|
||||
$sql = "UPDATE items SET name = :name, description = :description, price_per_day = :price_per_day, location = :location, image_url = :image_url WHERE id = :id AND owner_id = :owner_id";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([
|
||||
':name' => $name,
|
||||
':description' => $description,
|
||||
':price_per_day' => $price_per_day,
|
||||
':location' => $location,
|
||||
':image_url' => $image_url,
|
||||
':id' => $item_id,
|
||||
':owner_id' => $vendor_id
|
||||
]);
|
||||
$success_message = "Item updated successfully!";
|
||||
// Refresh item data after update
|
||||
$stmt = $pdo->prepare("SELECT * FROM items WHERE id = ? AND owner_id = ?");
|
||||
$stmt->execute([$item_id, $vendor_id]);
|
||||
$item = $stmt->fetch();
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Edit Item - RentEase</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php include 'header.php'; ?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Edit Rental Item</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p><?php echo htmlspecialchars($error); ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($success_message)): ?>
|
||||
<div class="alert alert-success">
|
||||
<?php echo htmlspecialchars($success_message); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($item): ?>
|
||||
<form action="edit_item.php?id=<?php echo htmlspecialchars($item['id']); ?>" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Item Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($item['name']); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="description" class="form-label">Description</label>
|
||||
<textarea class="form-control" id="description" name="description" rows="3"><?php echo htmlspecialchars($item['description']); ?></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="price_per_day" class="form-label">Price per Day ($)</label>
|
||||
<input type="number" class="form-control" id="price_per_day" name="price_per_day" step="0.01" value="<?php echo htmlspecialchars($item['price_per_day']); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="location" class="form-label">Location (e.g., City, State)</label>
|
||||
<input type="text" class="form-control" id="location" name="location" value="<?php echo htmlspecialchars($item['location']); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="image_url" class="form-label">Image URL</label>
|
||||
<input type="text" class="form-control" id="image_url" name="image_url" value="<?php echo htmlspecialchars($item['image_url'] ?? ''); ?>">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Update Item</button>
|
||||
<a href="my_listings.php" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<p>Unable to load item for editing.</p>
|
||||
<a href="my_listings.php" class="btn btn-primary">Back to My Listings</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'footer.php'; ?>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
16
footer.php
Normal file
16
footer.php
Normal file
@ -0,0 +1,16 @@
|
||||
<!-- Footer -->
|
||||
<footer class="mt-auto">
|
||||
<div class="container text-center py-4">
|
||||
<p>© <?php echo date("Y"); ?> RentEase. All Rights Reserved.</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<!-- Scripts -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
<script>
|
||||
feather.replace()
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
61
header.php
Normal file
61
header.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php if (session_status() === PHP_SESSION_NONE) { session_start(); } ?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<title>RentEase - Your Neighborhood Rental Marketplace</title>
|
||||
<meta name="description" content="<?php echo htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'Rent anything, anytime, anywhere in your neighborhood.'); ?>">
|
||||
|
||||
<!-- Meta tags for social sharing -->
|
||||
<meta property="og:title" content="RentEase - Your Neighborhood Rental Marketplace">
|
||||
<meta property="og:description" content="<?php echo htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'Rent anything, anytime, anywhere in your neighborhood.'); ?>">
|
||||
<meta property="og:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
|
||||
<meta property="og:url" content="/">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
|
||||
<!-- Stylesheets -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
|
||||
<!-- Icons -->
|
||||
<script src="https://unpkg.com/feather-icons"></script>
|
||||
|
||||
</head>
|
||||
<body style="padding-top: 70px;">
|
||||
|
||||
<!-- Header -->
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm fixed-top">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="index.php">RentEase</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto align-items-center">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="listings.php">Browse</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">For Vendors</a>
|
||||
</li>
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="dashboard.php">Dashboard</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-outline-primary ms-lg-2" href="logout.php">Logout</a>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="login.php">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-outline-primary ms-lg-2" href="register.php">Sign Up</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
258
index.php
258
index.php
@ -1,150 +1,114 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
<?php include 'header.php'; ?>
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
<!-- Hero Section -->
|
||||
<header class="hero">
|
||||
<div class="container">
|
||||
<h1 class="display-3">Your Neighborhood Rental Marketplace</h1>
|
||||
<p class="lead">Rent anything, from anyone, right around the corner.</p>
|
||||
<form class="search-bar" id="locationSearchForm">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control form-control-lg search-input" id="locationInput" placeholder="Enter your city, neighborhood, or address..." required>
|
||||
<button class="btn btn-light btn-lg search-button" type="submit">
|
||||
<i data-feather="search"></i> Search
|
||||
</button>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
</header>
|
||||
|
||||
<!-- How It Works Section -->
|
||||
<section class="section">
|
||||
<div class="container">
|
||||
<h2 class="section-title">How It Works</h2>
|
||||
<div class="row text-center">
|
||||
<div class="col-md-4">
|
||||
<div class="p-4">
|
||||
<i data-feather="map-pin" class="how-it-works-icon mb-3"></i>
|
||||
<h3>1. Find Nearby</h3>
|
||||
<p class="text-muted">Enter your location to discover thousands of items available for rent in your area.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="p-4">
|
||||
<i data-feather="calendar" class="how-it-works-icon mb-3"></i>
|
||||
<h3>2. Book & Rent</h3>
|
||||
<p class="text-muted">Select your item, choose your dates, and book instantly with secure payments.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="p-4">
|
||||
<i data-feather="smile" class="how-it-works-icon mb-3"></i>
|
||||
<h3>3. Enjoy & Return</h3>
|
||||
<p class="text-muted">Use your rental for as long as you need. Returning it is just as easy.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Featured Items Section -->
|
||||
<section class="section bg-light">
|
||||
<div class="container">
|
||||
<h2 class="section-title">Featured Items</h2>
|
||||
<div class="row">
|
||||
<!-- Placeholder Item 1 -->
|
||||
<div class="col-md-6 col-lg-3 mb-4">
|
||||
<div class="card h-100">
|
||||
<img src="https://images.pexels.com/photos/276583/pexels-photo-276583.jpeg?auto=compress&cs=tinysrgb&w=600" class="card-img-top" alt="Modern Chair" style="height: 200px; object-fit: cover;">
|
||||
<div class="card-body d-flex flex-column">
|
||||
<h5 class="card-title">Modern Chair</h5>
|
||||
<p class="card-text text-muted">Furniture</p>
|
||||
<div class="mt-auto d-flex justify-content-between align-items-center">
|
||||
<strong>$10 / day</strong>
|
||||
<a href="#" class="btn btn-primary btn-sm">Rent</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Placeholder Item 2 -->
|
||||
<div class="col-md-6 col-lg-3 mb-4">
|
||||
<div class="card h-100">
|
||||
<img src="https://images.pexels.com/photos/356056/pexels-photo-356056.jpeg?auto=compress&cs=tinysrgb&w=600" class="card-img-top" alt="Laptop" style="height: 200px; object-fit: cover;">
|
||||
<div class="card-body d-flex flex-column">
|
||||
<h5 class="card-title">MacBook Pro</h5>
|
||||
<p class="card-text text-muted">Electronics</p>
|
||||
<div class="mt-auto d-flex justify-content-between align-items-center">
|
||||
<strong>$25 / day</strong>
|
||||
<a href="#" class="btn btn-primary btn-sm">Rent</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Placeholder Item 3 -->
|
||||
<div class="col-md-6 col-lg-3 mb-4">
|
||||
<div class="card h-100">
|
||||
<img src="https://images.pexels.com/photos/3932930/pexels-photo-3932930.jpeg?auto=compress&cs=tinysrgb&w=600" class="card-img-top" alt="Camping Tent" style="height: 200px; object-fit: cover;">
|
||||
<div class="card-body d-flex flex-column">
|
||||
<h5 class="card-title">Camping Tent</h5>
|
||||
<p class="card-text text-muted">Outdoors</p>
|
||||
<div class="mt-auto d-flex justify-content-between align-items-center">
|
||||
<strong>$15 / day</strong>
|
||||
<a href="#" class="btn btn-primary btn-sm">Rent</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Placeholder Item 4 -->
|
||||
<div class="col-md-6 col-lg-3 mb-4">
|
||||
<div class="card h-100">
|
||||
<img src="https://images.pexels.com/photos/164595/pexels-photo-164595.jpeg?auto=compress&cs=tinysrgb&w=600" class="card-img-top" alt="King Size Bed" style="height: 200px; object-fit: cover;">
|
||||
<div class="card-body d-flex flex-column">
|
||||
<h5 class="card-title">King Size Bed</h5>
|
||||
<p class="card-text text-muted">Furniture</p>
|
||||
<div class="mt-auto d-flex justify-content-between align-items-center">
|
||||
<strong>$30 / day</strong>
|
||||
<a href="#" class="btn btn-primary btn-sm">Rent</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<?php include 'footer.php'; ?>
|
||||
60
item_details.php
Normal file
60
item_details.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php include 'header.php'; ?>
|
||||
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
|
||||
$item = null;
|
||||
if (isset($_GET['id'])) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT * FROM items WHERE item_id = ?");
|
||||
$stmt->execute([$_GET['id']]);
|
||||
$item = $stmt->fetch();
|
||||
} catch (PDOException $e) {
|
||||
error_log("Database error fetching item: " . $e->getMessage());
|
||||
// For production, you might redirect to an error page or show a generic error
|
||||
header("Location: listings.php");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$item) {
|
||||
header("Location: listings.php");
|
||||
exit();
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
if (isset($_GET['message']) && isset($_GET['type'])) {
|
||||
$message = htmlspecialchars($_GET['message']);
|
||||
$type = htmlspecialchars($_GET['type']);
|
||||
echo '<div class="alert alert-' . $type . ' alert-dismissible fade show" role="alert">';
|
||||
echo $message;
|
||||
echo '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>';
|
||||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
<div class="container section">
|
||||
<div class="row">
|
||||
<div class="col-md-8 offset-md-2">
|
||||
<div class="card mb-4 shadow-sm">
|
||||
<img src="https://images.pexels.com/photos/276583/pexels-photo-276583.jpeg?auto=compress&cs=tinysrgb&w=800" class="card-img-top" alt="<?php echo htmlspecialchars($item['name']); ?>" style="height: 400px; object-fit: cover;">
|
||||
<div class="card-body">
|
||||
<h1 class="card-title display-4 mb-3"><?php echo htmlspecialchars($item['name']); ?></h1>
|
||||
<h5 class="card-subtitle mb-2 text-muted"><i data-feather="map-pin"></i> <?php echo htmlspecialchars($item['location']); ?></h5>
|
||||
<p class="card-text lead"><?php echo htmlspecialchars($item['description']); ?></p>
|
||||
<hr>
|
||||
<div class="d-flex justify-content-between align-items-center mt-3">
|
||||
<h3 class="price-text">$<?php echo htmlspecialchars(number_format($item['price_per_day'], 2)); ?> / day</h3>
|
||||
<form action="rent_item.php" method="POST">
|
||||
<input type="hidden" name="item_id" value="<?php echo htmlspecialchars($item['item_id']); ?>">
|
||||
<button type="submit" class="btn btn-primary btn-lg">Rent Now</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'footer.php'; ?>
|
||||
74
listings.php
Normal file
74
listings.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php include 'header.php'; ?>
|
||||
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Fetch items from the database
|
||||
try {
|
||||
$pdo = db();
|
||||
$location = $_GET['location'] ?? '';
|
||||
|
||||
if (!empty($location)) {
|
||||
$stmt = $pdo->prepare("SELECT * FROM items WHERE location LIKE ? ORDER BY created_at DESC");
|
||||
$stmt->execute(["%{$location}%"]);
|
||||
} else {
|
||||
$stmt = $pdo->query("SELECT * FROM items ORDER BY created_at DESC");
|
||||
}
|
||||
|
||||
$items = $stmt->fetchAll();
|
||||
} catch (PDOException $e) {
|
||||
// For a real app, you'd log this error and show a user-friendly message
|
||||
$items = [];
|
||||
$db_error = "Database error: " . $e->getMessage();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="container section">
|
||||
<h1 class="section-title">Listings</h1>
|
||||
|
||||
<div class="row mb-4">
|
||||
<div class="col-md-12">
|
||||
<form class="search-bar" action="listings.php" method="GET">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control form-control-lg search-input" name="location" placeholder="Filter by city, neighborhood, or address..." value="<?php echo htmlspecialchars($location); ?>">
|
||||
<button class="btn btn-light btn-lg search-button" type="submit">
|
||||
<i data-feather="search"></i> Search
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (isset($db_error)): ?>
|
||||
<div class="alert alert-danger"><?php echo $db_error; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row">
|
||||
<?php if (empty($items)): ?>
|
||||
<div class="col">
|
||||
<div class="alert alert-info">No items found.<?php if (!empty($location)) { echo ' for "' . htmlspecialchars($location) . '"'; } ?>. Try a different search or check back later!</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<?php foreach ($items as $item): ?>
|
||||
<div class="col-md-6 col-lg-4 mb-4">
|
||||
<div class="card h-100">
|
||||
<img src="https://images.pexels.com/photos/276583/pexels-photo-276583.jpeg?auto=compress&cs=tinysrgb&w=600" class="card-img-top" alt="<?php echo htmlspecialchars($item['name']); ?>" style="height: 200px; object-fit: cover;">
|
||||
<div class="card-body d-flex flex-column">
|
||||
<h5 class="card-title"><?php echo htmlspecialchars($item['name']); ?></h5>
|
||||
<p class="card-text text-muted"><?php echo htmlspecialchars($item['location']); ?></p>
|
||||
<p class="card-text"><?php echo htmlspecialchars(substr($item['description'], 0, 100)); ?>...</p>
|
||||
<div class="mt-auto d-flex justify-content-between align-items-center">
|
||||
<strong>$<?php echo htmlspecialchars(number_format($item['price_per_day'], 2)); ?> / day</strong>
|
||||
<a href="item_details.php?id=<?php echo htmlspecialchars($item['item_id']); ?>" class="btn btn-primary btn-sm">Rent Now</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<?php include 'footer.php'; ?>
|
||||
91
login.php
Normal file
91
login.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// If user is already logged in, redirect to dashboard
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
header("Location: dashboard.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
$email = '';
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$email = trim($_POST['email']);
|
||||
$password = $_POST['password'];
|
||||
|
||||
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors[] = 'A valid email is required';
|
||||
}
|
||||
|
||||
if (empty($password)) {
|
||||
$errors[] = 'Password is required';
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
$stmt = db()->prepare("SELECT * FROM users WHERE email = ?");
|
||||
$stmt->execute([$email]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
// Regenerate session ID
|
||||
session_regenerate_id(true);
|
||||
|
||||
// Set session variables
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['user_name'] = $user['name'];
|
||||
$_SESSION['user_role'] = $user['role'];
|
||||
|
||||
// Redirect to dashboard
|
||||
header("Location: dashboard.php");
|
||||
exit;
|
||||
} else {
|
||||
$errors[] = "Invalid email or password.";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php include 'header.php'; ?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4>Login to your Account</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (isset($_GET['registered'])): ?>
|
||||
<div class="alert alert-success">
|
||||
Registration successful! Please login.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p><?php echo $error; ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="login.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email Address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($email); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
Don't have an account? <a href="register.php">Sign up here</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'footer.php'; ?>
|
||||
20
logout.php
Normal file
20
logout.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// Unset all of the session variables
|
||||
$_SESSION = array();
|
||||
|
||||
// Destroy the session.
|
||||
if (ini_get("session.use_cookies")) {
|
||||
$params = session_get_cookie_params();
|
||||
setcookie(session_name(), '', time() - 42000,
|
||||
$params["path"], $params["domain"],
|
||||
$params["secure"], $params["httponly"]
|
||||
);
|
||||
}
|
||||
|
||||
session_destroy();
|
||||
|
||||
// Redirect to login page
|
||||
header("Location: login.php?logged_out=true");
|
||||
exit;
|
||||
308
my_listings.php
Normal file
308
my_listings.php
Normal file
@ -0,0 +1,308 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
require_once 'db/config.php'; // Include the database configuration
|
||||
|
||||
// Handle CSV download
|
||||
if (isset($_GET['download_csv'])) {
|
||||
$user_id = $_SESSION['user_id'];
|
||||
$pdo = db();
|
||||
|
||||
$query = "SELECT name, description, price, location, status, creation_date FROM items WHERE vendor_id = ?";
|
||||
$query_params = [$user_id];
|
||||
|
||||
if (isset($_GET['search']) && !empty($_GET['search'])) {
|
||||
$searchTerm = '%' . $_GET['search'] . '%';
|
||||
$query .= " AND (name LIKE ? OR description LIKE ?)";
|
||||
$query_params[] = $searchTerm;
|
||||
$query_params[] = $searchTerm;
|
||||
}
|
||||
|
||||
if (isset($_GET['status']) && !empty($_GET['status'])) {
|
||||
$statusFilter = $_GET['status'];
|
||||
$query .= " AND status = ?";
|
||||
$query_params[] = $statusFilter;
|
||||
}
|
||||
|
||||
$orderBy = " ORDER BY creation_date DESC"; // Default sort
|
||||
|
||||
if (isset($_GET['sort']) && !empty($_GET['sort'])) {
|
||||
switch ($_GET['sort']) {
|
||||
case 'name_asc':
|
||||
$orderBy = " ORDER BY name ASC";
|
||||
break;
|
||||
case 'name_desc':
|
||||
$orderBy = " ORDER BY name DESC";
|
||||
break;
|
||||
case 'price_asc':
|
||||
$orderBy = " ORDER BY price ASC";
|
||||
break;
|
||||
case 'price_desc':
|
||||
$orderBy = " ORDER BY price DESC";
|
||||
break;
|
||||
case 'date_asc':
|
||||
$orderBy = " ORDER BY creation_date ASC";
|
||||
break;
|
||||
case 'date_desc':
|
||||
$orderBy = " ORDER BY creation_date DESC";
|
||||
break;
|
||||
}
|
||||
}
|
||||
$query .= $orderBy;
|
||||
|
||||
$stmt = $pdo->prepare($query);
|
||||
$stmt->execute($query_params);
|
||||
$items_to_export = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="my_listings.csv"');
|
||||
|
||||
$output = fopen('php://output', 'w');
|
||||
if (!empty($items_to_export)) {
|
||||
fputcsv($output, array_keys($items_to_export[0])); // CSV Header
|
||||
foreach ($items_to_export as $row) {
|
||||
fputcsv($output, $row);
|
||||
}
|
||||
}
|
||||
fclose($output);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Pagination constants
|
||||
$items_per_page = isset($_GET['items_per_page']) ? (int)$_GET['items_per_page'] : 6;
|
||||
// Validate $items_per_page to be a positive integer, e.g., 6, 12, 24, 48
|
||||
if (!in_array($items_per_page, [6, 12, 24, 48])) {
|
||||
$items_per_page = 6; // Default to 6 if invalid value is provided
|
||||
}
|
||||
|
||||
// Pagination constants
|
||||
// const ITEMS_PER_PAGE = 6;
|
||||
|
||||
// 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
|
||||
$total_items_query = "SELECT COUNT(*) FROM items WHERE vendor_id = ?";
|
||||
$total_items_params = [$user_id];
|
||||
|
||||
if (isset($_GET['search']) && !empty($_GET['search'])) {
|
||||
$searchTerm = '%' . $_GET['search'] . '%';
|
||||
$total_items_query .= " AND (name LIKE ? OR description LIKE ?)";
|
||||
$total_items_params[] = $searchTerm;
|
||||
$total_items_params[] = $searchTerm;
|
||||
}
|
||||
|
||||
if (isset($_GET['status']) && !empty($_GET['status'])) {
|
||||
$statusFilter = $_GET['status'];
|
||||
$total_items_query .= " AND status = ?";
|
||||
$total_items_params[] = $statusFilter;
|
||||
}
|
||||
|
||||
$total_stmt = $pdo->prepare($total_items_query);
|
||||
$total_stmt->execute($total_items_params);
|
||||
$total_items = $total_stmt->fetchColumn();
|
||||
|
||||
$total_pages = ceil($total_items / $items_per_page);
|
||||
|
||||
$current_page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
|
||||
$current_page = max(1, min($current_page, $total_pages == 0 ? 1 : $total_pages)); // Ensure current page is within valid range
|
||||
$offset = ($current_page - 1) * $items_per_page;
|
||||
|
||||
// Fetch items listed by the current vendor
|
||||
$query = "SELECT * FROM items WHERE vendor_id = ?";
|
||||
$query_params = [$user_id];
|
||||
|
||||
if (isset($_GET['search']) && !empty($_GET['search'])) {
|
||||
$searchTerm = '%' . $_GET['search'] . '%';
|
||||
$query .= " AND (name LIKE ? OR description LIKE ?)";
|
||||
$query_params[] = $searchTerm;
|
||||
$query_params[] = $searchTerm;
|
||||
}
|
||||
|
||||
if (isset($_GET['status']) && !empty($_GET['status'])) {
|
||||
$statusFilter = $_GET['status'];
|
||||
$query .= " AND status = ?";
|
||||
$query_params[] = $statusFilter;
|
||||
}
|
||||
|
||||
$orderBy = " ORDER BY creation_date DESC"; // Default sort
|
||||
|
||||
if (isset($_GET['sort']) && !empty($_GET['sort'])) {
|
||||
switch ($_GET['sort']) {
|
||||
case 'name_asc':
|
||||
$orderBy = " ORDER BY name ASC";
|
||||
break;
|
||||
case 'name_desc':
|
||||
$orderBy = " ORDER BY name DESC";
|
||||
break;
|
||||
case 'price_asc':
|
||||
$orderBy = " ORDER BY price ASC";
|
||||
break;
|
||||
case 'price_desc':
|
||||
$orderBy = " ORDER BY price DESC";
|
||||
break;
|
||||
case 'date_asc':
|
||||
$orderBy = " ORDER BY creation_date ASC";
|
||||
break;
|
||||
case 'date_desc':
|
||||
$orderBy = " ORDER BY creation_date DESC";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$query .= $orderBy;
|
||||
$query .= " LIMIT ? OFFSET ?";
|
||||
$query_params[] = $items_per_page;
|
||||
$query_params[] = $offset;
|
||||
|
||||
$stmt = $pdo->prepare($query);
|
||||
$stmt->execute($query_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>
|
||||
<select class="form-select" name="sort">
|
||||
<option value="" <?php echo (!isset($_GET['sort']) || $_GET['sort'] === '') ? 'selected' : ''; ?>>Sort By</option>
|
||||
<option value="name_asc" <?php echo (isset($_GET['sort']) && $_GET['sort'] === 'name_asc') ? 'selected' : ''; ?>>Name (A-Z)</option>
|
||||
<option value="name_desc" <?php echo (isset($_GET['sort']) && $_GET['sort'] === 'name_desc') ? 'selected' : ''; ?>>Name (Z-A)</option>
|
||||
<option value="price_asc" <?php echo (isset($_GET['sort']) && $_GET['sort'] === 'price_asc') ? 'selected' : ''; ?>>Price (Low to High)</option>
|
||||
<option value="price_desc" <?php echo (isset($_GET['sort']) && $_GET['sort'] === 'price_desc') ? 'selected' : ''; ?>>Price (High to Low)</option>
|
||||
<option value="date_desc" <?php echo (isset($_GET['sort']) && $_GET['sort'] === 'date_desc') ? 'selected' : ''; ?>>Date Added (Newest)</option>
|
||||
<option value="date_asc" <?php echo (isset($_GET['sort']) && $_GET['sort'] === 'date_asc') ? 'selected' : ''; ?>>Date Added (Oldest)</option>
|
||||
</select>
|
||||
<select class="form-select" name="items_per_page">
|
||||
<option value="6" <?php echo ((isset($_GET['items_per_page']) && $_GET['items_per_page'] == 6) || !isset($_GET['items_per_page'])) ? 'selected' : ''; ?>>6 per page</option>
|
||||
<option value="12" <?php echo (isset($_GET['items_per_page']) && $_GET['items_per_page'] == 12) ? 'selected' : ''; ?>>12 per page</option>
|
||||
<option value="24" <?php echo (isset($_GET['items_per_page']) && $_GET['items_per_page'] == 24) ? 'selected' : ''; ?>>24 per page</option>
|
||||
<option value="48" <?php echo (isset($_GET['items_per_page']) && $_GET['items_per_page'] == 48) ? 'selected' : ''; ?>>48 per page</option>
|
||||
</select>
|
||||
<button class="btn btn-outline-secondary" type="submit">Filter</button>
|
||||
<a href="my_listings.php" class="btn btn-outline-danger">Clear Filters</a>
|
||||
<button class="btn btn-outline-success" type="submit" name="download_csv">Download CSV</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php
|
||||
$activeFilters = [];
|
||||
if (!empty($_GET['search'])) {
|
||||
$activeFilters[] = 'Search: <strong>' . htmlspecialchars($_GET['search']) . '</strong>';
|
||||
}
|
||||
if (!empty($_GET['status'])) {
|
||||
$statusText = [
|
||||
'available' => 'Available',
|
||||
'rented' => 'Rented',
|
||||
'unavailable' => 'Unavailable'
|
||||
][$_GET['status']] ?? ucfirst($_GET['status']);
|
||||
$activeFilters[] = 'Status: <strong>' . htmlspecialchars($statusText) . '</strong>';
|
||||
}
|
||||
if (!empty($_GET['sort'])) {
|
||||
$sortText = [
|
||||
'name_asc' => 'Name (A-Z)',
|
||||
'name_desc' => 'Name (Z-A)',
|
||||
'price_asc' => 'Price (Low to High)',
|
||||
'price_desc' => 'Price (High to Low)',
|
||||
'date_desc' => 'Date Added (Newest)',
|
||||
'date_asc' => 'Date Added (Oldest)'
|
||||
][$_GET['sort']] ?? '';
|
||||
if (!empty($sortText)) {
|
||||
$activeFilters[] = 'Sort By: <strong>' . htmlspecialchars($sortText) . '</strong>';
|
||||
}
|
||||
}
|
||||
if (!empty($_GET['items_per_page']) && (int)$_GET['items_per_page'] !== 6) { // Assume 6 is default
|
||||
$activeFilters[] = 'Items per page: <strong>' . htmlspecialchars($_GET['items_per_page']) . '</strong>';
|
||||
}
|
||||
|
||||
if (!empty($activeFilters)):
|
||||
?>
|
||||
<div class="alert alert-info mb-4" role="alert">
|
||||
<strong>Active Filters:</strong> <?php echo implode(' | ', $activeFilters); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?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 if ($total_pages > 1): ?>
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination justify-content-center">
|
||||
<li class="page-item <?php echo ($current_page <= 1) ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="?<?php echo http_build_query(array_merge($_GET, ['page' => $current_page - 1])); ?>" tabindex="-1" aria-disabled="true">Previous</a>
|
||||
</li>
|
||||
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
|
||||
<li class="page-item <?php echo ($current_page == $i) ? 'active' : ''; ?>"><a class="page-link" href="?<?php echo http_build_query(array_merge($_GET, ['page' => $i])); ?>"><?php echo $i; ?></a></li>
|
||||
<?php endfor; ?>
|
||||
<li class="page-item <?php echo ($current_page >= $total_pages) ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="?<?php echo http_build_query(array_merge($_GET, ['page' => $current_page + 1])); ?>">Next</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'footer.php'; ?>
|
||||
102
register.php
Normal file
102
register.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
$errors = [];
|
||||
$name = '';
|
||||
$email = '';
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$name = trim($_POST['name']);
|
||||
$email = trim($_POST['email']);
|
||||
$password = $_POST['password'];
|
||||
$password_confirm = $_POST['password_confirm'];
|
||||
|
||||
if (empty($name)) {
|
||||
$errors[] = 'Name is required';
|
||||
}
|
||||
|
||||
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors[] = 'A valid email is required';
|
||||
} else {
|
||||
$stmt = db()->prepare("SELECT id FROM users WHERE email = ?");
|
||||
$stmt->execute([$email]);
|
||||
if ($stmt->fetch()) {
|
||||
$errors[] = 'Email already in use';
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($password)) {
|
||||
$errors[] = 'Password is required';
|
||||
}
|
||||
|
||||
if ($password !== $password_confirm) {
|
||||
$errors[] = 'Passwords do not match';
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
$role = isset($_POST['is_vendor']) && $_POST['is_vendor'] == '1' ? 'vendor' : 'user';
|
||||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$stmt = db()->prepare("INSERT INTO users (name, email, password, role) VALUES (?, ?, ?, ?)");
|
||||
if ($stmt->execute([$name, $email, $hashed_password, $role])) {
|
||||
// Redirect to login page
|
||||
header("Location: login.php?registered=true");
|
||||
exit;
|
||||
} else {
|
||||
$errors[] = "Failed to create account. Please try again.";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php include 'header.php'; ?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4>Create an Account</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p><?php echo $error; ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="register.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Full Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($name); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email Address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($email); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password_confirm" class="form-label">Confirm Password</label>
|
||||
<input type="password" class="form-control" id="password_confirm" name="password_confirm" required>
|
||||
</div>
|
||||
<div class="form-check mb-3">
|
||||
<input class="form-check-input" type="checkbox" value="1" id="is_vendor" name="is_vendor">
|
||||
<label class="form-check-label" for="is_vendor">
|
||||
I want to be a vendor
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Register</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
Already have an account? <a href="login.php">Login here</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'footer.php'; ?>
|
||||
56
rent_item.php
Normal file
56
rent_item.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Redirect if user is not logged in
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$message = '';
|
||||
$message_type = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (isset($_POST['item_id'])) {
|
||||
$item_id = filter_var($_POST['item_id'], FILTER_SANITIZE_NUMBER_INT);
|
||||
$user_id = $_SESSION['user_id'];
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
|
||||
// Check if item is available
|
||||
$stmt = $pdo->prepare("SELECT status FROM items WHERE item_id = ?");
|
||||
$stmt->execute([$item_id]);
|
||||
$item = $stmt->fetch();
|
||||
|
||||
if ($item && $item['status'] === 'available') {
|
||||
// Update item status to rented
|
||||
$stmt = $pdo->prepare("UPDATE items SET status = 'rented', renter_id = ?, rented_date = NOW() WHERE item_id = ?");
|
||||
$stmt->execute([$user_id, $item_id]);
|
||||
$message = 'Item rented successfully!';
|
||||
$message_type = 'success';
|
||||
} else {
|
||||
$message = 'Item is not available for rent or does not exist.';
|
||||
$message_type = 'danger';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
error_log("Database error during rental: " . $e->getMessage());
|
||||
$message = 'An error occurred during rental. Please try again.';
|
||||
$message_type = 'danger';
|
||||
}
|
||||
} else {
|
||||
$message = 'Invalid item ID.';
|
||||
$message_type = 'danger';
|
||||
}
|
||||
} else {
|
||||
header('Location: listings.php'); // Redirect if not a POST request
|
||||
exit();
|
||||
}
|
||||
|
||||
// Redirect back to item details with message
|
||||
// You might want to pass these messages via session or URL parameters
|
||||
header('Location: item_details.php?id=' . $item_id . '&message=' . urlencode($message) . '&type=' . $message_type);
|
||||
exit();
|
||||
|
||||
?>
|
||||
Loading…
x
Reference in New Issue
Block a user