-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpending-form.php
More file actions
303 lines (265 loc) · 9.35 KB
/
pending-form.php
File metadata and controls
303 lines (265 loc) · 9.35 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
<?php
session_start();
require_once 'inc/dbh.inc.php';
if (!isset($_SESSION['HospitalID'])) {
header('Location: login.php');
exit();
}
if (isset($_GET['logout'])) {
session_unset();
session_destroy();
header('Location: index.php');
exit();
}
$formid = $_GET['FormID'] ?? '';
$st = $_GET['status'] ?? '';
$hospitalID = (int) $_SESSION['HospitalID'];
$stmt = $conn->prepare("SELECT name, Logo FROM hospitals WHERE id = ?");
$stmt->bind_param('i', $hospitalID);
$stmt->execute();
$res = $stmt->get_result();
$row = $res->fetch_assoc();
$hospital_name = $row['name'];
if (!empty($row['Logo'])) {
$logo = base64_encode($row['Logo']);
$img_src = 'data:image/jpeg;base64,' . $logo;
} else {
$img_src = './src/img/hospital-logo.png';
}
$stmt->close();
// ============================================================================
// PAGINATION AND SEARCH FOR ENCRYPTED TABLE
// ============================================================================
$limit = 10;
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int) $_GET['page'] : 1;
$offset = ($page - 1) * $limit;
$search = isset($_GET['search']) ? trim($_GET['search']) : '';
// Build query for encrypted table
// Note: Can only search by FormID since other data is encrypted
// Email search requires hash lookup (mother_email_hash or informant_email_hash)
if ($search !== '') {
// Search by FormID only (can't search encrypted data without decrypting)
$where = "WHERE FormID LIKE ?"
. " AND (status = 'under review' OR status = 'created')"
. " AND hospital_id = ?";
$like = "%{$search}%";
$params = [&$like, &$hospitalID];
$types = 'si';
} else {
$where = "WHERE (status = 'under review' OR status = 'created')"
. " AND hospital_id = ?";
$params = [&$hospitalID];
$types = 'i';
}
// Count total records
$countSql = "SELECT COUNT(*) AS total FROM form_data_secure $where";
$countStmt = $conn->prepare($countSql);
if (!$countStmt) {
die('Count prepare failed: ' . $conn->error);
}
call_user_func_array([
$countStmt,
'bind_param'
], array_merge([$types], $params));
$countStmt->execute();
$total_records = $countStmt->get_result()->fetch_assoc()['total'];
$countStmt->close();
$total_pages = ceil($total_records / $limit);
// Fetch page of results
$dataSql = "SELECT FormID, submitted_date, status"
. " FROM form_data_secure"
. " $where"
. " ORDER BY submitted_date DESC"
. " LIMIT ? OFFSET ?";
$dataStmt = $conn->prepare($dataSql);
if (!$dataStmt) {
die('Data prepare failed: ' . $conn->error);
}
// Add LIMIT and OFFSET to parameters
$dataTypes = $types . 'ii';
$limitParam = $limit;
$offsetParam = $offset;
$dataParams = array_merge($params, [&$limitParam, &$offsetParam]);
call_user_func_array([
$dataStmt,
'bind_param'
], array_merge([$dataTypes], $dataParams));
$dataStmt->execute();
$result = $dataStmt->get_result();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./src/css/pending-form.css" />
<link rel="stylesheet" href="./src/css/dashboard.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<title>Pending Birth Forms</title>
<style>
.encrypted-notice {
background: #fff3cd;
border-left: 4px solid #ffc107;
padding: 10px 15px;
margin-bottom: 15px;
border-radius: 4px;
font-size: 13px;
color: #856404;
}
.encrypted-notice i {
margin-right: 8px;
}
.search-info {
font-size: 12px;
color: #666;
margin-top: 5px;
}
</style>
</head>
<body>
<?php if (isset($formid) && $st === 'approved'): ?>
<div id="popup-msg" class="popup success">
✅ Application ID <strong><?php echo htmlspecialchars($formid); ?></strong> has been <strong>Approved</strong>!
</div>
<?php elseif (isset($formid) && $st === 'rejected'): ?>
<div id="popup-msg" class="popup error">
❌ Application ID <strong><?php echo htmlspecialchars($formid); ?></strong> has been <strong>Rejected</strong>!
</div>
<?php endif; ?>
<header class="dashboard-header">
<div class="logo-title">
<?php echo "<img src='$img_src' alt='Hospital Logo' style='max-height: 40px; padding-right:10px;'>"; ?>
<?php echo "<h2> BIS - $hospital_name</h2>"; ?>
</div>
<a href="?logout=true" class="logout"><i class="fas fa-sign-out-alt"></i> Logout</a>
</header>
<nav class="breadcrumb">
<a href='index.php'><b> Dashboard </b> </a> / Pending Birth Registration Forms
</nav>
<main>
<div class="container">
<h3>Pending Birth Registration Forms</h3>
<form method="get" style="margin-bottom:1.5rem; display:flex; gap:0.5rem; flex-direction:column;">
<div style="display:flex; gap:0.5rem;">
<input type="text"
name="search"
placeholder="Search by Form ID (e.g., BT-20251013-0000001)"
value="<?php echo htmlspecialchars($search); ?>"
style="flex: 1;" />
<button type="submit" class="view-btn">
<i class="fas fa-search"></i> Search
</button>
<?php if ($search !== ''): ?>
<a href="pending-form.php" class="view-btn" style="background: #6c757d;">
<i class="fas fa-times"></i> Clear
</a>
<?php endif; ?>
</div>
</form>
<?php if ($total_records > 0): ?>
<table>
<thead>
<tr>
<th>Form ID</th>
<th>Submitted Date</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<td><strong><?php echo htmlspecialchars($row['FormID']); ?></strong></td>
<td><?php echo htmlspecialchars($row['submitted_date']); ?></td>
<td>
<?php if ($row['status'] === 'created'): ?>
<span class="badge" style="background: #d1ecf1; color: #0c5460;">Created</span>
<?php else: ?>
<span class="badge" style="background: #fff3cd; color: #856404;">Under Review</span>
<?php endif; ?>
</td>
<td class="actions">
<a href="admin-view.php?FormID=<?php echo urlencode($row['FormID']); ?>" class="view-btn">
<i class="fas fa-eye"></i> View Details
</a>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php if ($total_pages > 1): ?>
<div class="pagination">
<?php if ($page > 1): ?>
<a href="?search=<?php echo urlencode($search); ?>&page=<?php echo $page - 1; ?>">
<i class="fas fa-chevron-left"></i> Prev
</a>
<?php endif; ?>
<?php
// Smart pagination - show only relevant pages
$start_page = max(1, $page - 2);
$end_page = min($total_pages, $page + 2);
if ($start_page > 1): ?>
<a href="?search=<?php echo urlencode($search); ?>&page=1">1</a>
<?php if ($start_page > 2): ?>
<span>...</span>
<?php endif; ?>
<?php endif; ?>
<?php for ($i = $start_page; $i <= $end_page; $i++): ?>
<a href="?search=<?php echo urlencode($search); ?>&page=<?php echo $i; ?>"
<?php if ($i == $page) echo ' class="active"'; ?>>
<?php echo $i; ?>
</a>
<?php endfor; ?>
<?php if ($end_page < $total_pages): ?>
<?php if ($end_page < $total_pages - 1): ?>
<span>...</span>
<?php endif; ?>
<a href="?search=<?php echo urlencode($search); ?>&page=<?php echo $total_pages; ?>">
<?php echo $total_pages; ?>
</a>
<?php endif; ?>
<?php if ($page < $total_pages): ?>
<a href="?search=<?php echo urlencode($search); ?>&page=<?php echo $page + 1; ?>">
Next <i class="fas fa-chevron-right"></i>
</a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php else: ?>
<div style="text-align: center; padding: 40px 20px; color: #999;">
<i class="fas fa-inbox" style="font-size: 48px; margin-bottom: 15px; display: block;"></i>
<h3 style="margin: 0 0 10px 0; color: #666;">No Pending Forms</h3>
<p style="margin: 0;">
<?php if ($search !== ''): ?>
No forms found matching "<?= htmlspecialchars($search) ?>".
<a href="pending-form.php" style="color: #007bff;">Clear search</a>
<?php else: ?>
There are no pending birth registration forms at the moment.
<?php endif; ?>
</p>
</div>
<?php endif; ?>
</div>
</main>
<footer>
Register General's Department - Sri Lanka
</footer>
<script>
window.addEventListener('DOMContentLoaded', () => {
const pop = document.getElementById('popup-msg');
if (!pop) return;
// After 3s, fade out and remove
setTimeout(() => {
pop.style.opacity = '0';
pop.style.transition = 'opacity 0.5s';
// Remove from DOM after transition
setTimeout(() => pop.remove(), 500);
}, 3000);
});
</script>
</body>
</html>
<?php
$dataStmt->close();
$conn->close();
?>