-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstaff_acknowledge.php
More file actions
69 lines (59 loc) · 1.95 KB
/
Copy pathstaff_acknowledge.php
File metadata and controls
69 lines (59 loc) · 1.95 KB
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
<?php
// staff_acknowledge.php
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/check_session.php';
requireLogin('Staff');
header('Content-Type: application/json');
$complaintId = (int)($_POST['complaint_id'] ?? 0);
$staff_id = (int)$_SESSION['user_id'];
$staff_dept = $_SESSION['department'] ?? '';
if ($complaintId <= 0) {
echo json_encode(['error' => 'Invalid complaint id']);
exit;
}
// Start transaction
$conn->begin_transaction();
try {
// Verify complaint exists and is assignable
$stmt = $conn->prepare("
SELECT c.*, u.id as student_id
FROM complaints c
JOIN users u ON c.student_id = u.id
WHERE c.id = ? AND (c.department = ? OR c.assigned_department = ?)
AND c.acknowledged_by IS NULL
");
$stmt->bind_param('iss', $complaintId, $staff_dept, $staff_dept);
$stmt->execute();
$complaint = $stmt->get_result()->fetch_assoc();
$stmt->close();
if (!$complaint) {
throw new Exception('Complaint not found or already acknowledged');
}
// Update complaint for acknowledgment
$update = $conn->prepare("
UPDATE complaints
SET status = 'Acknowledged',
acknowledged_by = ?,
acknowledged_at = NOW(),
updated_at = NOW()
WHERE id = ?
");
$update->bind_param('ii', $staff_id, $complaintId);
$update->execute();
$update->close();
// Add notification for student
$notif = $conn->prepare("
INSERT INTO notifications (user_id, message, type)
VALUES (?, ?, 'complaint_acknowledged')
");
$msg = "Your complaint #{$complaintId} has been acknowledged by department staff.";
$notif->bind_param('is', $complaint['student_id'], $msg);
$notif->execute();
$notif->close();
// Commit transaction
$conn->commit();
echo json_encode(['success' => true]);
} catch (Exception $e) {
$conn->rollback();
echo json_encode(['error' => $e->getMessage()]);
}