-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.php
More file actions
225 lines (188 loc) · 4.78 KB
/
Copy pathusers.php
File metadata and controls
225 lines (188 loc) · 4.78 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
<?php
require_once "admin_middleware.php";
require_once "config.php";
$users = $pdo->query("
SELECT id, full_name, email, role, is_active, created_at
FROM users
ORDER BY id DESC
")->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>User Management</title>
<style>
body {
font-family: "Segoe UI", Tahoma, Arial, sans-serif;
background: #f4f6f9;
padding: 20px;
}
.page-card {
background: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
max-width: 1200px;
margin: auto;
}
.page-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}
.page-header h2 {
margin: 0;
}
.controls {
display: flex;
gap: 10px;
}
.search-box {
padding: 8px 12px;
border: 1px solid #ccc;
border-radius: 6px;
width: 220px;
}
.btn-add, .close-btn {
background: #2563eb;
color: #fff;
padding: 9px 14px;
border-radius: 6px;
text-decoration: none;
font-weight: 600;
cursor: pointer;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 12px;
border-bottom: 1px solid #e5e7eb;
}
th {
background: #f1f5f9;
text-transform: uppercase;
font-size: 0.8rem;
}
tr:hover {
background: #f9fafb;
}
.status {
padding: 4px 10px;
border-radius: 999px;
font-size: 0.75rem;
font-weight: 700;
}
.status.active {
background: #dcfce7;
color: #166534;
}
.status.disabled {
background: #fee2e2;
color: #991b1b;
}
.toggle-btn {
padding: 6px 10px;
border-radius: 6px;
font-size: 0.75rem;
font-weight: 700;
border: none;
cursor: pointer;
}
.toggle-enable {
background: #16a34a;
color: #fff;
}
.toggle-disable {
background: #dc2626;
color: #fff;
}
.actions a {
color: #2563eb;
text-decoration: none;
font-weight: 600;
}
</style>
</head>
<body>
<div class="page-card">
<div class="page-header">
<span class="close-btn" title="Close" onclick="window.location='admin_dashboard.php'">×</span>
<h2>👥 User Management</h2>
<div class="controls">
<input type="text" id="searchInput" class="search-box" placeholder="Search users...">
<a href="create_user.php" class="btn-add">➕ Add User</a>
</div>
</div>
<table id="userTable">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Role</th>
<th>Status</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $u): ?>
<tr>
<td><?= htmlspecialchars($u['full_name']) ?></td>
<td><?= htmlspecialchars($u['email']) ?></td>
<td><?= strtoupper($u['role']) ?></td>
<td>
<span class="status <?= $u['is_active'] ? 'active' : 'disabled' ?>">
<?= $u['is_active'] ? 'Active' : 'Disabled' ?>
</span>
</td>
<td><?= date('M d, Y', strtotime($u['created_at'])) ?></td>
<td>
<a href="edit_user.php?id=<?= $u['id'] ?>"
style="padding:6px 10px; background:#007bff; color:#fff; border-radius:4px; text-decoration:none;">
✏️ Edit
</a>
<?php if ($u['id'] != $_SESSION['id']): ?>
<a href="delete.php?id=<?= $u['id'] ?>"
onclick="return confirm('Disable this user?')"
style="padding:6px 10px; background:#dc3545; color:#fff; border-radius:4px; text-decoration:none; margin-left:5px;">
🚫 Disable
</a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<script>
// 🔍 Live search
document.getElementById('searchInput').addEventListener('keyup', function () {
let value = this.value.toLowerCase();
document.querySelectorAll('#userTable tbody tr').forEach(row => {
row.style.display = row.innerText.toLowerCase().includes(value) ? '' : 'none';
});
});
// 🔄 AJAX enable / disable
function toggleUser(userId, btn) {
if (!confirm('Are you sure?')) return;
fetch('toggle_user_status.php', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: 'user_id=' + userId
})
.then(res => res.json())
.then(data => {
if (data.success) {
location.reload();
} else {
alert(data.error);
}
});
}
</script>
</body>
</html>