Spaces:
Configuration error
Configuration error
File size: 14,948 Bytes
8df07b6 | 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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | ```php
<?php
include 'includes/auth.php';
include 'config/database.php';
$db = new Database();
$connection = $db->getConnection();
// Handle search and filters
$search = $_GET['search'] ?? '';
$category = $_GET['category'] ?? '';
$status = $_GET['status'] ?? 'available';
// Build query with filters
$query = "SELECT i.*, r.locationFound, r.timestamp as foundDate, sl.name as storageName
FROM items i
LEFT JOIN reports r ON i.reportID = r.reportID
LEFT JOIN storage_locations sl ON i.storageLocationID = sl.locationID
WHERE 1=1";
$params = [];
if ($search) {
$query .= " AND (i.description LIKE :search OR i.category LIKE :search)";
$params[':search'] = "%$search%";
}
if ($category) {
$query .= " AND i.category = :category";
$params[':category'] = $category;
}
if ($status) {
$query .= " AND i.status = :status";
$params[':status'] = $status;
}
$query .= " ORDER BY i.createdAt DESC";
$stmt = $connection->prepare($query);
foreach ($params as $key => $value) {
$stmt->bindValue($key, $value);
}
$stmt->execute();
$items = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Get categories for filter
$categoriesQuery = "SELECT DISTINCT category FROM items WHERE category IS NOT NULL";
$categoriesStmt = $connection->prepare($categoriesQuery);
$categoriesStmt->execute();
$categories = $categoriesStmt->fetchAll(PDO::FETCH_COLUMN);
// Handle claim submission
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['claim_item'])) {
if (!isLoggedIn() || !isOwner()) {
header("Location: login.php");
exit();
}
$itemID = $_POST['itemID'];
$userId = $_SESSION['user_id'];
// Check if item exists and is available
$checkQuery = "SELECT * FROM items WHERE itemID = :itemID AND status = 'available'";
$checkStmt = $connection->prepare($checkQuery);
$checkStmt->bindParam(':itemID', $itemID);
$checkStmt->execute();
if ($checkStmt->rowCount() > 0) {
// Handle proof upload
$proofPath = null;
if (isset($_FILES['proof']) && $_FILES['proof']['error'] === UPLOAD_ERR_OK) {
$uploadDir = 'uploads/proofs/';
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0755, true);
}
$fileExtension = pathinfo($_FILES['proof']['name'], PATHINFO_EXTENSION);
$fileName = uniqid() . '.' . $fileExtension;
$targetPath = $uploadDir . $fileName;
if (move_uploaded_file($_FILES['proof']['tmp_name'], $targetPath)) {
$proofPath = $targetPath;
}
}
// Create claim
$claimQuery = "INSERT INTO claims (itemID, ownerUserId, proofPath) VALUES (:itemID, :userId, :proofPath)";
$claimStmt = $connection->prepare($claimQuery);
$claimStmt->bindParam(':itemID', $itemID);
$claimStmt->bindParam(':userId', $userId);
$claimStmt->bindParam(':proofPath', $proofPath);
if ($claimStmt->execute()) {
// Update item status
$updateQuery = "UPDATE items SET status = 'claimed' WHERE itemID = :itemID";
$updateStmt = $connection->prepare($updateQuery);
$updateStmt->bindParam(':itemID', $itemID);
$updateStmt->execute();
$success = "Claim submitted successfully! We'll review your claim and contact you soon.";
}
} else {
$error = "Item not available for claiming.";
}
}
// Get specific item details if requested
$itemDetail = null;
if (isset($_GET['item'])) {
$itemQuery = "SELECT i.*, r.*, sl.name as storageName, sl.address as storageAddress
FROM items i
LEFT JOIN reports r ON i.reportID = r.reportID
LEFT JOIN storage_locations sl ON i.storageLocationID = sl.locationID
WHERE i.itemID = :itemID";
$itemStmt = $connection->prepare($itemQuery);
$itemStmt->bindParam(':itemID', $_GET['item']);
$itemStmt->execute();
$itemDetail = $itemStmt->fetch(PDO::FETCH_ASSOC);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Browse Items - Lost & Found</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<div class="container">
<nav>
<div class="logo">Lost & Found Pro</div>
<ul class="nav-links">
<li><a href="home.php">Home</a></li>
<li><a href="items.php">Browse Items</a></li>
<?php if (isLoggedIn()): ?>
<li><a href="dashboard.php">Dashboard</a></li>
<?php if (isFinder()): ?>
<li><a href="report_item.php">Report Item</a></li>
<?php endif; ?>
<li><a href="notifications.php">Notifications</a></li>
<li><a href="profile.php">Profile</a></li>
<li><a href="logout.php">Logout</a></li>
<?php else: ?>
<li><a href="login.php">Login</a></li>
<li><a href="register.php">Register</a></li>
<?php endif; ?>
</ul>
</nav>
</div>
</header>
<main class="container">
<?php if ($itemDetail): ?>
<!-- Item Detail View -->
<div class="card">
<a href="items.php" class="btn btn-secondary mb-3">← Back to Browse</a>
<div class="row">
<div class="col-6">
<?php if ($itemDetail['imagePath']): ?>
<img src="<?php echo $itemDetail['imagePath']; ?>" alt="<?php echo $itemDetail['description']; ?>"
style="width: 100%; max-height: 400px; object-fit: cover; border-radius: 10px;">
<?php else: ?>
<div style="width: 100%; height: 400px; background: #e9ecef; display: flex; align-items: center; justify-content: center; border-radius: 10px;">
<span>No Image Available</span>
</div>
<?php endif; ?>
</div>
<div class="col-6">
<h2><?php echo $itemDetail['category']; ?></h2>
<p><strong>Description:</strong> <?php echo $itemDetail['description']; ?></p>
<p><strong>Found Location:</strong> <?php echo $itemDetail['locationFound']; ?></p>
<p><strong>Found Date:</strong> <?php echo date('M j, Y', strtotime($itemDetail['foundDate'])); ?></p>
<p><strong>Status:</strong>
<span class="badge badge-<?php
switch($itemDetail['status']) {
case 'available': echo 'success'; break;
case 'claimed': echo 'warning'; break;
case 'returned': echo 'info'; break;
default: echo 'secondary';
}
?>">
<?php echo ucfirst($itemDetail['status']); ?>
</span>
</p>
<?php if ($itemDetail['storageName']): ?>
<p><strong>Storage Location:</strong> <?php echo $itemDetail['storageName']; ?></p>
<p><strong>Storage Address:</strong> <?php echo $itemDetail['storageAddress']; ?></p>
<?php endif; ?>
<?php if (isOwner() && $itemDetail['status'] == 'available'): ?>
<div class="mt-4">
<h4>Claim This Item</h4>
<form method="POST" enctype="multipart/form-data">
<input type="hidden" name="itemID" value="<?php echo $itemDetail['itemID']; ?>">
<div class="form-group">
<label for="proof">Upload Proof of Ownership (Optional)</label>
<input type="file" id="proof" name="proof" class="form-control" accept="image/*,.pdf">
<small>Photos, receipts, or documents that prove this item belongs to you</small>
</div>
<button type="submit" name="claim_item" class="btn btn-primary">Submit Claim</button>
</form>
</div>
<?php elseif (!isLoggedIn() && $itemDetail['status'] == 'available'): ?>
<div class="mt-4">
<p>You need to <a href="login.php">login</a> as an owner to claim this item.</p>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php else: ?>
<!-- Browse Items View -->
<div class="card">
<div class="card-header">
<h2>Browse Found Items</h2>
</div>
<?php if (isset($success)): ?>
<div style="background: #D1FAE5; color: #065F46; padding: 1rem; border-radius: 5px; margin-bottom: 1rem;">
<?php echo $success; ?>
</div>
<?php endif; ?>
<?php if (isset($error)): ?>
<div style="background: #FEE2E2; color: #DC2626; padding: 1rem; border-radius: 5px; margin-bottom: 1rem;">
<?php echo $error; ?>
</div>
<?php endif; ?>
<!-- Search and Filters -->
<form method="GET" class="row">
<div class="col-4">
<div class="form-group">
<input type="text" name="search" class="form-control" placeholder="Search items..." value="<?php echo htmlspecialchars($search); ?>">
</div>
</div>
<div class="col-3">
<div class="form-group">
<select name="category" class="form-control">
<option value="">All Categories</option>
<?php foreach ($categories as $cat): ?>
<option value="<?php echo $cat; ?>" <?php echo $category == $cat ? 'selected' : ''; ?>>
<?php echo $cat; ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="col-3">
<div class="form-group">
<select name="status" class="form-control">
<option value="available" <?php echo $status == 'available' ? 'selected' : ''; ?>>Available</option>
<option value="claimed" <?php echo $status == 'claimed' ? 'selected' : ''; ?>>Claimed</option>
<option value="returned" <?php echo $status == 'returned' ? 'selected' : ''; ?>>Returned</option>
</select>
</div>
</div>
<div class="col-2">
<button type="submit" class="btn btn-primary w-full">Filter</button>
</div>
</form>
<!-- Items Grid -->
<div class="row mt-3">
<?php foreach ($items as $item): ?>
<div class="col-4">
<div class="card">
<?php if ($item['imagePath']): ?>
<img src="<?php echo $item['imagePath']; ?>" alt="<?php echo $item['description']; ?>"
style="width: 100%; height: 200px; object-fit: cover; border-radius: 5px;">
<?php else: ?>
<div style="width: 100%; height: 200px; background: #e9ecef; display: flex; align-items: center; justify-content: center; border-radius: 5px;">
<span>No Image</span>
</div>
<?php endif; ?>
<h4 class="mt-2"><?php echo $item['category']; ?></h4>
<p><?php echo substr($item['description'], 0, 100); ?>...</p>
<p><small>Found: <?php echo date('M j, Y', strtotime($item['foundDate'])); ?></small></p>
<p>
<span class="badge badge-<?php
switch($item['status']) {
case 'available': echo 'success'; break;
case 'claimed': echo 'warning'; break;
case 'returned': echo 'info'; break;
default: echo 'secondary';
}
?>">
<?php echo ucfirst($item['status']); ?>
</span>
</p>
<a href="items.php?item=<?php echo $item['itemID']; ?>" class="btn btn-primary btn-sm w-full">View Details</a>
</div>
</div>
<?php endforeach; ?>
</div>
<?php if (empty($items)): ?>
<div class="text-center p-4">
<p>No items found matching your criteria.</p>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</main>
<footer>
<div class="container">
<div class="footer-content">
<div class="logo">Lost & Found Pro</div>
<p>© 2024 Lost & Found Management System. All rights reserved.</p>
</div>
</div>
</footer>
</body>
</html>
``` |