-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-dashboard.php
More file actions
187 lines (173 loc) · 8 KB
/
Copy pathadmin-dashboard.php
File metadata and controls
187 lines (173 loc) · 8 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
<?php
include('config.php');
session_start();
// Prevent browser caching
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
// Redirect to login if not logged in
if (!isset($_SESSION['student_id']) && !isset($_SESSION['admin_id'])) {
header("Location: index.php");
exit();
}
$admin_id = $_SESSION['admin_id'];
// Fetch admin's assigned category
$stmt = $conn->prepare("SELECT assigned_category FROM admins WHERE id = ?");
$stmt->bind_param("i", $admin_id);
$stmt->execute();
$result = $stmt->get_result();
$admin_data = $result->fetch_assoc();
$assigned_category = $admin_data['assigned_category'] ?? '';
if (!$assigned_category) {
echo "No category assigned. Contact super admin.";
exit();
}
// Summary stats for this category
$stmt = $conn->prepare("
SELECT
COUNT(*) AS total,
SUM(CASE WHEN status = 'Resolved' THEN 1 ELSE 0 END) AS resolved,
SUM(CASE WHEN status = 'Pending' THEN 1 ELSE 0 END) AS pending
FROM grievances
WHERE category = ?
");
$stmt->bind_param("s", $assigned_category);
$stmt->execute();
$stats = $stmt->get_result()->fetch_assoc();
// Fetch admins of the same category
$stmt = $conn->prepare("SELECT id, name, email, assigned_category FROM admins WHERE assigned_category = ?");
$stmt->bind_param("s", $assigned_category);
$stmt->execute();
$category_admins = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
<link rel="stylesheet" href="assets/css/sidebar.css" />
<link rel="stylesheet" href="assets/css/admin-dashboard.css" />
<meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate, max-age=0" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
</head>
<body>
<nav id="sidebar">
<ul>
<li>
<span class="logo">SKIT</span>
<button id="toggle-btn">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px"
fill="#e3e3e3">
<path d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z" />
</svg>
</button>
</li>
<li class="active">
<a href="#">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px"
fill="#e3e3e3">
<path
d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h240v-560H200v560Zm320 0h240v-280H520v280Zm0-360h240v-200H520v200Z" />
</svg>
<span>Dashboard</span>
</a>
</li>
<li>
<a href="admin-view-grievances.php">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px"
fill="#e3e3e3">
<path
d="M200-200v-560 179-19 400Zm80-240h221q2-22 10-42t20-38H280v80Zm0 160h157q17-20 39-32.5t46-20.5q-4-6-7-13t-5-14H280v80Zm0-320h400v-80H280v80Zm-80 480q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v258q-14-26-34-46t-46-33v-179H200v560h202q-1 6-1.5 12t-.5 12v56H200Zm480-200q-42 0-71-29t-29-71q0-42 29-71t71-29q42 0 71 29t29 71q0 42-29 71t-71 29ZM480-120v-56q0-24 12.5-44.5T528-250q36-15 74.5-22.5T680-280q39 0 77.5 7.5T832-250q23 9 35.5 29.5T880-176v56H480Z" />
</svg>
<span>View Grievances</span>
</a>
</li>
<li>
<a href="admin-action.php">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px"
fill="#e3e3e3">
<path
d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h167q11-35 43-57.5t70-22.5q40 0 71.5 22.5T594-840h166q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560h-80v120H280v-120h-80v560Zm280-560q17 0 28.5-11.5T520-800q0-17-11.5-28.5T480-840q-17 0-28.5 11.5T440-800q0 17 11.5 28.5T480-760Z" />
</svg>
<span>Take Action</span>
</a>
</li>
<li>
<a href="admin-profile.php">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px"
fill="#e3e3e3">
<path
d="M480-480q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 66-47 113t-113 47ZM160-160v-112q0-34 17.5-62.5T224-378q62-31 126-46.5T480-440q66 0 130 15.5T736-378q29 15 46.5 43.5T800-272v112H160Zm80-80h480v-32q0-11-5.5-20T700-306q-54-27-109-40.5T480-360q-56 0-111 13.5T260-306q-9 5-14.5 14t-5.5 20v32Zm240-320q33 0 56.5-23.5T560-640q0-33-23.5-56.5T480-720q-33 0-56.5 23.5T400-640q0 33 23.5 56.5T480-560Zm0-80Zm0 400Z" />
</svg>
<span>Profile</span>
</a>
</li>
</ul>
</nav>
<main>
<header>
<h1>Dashboard</h1>
<button id="logout-btn">
<a href="logout.php" class="logout-text">Logout</a>
</button>
</header>
<p class="sub-heading">Category: <strong><?php echo htmlspecialchars($assigned_category); ?></strong></h3>
<div class="container">
<!-- Stats Section -->
<div class="cards">
<div class="card">
<h3><?php echo $stats['total'] ?? 0; ?></h3>
<p>Total Grievances</p>
</div>
<div class="card">
<h3><?php echo $stats['pending'] ?? 0; ?></h3>
<p>Pending</p>
</div>
<div class="card">
<h3><?php echo $stats['resolved'] ?? 0; ?></h3>
<p>Resolved</p>
</div>
</div>
<!-- Admin List for This Category -->
<p class="heading">Admins for <?php echo htmlspecialchars($assigned_category); ?></p>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Assigned Category</th>
</tr>
</thead>
<tbody>
<?php if (!empty($category_admins)): ?>
<?php foreach ($category_admins as $admin): ?>
<tr>
<td data-label="Name"><?php echo htmlspecialchars($admin['name']); ?></td>
<td data-label="Email"><?php echo htmlspecialchars($admin['email']); ?></td>
<td data-label="Assigned Category">
<?php echo htmlspecialchars($admin['assigned_category']); ?>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="3">No admins found for this category.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
<script src="assets/JavaScript/sidebar.js" defer></script>
<script>
window.addEventListener('pageshow', function (event) {
if (event.persisted) {
window.location.reload();
}
});
</script>
</body>
</html>