Spaces:
Configuration error
Configuration error
Download report_item.php from brucelloyd1/lost-found-tracker-pro: direct link, hf CLI and curl.
- Browser
- Download file 9.5 kB
-
https://huggingface.co/spaces/brucelloyd1/lost-found-tracker-pro/resolve/main/report_item.php
- Command line
-
hf download hf://spaces/brucelloyd1/lost-found-tracker-pro/report_item.php
-
curl -L -o report_item.php https://huggingface.co/spaces/brucelloyd1/lost-found-tracker-pro/resolve/main/report_item.php
9.5 kB
| ```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> | |
| ``` |