-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcert-view.php
More file actions
217 lines (182 loc) · 5.74 KB
/
cert-view.php
File metadata and controls
217 lines (182 loc) · 5.74 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
<?php
session_start();
if (!isset($_SESSION["HospitalID"])) {
header("Location: login.php");
exit();
}
if (isset($_GET['logout'])) {
session_unset();
session_destroy();
header("Location: index.php");
exit();
}
require_once 'inc/dbh.inc.php';
$status = $_GET['status'] ?? '';
$highlight = $_GET['id'] ?? '';
$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']) : '';
// search
$where = '';
$params = [];
$types = '';
if ($search !== '') {
$where = "WHERE FormID LIKE ? AND status = 'approved'";
$like = "%{$search}%";
$params[] = &$like;
$types .= 's';
}
//total records
$countSql = "SELECT COUNT(*) AS total FROM form_data_secure $where";
$countStmt = $conn->prepare($countSql);
if (!$countStmt) {
die('Count prepare failed: ' . $conn->error);
}
if ($search !== '') {
array_unshift($params, $types);
call_user_func_array([$countStmt, 'bind_param'], $params);
array_shift($params);
array_shift($params);
}
$countStmt->execute();
$countResult = $countStmt->get_result();
$total_records = $countResult->fetch_assoc()['total'];
$total_pages = ceil($total_records / $limit);
$countStmt->close();
$searchTerm = trim($search ?? '');
if ($searchTerm !== '') {
$sql = "
SELECT ID, `date`, link
FROM cert
WHERE CAST(ID AS CHAR) LIKE ?
OR link LIKE ?
ORDER BY `date` DESC
LIMIT ? OFFSET ?
";
$stmt = $conn->prepare($sql);
if (!$stmt) {
die('Prepare failed: ' . $conn->error);
}
$like = "%{$searchTerm}%";
$stmt->bind_param('ssii', $like, $like, $limit, $offset);
} else {
$sql = "
SELECT ID, `date`, link
FROM cert
ORDER BY `date` DESC
LIMIT ? OFFSET ?
";
$stmt = $conn->prepare($sql);
if (!$stmt) {
die('Prepare failed: ' . $conn->error);
}
$stmt->bind_param('ii', $limit, $offset);
}
$stmt->execute();
$result = $stmt->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="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" />
<link rel="stylesheet" href="./src/css/cert-view.css" />
<link rel="stylesheet" href="./src/css/dashboard-rgd.css" />
<title>Pending Birth Forms</title>
</head>
<body>
<?php if ($status === 'success'): ?>
<div id="popup-msg" class="popup success">
✅ Email resent successfully!
</div>
<?php elseif ($status === 'error'): ?>
<div id="popup-msg" class="popup error">
❌ Failed to resend email. Please try again.
</div>
<?php endif; ?>
<header class="dashboard-header">
<div class="logo-title">
<?php echo "<img src='./src/img/rgd-logo.png' alt='RGD Logo' style='max-height: 40px; padding-right:10px;'>"; ?>
<?php echo "<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='index.php'><b> Dashboard </b> </a> / Pending Birth Registration Application
</nav>
</header>
<main>
<div class="container">
<h3>Issued certificates</h3>
<form method="get" style="margin-bottom:1.5rem; display:flex; gap:0.5rem;">
<input type="text" name="search" placeholder="Search by Form ID" value="<?php echo htmlspecialchars($search); ?>" />
<button type="submit" class="view-btn">Search</button>
</form>
<table>
<thead>
<tr>
<th>Certificate ID</th>
<th>Issued Date</th>
<th style="padding-left:9%;">Action</th>
</tr>
</thead>
<tbody>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo htmlspecialchars($row['ID']); ?></td>
<td><?php echo htmlspecialchars($row['date']); ?></td>
<td class="actions">
<!-- Download -->
<a href="<?php echo $row['link']; ?>" class="view-btn">
<i class="fas fa-download"></i> Download
</a>
<!-- Resend -->
<a
href="inc/resend.php?id=<?php echo urlencode($row['ID']); ?>"
class="view-btn resend-btn">
<img
src="./src/img/send.png"
alt="Email icon"
class="icon email-icon" />
Resend
</a>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<div class="pagination">
<?php if ($page > 1): ?>
<a href="?search=<?php echo urlencode($search); ?>&page=<?php echo $page - 1; ?>">Prev</a>
<?php endif; ?>
<?php for ($i = 1; $i <= $total_pages; $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 ($page < $total_pages): ?>
<a href="?search=<?php echo urlencode($search); ?>&page=<?php echo $page + 1; ?>">Next</a>
<?php endif; ?>
</div>
</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';
// remove from DOM after transition
pop.addEventListener('transitionend', () => pop.remove());
}, 3000);
});
</script>
</body>
</html>
<?php
$conn->close();
?>