Spaces:
Configuration error

lost-found-tracker-pro / process_claim.php
brucelloyd1's picture
You are a professional full-stack web developer assistant.
8df07b6 verified
Raw History Blame Contribute Delete
2.72 kB
```php
<?php
include 'includes/auth.php';
redirectIfNotAdmin();
include 'config/database.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$claimID = $_POST['claimID'];
$status = $_POST['status'];
$notes = $_POST['notes'] ?? '';
$adminId = $_SESSION['admin_id'];
$db = new Database();
$connection = $db->getConnection();
try {
$connection->beginTransaction();
// Update claim status
$updateQuery = "UPDATE claims SET status = :status WHERE claimId = :claimID";
$updateStmt = $connection->prepare($updateQuery);
$updateStmt->bindParam(':status', $status);
$updateStmt->bindParam(':claimID', $claimID);
$updateStmt->execute();
// Get claim details for notifications
$detailsQuery = "
SELECT c.*, i.description, i.itemID, u.userId, u.name as ownerName
FROM claims c
JOIN items i ON c.itemID = i.itemID
JOIN users u ON c.ownerUserId = u.userId
WHERE c.claimId = :claimID
";
$detailsStmt = $connection->prepare($detailsQuery);
$detailsStmt->bindParam(':claimID', $claimID);
$detailsStmt->execute();
$details = $detailsStmt->fetch(PDO::FETCH_ASSOC);
// Update item status based on claim result
$itemStatus = $status == 'approved' ? 'returned' : 'available';
$itemQuery = "UPDATE items SET status = :status WHERE itemID = :itemID";
$itemStmt = $connection->prepare($itemQuery);
$itemStmt->bindParam(':status', $itemStatus);
$itemStmt->bindParam(':itemID', $details['itemID']);
$itemStmt->execute();
// Create notification for owner
$message = $status == 'approved'
? "Your claim for '{$details['description']}' has been approved! The item will be returned to you."
: "Your claim for '{$details['description']}' has been rejected. Reason: $notes";
$notificationQuery = "INSERT INTO notifications (userId, message) VALUES (:userId, :message)";
$notificationStmt = $connection->prepare($notificationQuery);
$notificationStmt->bindParam(':userId', $details['userId']);
$notificationStmt->bindParam(':message', $message);
$notificationStmt->execute();
$connection->commit();
$_SESSION['success'] = "Claim processed successfully!";
} catch (Exception $e) {
$connection->rollBack();
$_SESSION['error'] = "Error processing claim: " . $e->getMessage();
}
header("Location: verifications.php");
exit();
} else {
header("Location: verifications.php");
exit();
}
?>
```