-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuserManagement.php
More file actions
230 lines (211 loc) · 10.3 KB
/
userManagement.php
File metadata and controls
230 lines (211 loc) · 10.3 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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "frontend&backend";
$conn = mysqli_connect($servername, $username, $password, $database);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Search functionality
$search = isset($_GET['search']) ? $_GET['search'] : '';
$where = "WHERE 1=1";
if (!empty($search)) {
$search = mysqli_real_escape_string($conn, $search);
$where .= " AND (full_name LIKE '%$search%'
OR first_name LIKE '%$search%'
OR id_number LIKE '%$search%'
OR university_name LIKE '%$search%')";
}
// Pagination
$limit = 8;
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$offset = ($page - 1) * $limit;
$query = "SELECT * FROM teachers $where LIMIT $limit OFFSET $offset";
$result = mysqli_query($conn, $query);
// Total rows for pagination
$total_query = "SELECT COUNT(*) as total FROM teachers $where";
$total_result = mysqli_query($conn, $total_query);
$total_row = mysqli_fetch_assoc($total_result);
$total_rows = $total_row['total'];
$total_pages = ceil($total_rows / $limit);
// Delete functionality
if (isset($_POST['delete_id'])) {
$delete_id = $_POST['delete_id'];
$delete_query = "DELETE FROM teachers WHERE id = $delete_id";
if (mysqli_query($conn, $delete_query)) {
header("Location: userManagement.php?deleted=1");
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Management</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.sidebar-item {
transition: all 0.2s ease;
}
.sidebar-item:hover {
transform: translateX(3px);
}
</style>
</head>
<body class="bg-gray-100 min-h-screen flex">
<!-- Sidebar Navigation -->
<div class="bg-blue-800 w-64 flex flex-col text-white p-6 fixed h-full">
<div class="flex items-center gap-3 border-b border-blue-600 pb-4">
<i class="fas fa-user-circle text-4xl text-blue-200"></i>
<div>
<p class="text-lg font-semibold">Admin Panel</p>
<p class="text-sm text-blue-200">Administrator</p>
</div>
</div>
<nav class="mt-6 space-y-2">
<a href="admin.php" class="flex items-center gap-3 p-3 sidebar-item hover:bg-blue-700 rounded-lg">
<i class="fas fa-chart-line w-5 text-center"></i>
<span>Dashboard</span>
</a>
<a href="pendingApproval.php" class="flex items-center gap-3 p-3 sidebar-item hover:bg-blue-700 rounded-lg">
<i class="fas fa-clock w-5 text-center"></i>
<span>Pending Approval</span>
</a>
<a href="approvedCurriculum.php" class="flex items-center gap-3 p-3 sidebar-item hover:bg-blue-700 rounded-lg">
<i class="fas fa-check-circle w-5 text-center"></i>
<span>Approved Curriculum</span>
</a>
<a href="userManagement.php" class="flex items-center gap-3 p-3 sidebar-item bg-blue-700 rounded-lg">
<i class="fas fa-users w-5 text-center"></i>
<span>User Management</span>
</a>
<a href="#" class="flex items-center gap-3 p-3 sidebar-item hover:bg-blue-700 rounded-lg mt-8">
<i class="fas fa-sign-out-alt w-5 text-center"></i>
<span>Logout</span>
</a>
</nav>
</div>
<!-- Main Content -->
<div class="flex-1 ml-64 p-8 overflow-y-auto">
<div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-bold text-gray-800">
<i class="fas fa-users text-blue-600 mr-2"></i>
User Management
</h1>
<!-- Search Bar -->
<form method="GET" action="" class="flex items-center">
<div class="relative">
<input type="text" name="search" placeholder="Search users..."
value="<?php echo htmlspecialchars($search); ?>"
class="pl-10 pr-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
<i class="fas fa-search absolute left-3 top-3 text-gray-400"></i>
</div>
<button type="submit" class="ml-2 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg">
Search
</button>
<?php if (!empty($search)): ?>
<a href="userManagement.php" class="ml-2 bg-gray-500 hover:bg-gray-600 text-white px-4 py-2 rounded-lg">
Clear
</a>
<?php endif; ?>
</form>
</div>
<!-- User Table -->
<div class="bg-white p-6 rounded-lg shadow-md overflow-auto">
<table class="min-w-full text-sm text-left">
<thead class="bg-blue-800 text-white">
<tr>
<th class="px-6 py-3">ID</th>
<th class="px-6 py-3">Full Name</th>
<th class="px-6 py-3">Email</th>
<th class="px-6 py-3">ID Number</th>
<th class="px-6 py-3">University</th>
<th class="px-6 py-3">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200 text-gray-800">
<?php if (mysqli_num_rows($result) > 0): ?>
<?php while ($row = mysqli_fetch_assoc($result)): ?>
<tr class="hover:bg-gray-50">
<td class="px-6 py-4"><?php echo htmlspecialchars($row['id']); ?></td>
<td class="px-6 py-4"><?php echo htmlspecialchars($row['full_name']); ?></td>
<td class="px-6 py-4"><?php echo htmlspecialchars($row['full_name']); ?></td>
<td class="px-6 py-4"><?php echo htmlspecialchars($row['id_number']); ?></td>
<td class="px-6 py-4"><?php echo htmlspecialchars($row['university_name']); ?></td>
<td class="px-6 py-4">
<form method="POST" action="" onsubmit="return confirm('Are you sure you want to delete this user?');">
<input type="hidden" name="delete_id" value="<?php echo $row['id']; ?>">
<button type="submit" class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-md text-sm">
<i class="fas fa-trash-alt mr-1"></i> Delete
</button>
</form>
</td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr>
<td colspan="6" class="px-6 py-4 text-center text-gray-500">
No users found <?php echo !empty($search) ? 'matching your search' : ''; ?>
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
<!-- Pagination -->
<?php if ($total_pages > 1): ?>
<div class="mt-6 flex justify-center">
<nav class="inline-flex rounded-md shadow">
<?php if ($page > 1): ?>
<a href="?page=<?php echo $page - 1; ?>&search=<?php echo urlencode($search); ?>"
class="px-3 py-2 rounded-l-md border border-gray-300 bg-white text-gray-500 hover:bg-gray-50">
<i class="fas fa-chevron-left"></i>
</a>
<?php endif; ?>
<?php
// Show page numbers
$start = max(1, $page - 2);
$end = min($total_pages, $page + 2);
if ($start > 1) {
echo '<a href="?page=1&search='.urlencode($search).'" class="px-3 py-2 border border-gray-300 bg-white text-gray-500 hover:bg-gray-50">1</a>';
if ($start > 2) echo '<span class="px-3 py-2 border border-gray-300 bg-white text-gray-500">...</span>';
}
for ($i = $start; $i <= $end; $i++) {
$active = $i == $page ? 'bg-blue-600 text-white' : 'bg-white text-gray-500 hover:bg-gray-50';
echo '<a href="?page='.$i.'&search='.urlencode($search).'" class="px-3 py-2 border border-gray-300 '.$active.'">'.$i.'</a>';
}
if ($end < $total_pages) {
if ($end < $total_pages - 1) echo '<span class="px-3 py-2 border border-gray-300 bg-white text-gray-500">...</span>';
echo '<a href="?page='.$total_pages.'&search='.urlencode($search).'" class="px-3 py-2 border border-gray-300 bg-white text-gray-500 hover:bg-gray-50">'.$total_pages.'</a>';
}
?>
<?php if ($page < $total_pages): ?>
<a href="?page=<?php echo $page + 1; ?>&search=<?php echo urlencode($search); ?>"
class="px-3 py-2 rounded-r-md border border-gray-300 bg-white text-gray-500 hover:bg-gray-50">
<i class="fas fa-chevron-right"></i>
</a>
<?php endif; ?>
</nav>
</div>
<?php endif; ?>
</div>
<?php if (isset($_GET['deleted'])): ?>
<div id="notification" class="fixed bottom-4 right-4 bg-green-600 text-white px-6 py-3 rounded-lg shadow-lg">
<div class="flex items-center gap-3">
<i class="fas fa-check-circle"></i>
<span>User deleted successfully!</span>
</div>
</div>
<script>
setTimeout(() => {
document.getElementById('notification').classList.add('hidden');
}, 3000);
</script>
<?php endif; ?>
</body>
</html>
<?php mysqli_close($conn); ?>