Spaces:
Configuration error
Configuration error
File size: 9,502 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 | ```php
<?php
include 'includes/auth.php';
redirectIfNotLoggedIn();
if (!isFinder()) {
header("Location: dashboard.php");
exit();
}
include 'config/database.php';
$db = new Database();
$connection = $db->getConnection();
// Get storage locations for dropdown
$locationsQuery = "SELECT * FROM storage_locations";
$locationsStmt = $connection->prepare($locationsQuery);
$locationsStmt->execute();
$storageLocations = $locationsStmt->fetchAll(PDO::FETCH_ASSOC);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$userId = $_SESSION['user_id'];
$locationFound = $_POST['locationFound'] ?? '';
$notes = $_POST['notes'] ?? '';
$itemDescription = $_POST['itemDescription'] ?? '';
$category = $_POST['category'] ?? '';
$storageLocationID = $_POST['storageLocationID'] ?? null;
try {
$connection->beginTransaction();
// Insert report
$reportQuery = "INSERT INTO reports (userId, locationFound, notes) VALUES (:userId, :locationFound, :notes)";
$reportStmt = $connection->prepare($reportQuery);
$reportStmt->bindParam(':userId', $userId);
$reportStmt->bindParam(':locationFound', $locationFound);
$reportStmt->bindParam(':notes', $notes);
$reportStmt->execute();
$reportID = $connection->lastInsertId();
// Handle file upload
$imagePath = null;
if (isset($_FILES['itemImage']) && $_FILES['itemImage']['error'] === UPLOAD_ERR_OK) {
$uploadDir = 'uploads/';
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0755, true);
}
$fileExtension = pathinfo($_FILES['itemImage']['name'], PATHINFO_EXTENSION);
$fileName = uniqid() . '.' . $fileExtension;
$targetPath = $uploadDir . $fileName;
if (move_uploaded_file($_FILES['itemImage']['tmp_name'], $targetPath)) {
$imagePath = $targetPath;
}
}
// Insert item
$itemQuery = "INSERT INTO items (reportID, description, category, storageLocationID, imagePath)
VALUES (:reportID, :description, :category, :storageLocationID, :imagePath)";
$itemStmt = $connection->prepare($itemQuery);
$itemStmt->bindParam(':reportID', $reportID);
$itemStmt->bindParam(':description', $itemDescription);
$itemStmt->bindParam(':category', $category);
$itemStmt->bindParam(':storageLocationID', $storageLocationID);
$itemStmt->bindParam(':imagePath', $imagePath);
$itemStmt->execute();
$itemID = $connection->lastInsertId();
// Create verification record
$verificationQuery = "INSERT INTO verifications (reportID, itemID) VALUES (:reportID, :itemID)";
$verificationStmt = $connection->prepare($verificationQuery);
$verificationStmt->bindParam(':reportID', $reportID);
$verificationStmt->bindParam(':itemID', $itemID);
$verificationStmt->execute();
// Create notification
$notificationQuery = "INSERT INTO notifications (userId, message) VALUES (:userId, :message)";
$notificationStmt = $connection->prepare($notificationQuery);
$message = "Your report #$reportID has been submitted and is pending verification.";
$notificationStmt->bindParam(':userId', $userId);
$notificationStmt->bindParam(':message', $message);
$notificationStmt->execute();
$connection->commit();
$success = "Report submitted successfully! Your report ID is #$reportID";
} catch (Exception $e) {
$connection->rollBack();
$error = "Error submitting report: " . $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Report Found Item - 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>
<li><a href="dashboard.php">Dashboard</a></li>
<li><a href="report_item.php">Report Item</a></li>
<li><a href="notifications.php">Notifications</a></li>
<li><a href="profile.php">Profile</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</nav>
</div>
</header>
<main class="container">
<div style="max-width: 600px; margin: 2rem auto;">
<div class="card">
<div class="card-header">
<h2>Report Found Item</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; ?>
<form method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="locationFound">Where did you find this item?</label>
<input type="text" id="locationFound" name="locationFound" class="form-control" required
placeholder="e.g., Library main desk, Cafeteria table 5">
</div>
<div class="form-group">
<label for="itemDescription">Item Description</label>
<textarea id="itemDescription" name="itemDescription" class="form-control" rows="4" required
placeholder="Describe the item in detail (color, brand, size, distinctive features...)"></textarea>
</div>
<div class="form-group">
<label for="category">Category</label>
<select id="category" name="category" class="form-control" required>
<option value="">Select a category</option>
<option value="Wallet/Purse">Wallet/Purse</option>
<option value="Keys">Keys</option>
<option value="Phone">Phone</option>
<option value="Laptop/Tablet">Laptop/Tablet</option>
<option value="Jewelry">Jewelry</option>
<option value="Bag/Backpack">Bag/Backpack</option>
<option value="Clothing">Clothing</option>
<option value="Documents">Documents</option>
<option value="Books">Books</option>
<option value="Electronics">Electronics</option>
<option value="Other">Other</option>
</select>
</div>
<div class="form-group">
<label for="storageLocationID">Storage Location (if known)</label>
<select id="storageLocationID" name="storageLocationID" class="form-control">
<option value="">Select storage location</option>
<?php foreach ($storageLocations as $location): ?>
<option value="<?php echo $location['locationID']; ?>">
<?php echo $location['name']; ?> - <?php echo $location['address']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="itemImage">Upload Item Photo (Optional)</label>
<input type="file" id="itemImage" name="itemImage" class="form-control"
accept="image/*">
</div>
<div class="form-group">
<label for="notes">Additional Notes</label>
<textarea id="notes" name="notes" class="form-control" rows="3"
placeholder="Any additional information about how/when you found the item"></textarea>
</div>
<button type="submit" class="btn btn-primary w-full">Submit Report</button>
</form>
</div>
</div>
</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>
``` |