-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_users.php
224 lines (193 loc) · 5.45 KB
/
view_users.php
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
<?php
// Start session or resume existing session
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
// Include config file for database connection
include 'config.php';
// Check if admin is logged in
if (!isset($_SESSION['username']) || $_SESSION['role'] !== 'admin') {
header('Location: login.php');
exit();
}
// Establish database connection
$conn = openDbConnection();
// Fetch users from the database
$query = "SELECT * FROM users";
$result = $conn->query($query);
// Check for errors
if (!$result) {
die("Error fetching users: " . $conn->error);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="style.css">
<title>Admin Dashboard - SeyssingComp</title>
</head>
<body>
<!-- Include Admin Header -->
<?php include 'admin_header.php'; ?>
<section class="admin-dashboard">
<div class="dashboard-header">
<h2>Welcome, Admin!</h2>
<h3>User Management</h3>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>User ID</th>
<th>Username</th>
<th>Name</th>
<th>Status</th>
<th>Email</th>
<th>Phone Number</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo htmlspecialchars($row['id']); ?></td>
<td><?php echo htmlspecialchars($row['username']); ?></td>
<td><?php echo htmlspecialchars($row['fullname']); ?></td>
<td><?php echo isset($row['status']) ? htmlspecialchars($row['status']) : 'Unknown'; ?></td>
<td><?php echo htmlspecialchars($row['email']); ?></td>
<td><?php echo htmlspecialchars($row['phone']); ?></td>
<td>
<form action="edit_user.php" method="post" class="user-action-form">
<input type="hidden" name="user_id" value="<?php echo $row['id']; ?>">
<button type="submit" name="action" value="edit" class="btn btn-edit">Edit</button>
</form>
<form action="delete_user.php" method="post" class="user-action-form">
<input type="hidden" name="user_id" value="<?php echo $row['id']; ?>">
<button type="submit" name="action" value="delete" class="btn btn-delete">Delete</button>
</form>
<form action="logout_user.php" method="post" class="user-action-form">
<input type="hidden" name="user_id" value="<?php echo $row['id']; ?>">
<button type="submit" name="action" value="logout" class="btn btn-logout">Log Out</button>
</form>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</section>
</body>
</html>
<?php
// Close database connection
$conn->close();
?>
<style>
/* Reset default margin and padding */
body, html {
margin: 0;
padding: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
background-color: #f0f0f0;
}
/* Make the header fixed */
header {
position: fixed;
top: 0;
width: 100%;
z-index: 1000;
background-color: #fff;
border-bottom: 1px solid #ddd;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
/* Add top padding to main content */
.admin-dashboard {
max-width: 1000px;
margin: 80px auto 20px auto; /* Adjusted margin to account for the header height */
padding: 20px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
/* Header styling */
.dashboard-header {
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 1px solid #ddd;
}
.dashboard-header h2 {
font-size: 28px;
color: #333;
margin-top: 0;
}
.dashboard-header h3 {
font-size: 20px;
color: #666;
margin-top: 5px;
}
/* Styling for the table */
.table-container {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
background-color: #fff;
}
table th, table td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
}
table th {
background-color: #f2f2f2;
font-size: 14px;
font-weight: bold;
color: #333;
text-transform: uppercase;
}
table td {
font-size: 14px;
color: #666;
}
/* Styling for action buttons */
.btn {
border: none;
padding: 8px 16px;
cursor: pointer;
border-radius: 4px;
transition: background-color 0.3s ease;
}
.btn.btn-edit {
background-color: #3498db;
color: #fff;
}
.btn.btn-delete {
background-color: #e74c3c;
color: #fff;
}
.btn.btn-logout {
background-color: #f39c12;
color: #fff;
}
.btn:hover {
opacity: 0.8;
}
/* Responsive design for smaller screens */
@media only screen and (max-width: 768px) {
.admin-dashboard {
padding: 15px;
}
table {
font-size: 12px;
}
.btn {
padding: 6px 12px;
}
}
</style>