Spaces:
Configuration error

File size: 13,585 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
```php
<?php
include 'includes/auth.php';
redirectIfNotAdmin();
include 'config/database.php';

$db = new Database();
$connection = $db->getConnection();

// Handle verification actions
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $verificationID = $_POST['verificationID'];
    $result = $_POST['result'];
    $notes = $_POST['notes'] ?? '';
    $adminId = $_SESSION['admin_id'];
    
    try {
        $connection->beginTransaction();
        
        // Update verification
        $updateQuery = "UPDATE verifications SET result = :result, notes = :notes, adminId = :adminId, vDate = NOW() 
                       WHERE verificationID = :verificationID";
        $updateStmt = $connection->prepare($updateQuery);
        $updateStmt->bindParam(':result', $result);
        $updateStmt->bindParam(':notes', $notes);
        $updateStmt->bindParam(':adminId', $adminId);
        $updateStmt->bindParam(':verificationID', $verificationID);
        $updateStmt->execute();
        
        // Get verification details for notifications
        $detailsQuery = "SELECT v.reportID, v.itemID, r.userId, i.description 
                        FROM verifications v 
                        JOIN reports r ON v.reportID = r.reportID 
                        JOIN items i ON v.itemID = i.itemID 
                        WHERE v.verificationID = :verificationID";
        $detailsStmt = $connection->prepare($detailsQuery);
        $detailsStmt->bindParam(':verificationID', $verificationID);
        $detailsStmt->execute();
        $details = $detailsStmt->fetch(PDO::FETCH_ASSOC);
        
        // Update report status
        $reportStatus = $result == 'approved' ? 'verified' : 'rejected';
        $reportQuery = "UPDATE reports SET status = :status WHERE reportID = :reportID";
        $reportStmt = $connection->prepare($reportQuery);
        $reportStmt->bindParam(':status', $reportStatus);
        $reportStmt->bindParam(':reportID', $details['reportID']);
        $reportStmt->execute();
        
        // Update item status
        $itemStatus = $result == 'approved' ? 'available' : 'lost';
        $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
        $message = $result == 'approved' 
            ? "Your report #{$details['reportID']} for '{$details['description']}' has been approved. The item is now available for claiming."
            : "Your report #{$details['reportID']} 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();
        $success = "Verification updated successfully!";
        
    } catch (Exception $e) {
        $connection->rollBack();
        $error = "Error updating verification: " . $e->getMessage();
    }
}

// Get pending verifications
$verificationsQuery = "
    SELECT v.*, r.locationFound, r.notes as reportNotes, i.description, i.category, i.imagePath, 
           u.name as finderName, u.email as finderEmail
    FROM verifications v
    JOIN reports r ON v.reportID = r.reportID
    JOIN items i ON v.itemID = i.itemID
    JOIN users u ON r.userId = u.userId
    WHERE v.result = 'pending'
    ORDER BY v.vDate ASC
";
$verificationsStmt = $connection->prepare($verificationsQuery);
$verificationsStmt->execute();
$pendingVerifications = $verificationsStmt->fetchAll(PDO::FETCH_ASSOC);

// Get pending claims
$claimsQuery = "
    SELECT c.*, i.description, i.category, i.imagePath, u.name as ownerName, u.email as ownerEmail
    FROM claims c
    JOIN items i ON c.itemID = i.itemID
    JOIN users u ON c.ownerUserId = u.userId
    WHERE c.status = 'pending'
    ORDER BY c.createdAt ASC
";
$claimsStmt = $connection->prepare($claimsQuery);
$claimsStmt->execute();
$pendingClaims = $claimsStmt->fetchAll(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>Verifications - 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="dashboard.php">Dashboard</a></li>
                    <li><a href="admin.php">Admin</a></li>
                    <li><a href="verifications.php">Verifications</a></li>
                    <li><a href="storage.php">Storage</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 class="card">
            <div class="card-header">
                <h1>Verification Queue</h1>
                <p>Review and approve/reject pending verifications and claims</p>
            </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; ?>
            
            <!-- Pending Report Verifications -->
            <div class="mt-4">
                <h3>Pending Report Verifications (<?php echo count($pendingVerifications); ?>)</h3>
                <?php if (empty($pendingVerifications)): ?>
                    <p>No pending verifications.</p>
                <?php else: ?>
                    <?php foreach ($pendingVerifications as $verification): ?>
                        <div class="card mt-2">
                            <div class="row">
                                <div class="col-3">
                                    <?php if ($verification['imagePath']): ?>
                                        <img src="<?php echo $verification['imagePath']; ?>" alt="<?php echo $verification['description']; ?>" 
                                             style="width: 100%; height: 150px; object-fit: cover; border-radius: 5px;">
                                    <?php else: ?>
                                        <div style="width: 100%; height: 150px; background: #e9ecef; display: flex; align-items: center; justify-content: center; border-radius: 5px;">
                                            <span>No Image</span>
                                        </div>
                                    <?php endif; ?>
                                </div>
                                <div class="col-6">
                                    <h4><?php echo $verification['category']; ?></h4>
                                    <p><strong>Description:</strong> <?php echo $verification['description']; ?></p>
                                    <p><strong>Found Location:</strong> <?php echo $verification['locationFound']; ?></p>
                                    <p><strong>Reported by:</strong> <?php echo $verification['finderName']; ?> (<?php echo $verification['finderEmail']; ?>)</p>
                                    <p><strong>Report Notes:</strong> <?php echo $verification['reportNotes']; ?></p>
                                </div>
                                <div class="col-3">
                                    <form method="POST">
                                        <input type="hidden" name="verificationID" value="<?php echo $verification['verificationID']; ?>">
                                        <div class="form-group">
                                            <label>Action:</label>
                                            <select name="result" class="form-control" required>
                                                <option value="approved">Approve</option>
                                                <option value="rejected">Reject</option>
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label>Notes:</label>
                                            <textarea name="notes" class="form-control" rows="3" placeholder="Additional notes..."></textarea>
                                        </div>
                                        <button type="submit" class="btn btn-primary w-full">Submit Verification</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    <?php endforeach; ?>
                <?php endif; ?>
            </div>
            
            <!-- Pending Claims -->
            <div class="mt-4">
                <h3>Pending Claims (<?php echo count($pendingClaims); ?>)</h3>
                <?php if (empty($pendingClaims)): ?>
                    <p>No pending claims.</p>
                <?php else: ?>
                    <?php foreach ($pendingClaims as $claim): ?>
                        <div class="card mt-2">
                            <div class="row">
                                <div class="col-3">
                                    <?php if ($claim['imagePath']): ?>
                                        <img src="<?php echo $claim['imagePath']; ?>" alt="<?php echo $claim['description']; ?>" 
                                             style="width: 100%; height: 150px; object-fit: cover; border-radius: 5px;">
                                    <?php else: ?>
                                        <div style="width: 100%; height: 150px; background: #e9ecef; display: flex; align-items: center; justify-content: center; border-radius: 5px;">
                                            <span>No Image</span>
                                        </div>
                                    <?php endif; ?>
                                </div>
                                <div class="col-6">
                                    <h4><?php echo $claim['category']; ?></h4>
                                    <p><strong>Description:</strong> <?php echo $claim['description']; ?></p>
                                    <p><strong>Claimed by:</strong> <?php echo $claim['ownerName']; ?> (<?php echo $claim['ownerEmail']; ?>)</p>
                                    <?php if ($claim['proofPath']): ?>
                                        <p><strong>Proof Provided:</strong> 
                                            <a href="<?php echo $claim['proofPath']; ?>" target="_blank">View Proof</a>
                                        </p>
                                    <?php endif; ?>
                                    <p><strong>Claim Date:</strong> <?php echo date('M j, Y g:i A', strtotime($claim['createdAt'])); ?></p>
                                </div>
                                <div class="col-3">
                                    <form method="POST" action="process_claim.php">
                                        <input type="hidden" name="claimID" value="<?php echo $claim['claimId']; ?>">
                                        <div class="form-group">
                                            <label>Action:</label>
                                            <select name="status" class="form-control" required>
                                                <option value="approved">Approve Claim</option>
                                                <option value="rejected">Reject Claim</option>
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label>Notes:</label>
                                            <textarea name="notes" class="form-control" rows="3" placeholder="Reason for decision..."></textarea>
                                        </div>
                                        <button type="submit" class="btn btn-primary w-full">Process Claim</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    <?php endforeach; ?>
                <?php endif; ?>
            </div>
        </div>
    </main>

    <footer>
        <div class="container">
            <div class="footer-content">
                <div class="logo">Lost & Found Pro</div>
                <p>&copy; 2024 Lost & Found Management System. All rights reserved.</p>
            </div>
        </div>
    </footer>
</body>
</html>
```