-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport_verify.php
More file actions
268 lines (236 loc) · 8.9 KB
/
report_verify.php
File metadata and controls
268 lines (236 loc) · 8.9 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
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
266
267
268
<?php
session_start();
include 'db.php';
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header("Location: splash.php");
exit;
}
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$report_id = $_GET['id'];
try {
$sql = "SELECT id, title, description, incident_picture FROM incident_reports WHERE id = :id";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':id', $report_id, PDO::PARAM_INT);
$stmt->execute();
$report = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$report) {
echo "Report not found.";
exit;
}
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
exit;
}
} else {
echo "Invalid report ID.";
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Report Verification</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/report_verify.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
<script src="js/report_verify.js" defer></script>
<link rel="icon" type="image/png" href="assets/Southside.png">
<style>
.modal-backdrop {
display: none !important;
}
.horizontal-images {
display: flex;
overflow-x: auto;
gap: 10px;
padding: 10px 0;
}
.horizontal-images img {
width: 200px;
height: 200px;
object-fit: cover;
border-radius: 8px;
cursor: pointer;
}
.zoomable-image {
transition: transform 0.3s ease;
}
.zoomable-image:hover {
transform: scale(1.05);
}
</style>
</head>
<body>
<?php
$pageTitle = "Report Verification";
include 'header.php';
include 'sidebar.php';
?>
<!-- Main content container -->
<div class="main-container" style="padding-top: 20px;">
<!-- Back Button with Font Awesome icon -->
<button class="back-btn btn-secondary" onclick="goBack()">
<i class="fas fa-arrow-left"></i> Back
</button>
<div class="form-group">
<label for="reportTitle" class="form-label">Title:</label>
<input type="text" class="form-control" id="reportTitle" value="<?php echo htmlspecialchars($report['title']); ?>" readonly>
</div>
<div class="form-group">
<label for="reportDescription" class="form-label">Description:</label>
<textarea class="form-control" id="reportDescription" readonly><?php echo htmlspecialchars($report['description']); ?></textarea>
</div>
<div class="form-group">
<label class="form-label">Images:</label>
<div class="horizontal-images">
<?php
if (!empty($report['incident_picture'])) {
// Decode the JSON string to an array
$images = json_decode($report['incident_picture'], true);
if ($images && is_array($images)) {
foreach ($images as $image) {
// Remove any unwanted whitespace
$image = trim($image);
echo '<img src="' . htmlspecialchars($image) . '" class="img-thumbnail zoomable-image" alt="Incident Image" onclick="showImageModal(this.src)">';
}
}
}
?>
</div>
</div>
<div class="d-flex justify-content-start" style="padding-top: 1rem;">
<button class="action-btn me-2" id="resolvedBtn">Resolved</button>
</div>
</div>
<!-- Image Modal -->
<div class="modal fade" id="imageModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Image Preview</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body text-center">
<img id="modalImage" src="" class="img-fluid" alt="Zoomed Image">
</div>
</div>
</div>
</div>
<!-- Confirmation Modal -->
<div class="modal fade" id="confirmModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Confirm Resolution</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Are you sure you want to mark this report as resolved?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" id="confirmResolve" class="btn btn-primary">Confirm</button>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
class ModalManager {
constructor() {
this.imageModal = new bootstrap.Modal(document.getElementById('imageModal'), {});
this.confirmModal = new bootstrap.Modal(document.getElementById('confirmModal'), {});
this.modalImage = document.getElementById('modalImage');
this.setupEventListeners();
}
setupEventListeners() {
// Image modal listeners
document.querySelectorAll('.zoomable-image').forEach(image => {
image.addEventListener('click', () => this.showImageModal(image.src));
});
// Resolve button listener
document.getElementById('resolvedBtn').addEventListener('click', () => {
this.cleanupModalState();
this.confirmModal.show();
});
// Confirm resolution button listener
document.getElementById('confirmResolve').addEventListener('click', () => this.handleReportResolution());
// Modal hidden cleanup
['imageModal', 'confirmModal'].forEach(modalId => {
document.getElementById(modalId).addEventListener('hidden.bs.modal', () => this.cleanupModalState());
});
}
showImageModal(src) {
this.modalImage.src = src;
this.cleanupModalState(); // Cleanup lingering artifacts
this.imageModal.show();
}
async handleReportResolution() {
const reportId = this.getReportId();
try {
const response = await fetch('resolve_report.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `report_id=${reportId}`
});
if (response.ok) {
this.confirmModal.hide();
alert('The report has been marked as resolved.');
window.history.back();
} else {
throw new Error(await response.text());
}
} catch (error) {
alert(`Error: ${error.message}`);
}
}
cleanupModalState() {
// Remove all backdrops
document.querySelectorAll('.modal-backdrop').forEach(backdrop => backdrop.remove());
// Ensure body classes are cleaned up
document.body.classList.remove('modal-open');
document.body.style.overflow = ''; // Reset overflow
document.body.style.paddingRight = ''; // Reset padding
}
getReportId() {
return <?php echo json_encode($report_id); ?>;
}
}
// Textarea Auto-resize Manager
class TextareaManager {
constructor(textareaId) {
this.textarea = document.getElementById(textareaId);
if (this.textarea) {
this.setupAutoResize();
}
}
setupAutoResize() {
this.adjustHeight();
this.textarea.addEventListener('input', () => this.adjustHeight());
}
adjustHeight() {
this.textarea.style.height = 'auto';
this.textarea.style.height = `${this.textarea.scrollHeight}px`;
}
}
// Navigation Functions
const navigationManager = {
goBack() {
window.history.back();
}
};
// Initialize everything when DOM is ready
document.addEventListener('DOMContentLoaded', () => {
new ModalManager();
new TextareaManager('reportDescription');
});
// Expose navigation function globally
window.goBack = navigationManager.goBack;
</script>
</body>
</html>