-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.php
More file actions
260 lines (237 loc) · 7.98 KB
/
dashboard.php
File metadata and controls
260 lines (237 loc) · 7.98 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
<?php
if (!isset($_SESSION['HospitalID'])) {
header('Location: index.php');
exit();
}
if (isset($_GET['logout'])) {
session_unset();
session_destroy();
header('Location: index.php');
exit();
}
require_once './inc/dbh.inc.php';
$hospitalID = (int) $_SESSION['HospitalID'];
// Get hospital information
$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();
// ============================================================================
// STATISTICS FROM ENCRYPTED TABLE (form_data_secure)
// ============================================================================
// Total Issued Forms (all submissions for this hospital)
$stmt1 = $conn->prepare("SELECT COUNT(*) FROM form_data_secure WHERE hospital_id = ?");
$stmt1->bind_param('i', $hospitalID);
$stmt1->execute();
$stmt1->bind_result($totalCount);
$stmt1->fetch();
$stmt1->close();
// Generated Today (submissions today)
$stmt2 = $conn->prepare("SELECT COUNT(*) FROM form_data_secure WHERE DATE(submitted_date) = CURDATE() AND hospital_id = ?");
$stmt2->bind_param('i', $hospitalID);
$stmt2->execute();
$stmt2->bind_result($todayCount);
$stmt2->fetch();
$stmt2->close();
// Pending Today (status 'under review' or 'created')
$stmt3 = $conn->prepare("SELECT COUNT(*) FROM form_data_secure WHERE (status = 'under review' OR status = 'created') AND DATE(submitted_date) = CURDATE() AND hospital_id = ?");
$stmt3->bind_param('i', $hospitalID);
$stmt3->execute();
$stmt3->bind_result($pendingCount);
$stmt3->fetch();
$stmt3->close();
// Approved Today
$stmt4 = $conn->prepare("SELECT COUNT(*) FROM form_data_secure WHERE (status = 'approved' OR status = 'issued') AND DATE(submitted_date) = CURDATE() AND hospital_id = ?");
$stmt4->bind_param('i', $hospitalID);
$stmt4->execute();
$stmt4->bind_result($approvedCount);
$stmt4->fetch();
$stmt4->close();
// Approved This Month
$stmt5 = $conn->prepare(
"SELECT COUNT(*) FROM form_data_secure
WHERE (status = 'approved' OR status = 'issued')
AND MONTH(submitted_date) = MONTH(CURDATE())
AND YEAR(submitted_date) = YEAR(CURDATE())
AND hospital_id = ?"
);
$stmt5->bind_param('i', $hospitalID);
$stmt5->execute();
$stmt5->bind_result($monthCount);
$stmt5->fetch();
$stmt5->close();
// Recent Forms (latest 10 submissions)
// Note: We can't decrypt data here for performance, so we'll just show FormID and basic info
$limit = 10;
$stmt6 = $conn->prepare(
"SELECT FormID, status, submitted_date
FROM form_data_secure
WHERE hospital_id = ?
ORDER BY submitted_date DESC
LIMIT ?"
);
$stmt6->bind_param('ii', $hospitalID, $limit);
$stmt6->execute();
$result6 = $stmt6->get_result();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>BIS Dashboard</title>
<link rel="stylesheet" href="./src/css/dashboard.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" />
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
height: 100%;
}
body {
display: flex;
flex-direction: column;
}
main {
flex: 1;
}
footer {
background-color: #f5f5f5;
border-top: 1px solid #ddd;
padding: 20px;
text-align: center;
color: #666;
font-size: 14px;
margin-top: auto;
}
.badge.issued {
background-color: #abcaec;
color: #054c97;
padding: 5px 18px;
}
.badge.created {
background-color: #d1ecf1;
color: #0c5460;
padding: 5px 18px;
}
</style>
</head>
<body>
<header class="dashboard-header">
<div class="logo-title">
<img src="<?= htmlspecialchars($img_src) ?>" alt="Hospital Logo" style="max-height:40px;padding-right:10px;">
<h2>BIS Dashboard - <?= htmlspecialchars($hospital_name) ?></h2>
</div>
<a href="?logout=true" class="logout"><i class="fas fa-sign-out-alt"></i> Logout</a>
</header>
<main>
<section class="summary-section">
<div class="total-box">Total Submitted Forms: <strong><?= $totalCount ?></strong></div>
<div class="cards">
<div class="card">
<img src="src/img/generated.png" alt="Forms Today" class="card-icon" />
<p>Submitted Today<br><strong><?= $todayCount ?></strong></p>
</div>
<div class="card">
<img src="src/img/pending.png" alt="Pending Today" class="card-icon" />
<p>Pending Today<br><strong><?= $pendingCount ?></strong></p>
</div>
<div class="card">
<img src="src/img/approved.png" alt="Approved Today" class="card-icon" />
<p>Approved Today<br><strong><?= $approvedCount ?></strong></p>
</div>
<div class="card">
<img src="src/img/overview.png" alt="This Month" class="card-icon" />
<p>Approved This Month<br><strong><?= $monthCount ?></strong></p>
</div>
</div>
</section>
<section class="dashboard-actions">
<button onclick="location.href='generate-form.php'" class="action-btn generate">
<i class="fas fa-plus-circle"></i> Generate Birth Form
</button>
<button onclick="location.href='pending-form.php'" class="action-btn pending">
<i class="fas fa-hourglass-half"></i> View Pending Forms
</button>
<button onclick="location.href='approved-form.php'" class="action-btn approved">
<i class="fas fa-check-circle"></i> View Approved Forms
</button>
</section>
<section class="table-section">
<h2>Recent Forms Activity</h2>
<table>
<thead>
<tr>
<th>Form ID</th>
<th>Submitted Date</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php if ($result6->num_rows === 0): ?>
<tr>
<td colspan="4" style="text-align:center; padding: 20px; color: #999;">
<i class="fas fa-inbox"></i> No forms submitted yet
</td>
</tr>
<?php else: ?>
<?php while ($r = $result6->fetch_assoc()):
$statusBadge = '';
switch ($r['status']) {
case 'under review':
$statusBadge = '<span class="badge pending">Pending</span>';
break;
case 'created':
$statusBadge = '<span class="badge created">Created</span>';
break;
case 'issued':
$statusBadge = '<span class="badge issued">Issued</span>';
break;
case 'approved':
$statusBadge = '<span class="badge approved">Approved</span>';
break;
case 'rejected':
$statusBadge = '<span class="badge rejected">Rejected</span>';
break;
default:
$statusBadge = '<span class="badge">' . htmlspecialchars($r['status']) . '</span>';
}
?>
<tr>
<td><strong><?= htmlspecialchars($r['FormID']) ?></strong></td>
<td><?= htmlspecialchars($r['submitted_date']) ?></td>
<td><?= $statusBadge ?></td>
<td class="actions">
<a href="admin-view.php?FormID=<?= urlencode($r['FormID']) ?>" class="view-btn">
<i class="fas fa-eye"></i> View
</a>
</td>
</tr>
<?php endwhile; ?>
<?php endif; ?>
</tbody>
</table>
</section>
</main>
<footer>
Register General's Department - Sri Lanka
</footer>
</body>
</html>
<?php
$stmt6->close();
$conn->close();
?>