-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication-view.php
More file actions
447 lines (407 loc) · 18.7 KB
/
application-view.php
File metadata and controls
447 lines (407 loc) · 18.7 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
<?php
require_once __DIR__ . '/inc/dbh.inc.php';
require_once __DIR__ . '/inc/kms-decrypt-functions.php';
// Load .env if using dotenv
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require __DIR__ . '/vendor/autoload.php';
if (class_exists('Dotenv\Dotenv')) {
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__ . '/..');
$dotenv->safeLoad();
}
}
if (!isset($_SESSION["HospitalID"]) && !isset($_SESSION["RGD_Admin"])) {
header("Location: login.php");
exit();
}
if (isset($_GET['logout'])) {
session_unset();
session_destroy();
header('Location: index.php');
exit();
}
if (!isset($_GET['FormID'])) {
die('No form ID specified.');
}
$formid = $_GET['FormID'];
$st = $_GET['status'] ?? '';
try {
// Decrypt the form data using KMS
$data = decryptFormData($conn, $formid);
if ($data === null) {
die('No application found for this ID: ' . htmlspecialchars($formid));
}
// Extract metadata
$status = $data['_metadata']['status'] ?? 'pending';
$kms_key_id = $data['_metadata']['kms_key_id'] ?? 'N/A';
// Log successful decryption for audit
$userType = isset($_SESSION['RGD_Admin']) ? 'RGD_Admin' : 'Hospital_' . $_SESSION['HospitalID'];
error_log("[RGD View] FormID={$formid} decrypted by {$userType} at " . gmdate('Y-m-d H:i:s'));
} catch (Exception $e) {
error_log("[RGD View Error] Failed to decrypt FormID={$formid}: " . $e->getMessage());
error_log("[RGD View Error] Stack trace: " . $e->getTraceAsString());
die('Error loading form data: ' . htmlspecialchars($e->getMessage()));
}
if (isset($_GET['action'])) {
$new_status = null;
if ($_GET['action'] === 'approved') {
$new_status = 'approved';
} elseif ($_GET['action'] === 'rejected') {
$new_status = 'rejected';
}
if ($new_status) {
// Update status in encrypted table
$update = $conn->prepare("UPDATE form_data_secure SET status=? WHERE FormID=?");
$update->bind_param("ss", $new_status, $formid);
$update->execute();
$update->close();
error_log("[RGD Action] FormID={$formid} status changed to {$new_status}");
header("Location: application-view.php?FormID=" . urlencode($formid));
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Application View - RGD</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<link rel="stylesheet" href="src/css/application-view.css">
<script src="./src/js/application-view.js"></script>
</head>
<body>
<?php if ($st === 'issued'): ?>
<div id="popup-msg" class="popup success">
✅ Certificate issued and sent to the provided email address!
</div>
<?php elseif ($st === 'error'): ?>
<div id="popup-msg" class="popup error">
❌ Failed to issue the certificate. Please try again.
</div>
<?php elseif ($st === 's3error'): ?>
<div id="popup-msg" class="popup error">
❌ Server not responding. Please try again later.
</div>
<?php endif; ?>
<div id="main-blur-wrapper">
<header class="dashboard-header">
<div class="logo-title">
<img src="./src/img/rgd-logo.png" alt="RGD Logo" style="max-height: 40px; padding-right:10px;">
<h2>BIS - Registrar General's Department</h2>
</div>
<a href="?logout=true" class="logout"><i class="fas fa-sign-out-alt"></i> Logout</a>
</header>
<nav class="breadcrumb">
<a href='rgd-dashboard.php'><b> Dashboard </b> </a> /
<a href="pending-application.php">Pending Birth Forms</a> /
Application Details
</nav>
<div class="app-container">
<h2>Application Details</h2>
<!-- Application Status -->
<div class="gov-form">
<h3>Application Status</h3>
<div class="row">
<div class="label">Status:</div>
<div class="value">
<span class="status"><b><?= htmlspecialchars(ucfirst($status)) ?></b></span>
</div>
</div>
<div class="row">
<div class="label">Form ID:</div>
<div class="value"><strong><?= htmlspecialchars($data['formID'] ?? $data['FormID'] ?? $formid) ?></strong></div>
</div>
<div class="row">
<div class="label">Submitted Date:</div>
<div class="value"><?= htmlspecialchars($data['submitted_date'] ?? 'N/A') ?></div>
</div>
</div>
<!-- Children's Information -->
<div class="gov-form">
<h3>Children's Information</h3>
<div class="row">
<div class="label">Date of Birth:</div>
<div class="value"><?= htmlspecialchars($data['dob'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Place of Birth:</div>
<div class="value"><?= htmlspecialchars($data['place_of_birth'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">District:</div>
<div class="value"><?= htmlspecialchars($data['district'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Divisional Secretary Division:</div>
<div class="value"><?= htmlspecialchars($data['divisional'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Registration Division:</div>
<div class="value"><?= htmlspecialchars($data['registration'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Birth Occurred at a Hospital:</div>
<div class="value"><?= !empty($data['hospital_birth']) ? 'Yes' : 'No' ?></div>
</div>
<div class="row">
<div class="label">Multiple Birth:</div>
<div class="value"><?= ($data['multiple_birth'] ?? '') === 'yes' ? 'Yes' : 'No' ?></div>
</div>
<?php if (($data['multiple_birth'] ?? '') === 'yes'): ?>
<div class="row">
<div class="label">Number of Children:</div>
<div class="value"><?= htmlspecialchars($data['number_of_children'] ?? 'N/A') ?></div>
</div>
<?php endif; ?>
<div class="row">
<div class="label">Name on Birth Certificate:</div>
<div class="value"><?= htmlspecialchars($data['child_name'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Gender:</div>
<div class="value"><?= htmlspecialchars($data['child_gender'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Birth Weight (kg):</div>
<div class="value"><?= htmlspecialchars($data['birth_weight'] ?? 'N/A') ?></div>
</div>
</div>
<!-- Father's Information -->
<div class="gov-form">
<h3>Father's Information</h3>
<?php if (($data['father_type'] ?? '') === 'sri-lankan'): ?>
<div class="row">
<div class="label">Nationality:</div>
<div class="value">Sri Lankan</div>
</div>
<div class="row">
<div class="label">Full Name:</div>
<div class="value"><?= htmlspecialchars($data['father_name'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">NIC Number:</div>
<div class="value"><?= htmlspecialchars($data['father_nic'] ?? 'N/A') ?></div>
</div>
<?php else: ?>
<div class="row">
<div class="label">Nationality:</div>
<div class="value">Foreigner</div>
</div>
<div class="row">
<div class="label">Full Name:</div>
<div class="value"><?= htmlspecialchars($data['father_name'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Country:</div>
<div class="value"><?= htmlspecialchars($data['father_country'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Passport Number:</div>
<div class="value"><?= htmlspecialchars($data['father_passport'] ?? 'N/A') ?></div>
</div>
<?php endif; ?>
<div class="row">
<div class="label">Date of Birth:</div>
<div class="value"><?= htmlspecialchars($data['father_dob'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Ethnic Group:</div>
<div class="value"><?= htmlspecialchars($data['father_ethnicity'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Place of Birth:</div>
<div class="value"><?= htmlspecialchars($data['father_birthplace'] ?? 'N/A') ?></div>
</div>
</div>
<!-- Mother's Information -->
<div class="gov-form">
<h3>Mother's Information</h3>
<?php if (($data['mother_type'] ?? '') === 'sri-lankan'): ?>
<div class="row">
<div class="label">Nationality:</div>
<div class="value">Sri Lankan</div>
</div>
<div class="row">
<div class="label">NIC Number:</div>
<div class="value"><?= htmlspecialchars($data['mother_nic'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">District:</div>
<div class="value"><?= htmlspecialchars($data['mother_district'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Divisional Secretary Division:</div>
<div class="value"><?= htmlspecialchars($data['mother_division'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Permanent Address:</div>
<div class="value"><?= htmlspecialchars($data['mother_address'] ?? 'N/A') ?></div>
</div>
<?php else: ?>
<div class="row">
<div class="label">Nationality:</div>
<div class="value">Foreigner</div>
</div>
<div class="row">
<div class="label">Country:</div>
<div class="value"><?= htmlspecialchars($data['mother_country'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Passport Number:</div>
<div class="value"><?= htmlspecialchars($data['mother_passport_number'] ?? 'N/A') ?></div>
</div>
<?php endif; ?>
<div class="row">
<div class="label">Full Name:</div>
<div class="value"><?= htmlspecialchars($data['mother_name'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Date of Birth:</div>
<div class="value"><?= htmlspecialchars($data['mother_dob'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Ethnic Group:</div>
<div class="value"><?= htmlspecialchars($data['mother_ethnicity'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Place of Birth:</div>
<div class="value"><?= htmlspecialchars($data['mother_birthplace'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Phone Number:</div>
<div class="value"><?= htmlspecialchars($data['mother_phone'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Email Address:</div>
<div class="value"><?= htmlspecialchars($data['mother_email'] ?? 'N/A') ?></div>
</div>
<?php if (!empty($data['admission_number'])): ?>
<div class="row">
<div class="label">Hospital Admission No.:</div>
<div class="value"><?= htmlspecialchars($data['admission_number']) ?></div>
</div>
<?php endif; ?>
<?php if (!empty($data['admission_date'])): ?>
<div class="row">
<div class="label">Admission Date:</div>
<div class="value"><?= htmlspecialchars($data['admission_date']) ?></div>
</div>
<?php endif; ?>
</div>
<!-- Marriage Details -->
<div class="gov-form">
<h3>Details of the Marriage</h3>
<div class="row">
<div class="label">Married:</div>
<div class="value"><?= (($data['married'] ?? '') === 'yes') ? 'Yes' : 'No' ?></div>
</div>
<?php if (($data['married'] ?? '') === 'yes'): ?>
<div class="row">
<div class="label">Place of Marriage:</div>
<div class="value"><?= htmlspecialchars($data['marriage_place'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Date of Marriage:</div>
<div class="value"><?= htmlspecialchars($data['marriage_date'] ?? 'N/A') ?></div>
</div>
<?php endif; ?>
</div>
<!-- Informant Details -->
<div class="gov-form">
<h3>Details of the Informant</h3>
<div class="row">
<div class="label">Relationship:</div>
<div class="value"><?= htmlspecialchars($data['informant_person'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Name:</div>
<div class="value"><?= htmlspecialchars($data['informant_name'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Postal Details:</div>
<div class="value"><?= htmlspecialchars($data['informant_postal'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Contact Number:</div>
<div class="value"><?= htmlspecialchars($data['informant_phone'] ?? 'N/A') ?></div>
</div>
<div class="row">
<div class="label">Email:</div>
<div class="value"><?= htmlspecialchars($data['informant_email'] ?? 'N/A') ?></div>
</div>
</div>
<!-- Action Buttons -->
<?php if ($status !== 'issued'): ?>
<div class="bottom-action" style="text-align: center; margin: 2em 0;">
<button id="openApproveModal" class="btn approve-btn">
Issue Certificate
</button>
</div>
<?php else: ?>
<div class="bottom-action" style="text-align: center; margin: 2em 0;">
<a href="./inc/certificate.php?FormID=<?= urlencode($data['formID'] ?? $data['FormID'] ?? $formid) ?>&action=download"
class="btn download-btn">
<i class="fas fa-download"></i> Download Certificate
</a>
</div>
<?php endif; ?>
</div>
</div>
<!-- Issue Certificate Modal -->
<div id="approveModal" class="modal">
<div class="modal-content" style="text-align:center;">
<h3> Confirmation</h3>
<p>Are you sure you want to issue the birth certificate?</p>
<p style="font-size: 13px; color: #666;">
The certificate will be generated and sent to the registered email address.
</p>
<form id="approveForm" method="post" action="./inc/certificate.php" autocomplete="off">
<input type="hidden" name="FormID" value="<?= htmlspecialchars($data['formID'] ?? $data['FormID'] ?? $formid) ?>">
<!-- Loader, hidden by default -->
<div id="modal-loader" class="modal-loader" style="display: none;">
<img src="./src/img/loader.gif" alt="Loading…" />
<p>Generating certificate...</p>
</div>
<div style="margin-top:18px;">
<button type="submit" id="confirmApproveBtn" class="modal-btn approve">
<i class="fas fa-check"></i> Yes, Issue Certificate
</button>
<button type="button" id="cancelApproveBtn" class="modal-btn cancel">
<i class="fas fa-times"></i> Cancel
</button>
</div>
</form>
</div>
</div>
<footer>
Register General's Department - Sri Lanka
</footer>
<script>
// Popup message auto-hide
window.addEventListener('DOMContentLoaded', () => {
const pop = document.getElementById('popup-msg');
if (!pop) return;
setTimeout(() => {
pop.style.opacity = '0';
pop.style.transition = 'opacity 0.5s';
setTimeout(() => pop.remove(), 500);
}, 3000);
});
// Form submission loader
const approveForm = document.getElementById('approveForm');
const loader = document.getElementById('modal-loader');
const confirmBtn = document.getElementById('confirmApproveBtn');
const cancelBtn = document.getElementById('cancelApproveBtn');
if (approveForm) {
approveForm.addEventListener('submit', () => {
loader.style.display = 'flex';
confirmBtn.disabled = true;
cancelBtn.disabled = true;
});
}
</script>
</body>
</html>
<?php
$conn->close();
?>