-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin-users.php
269 lines (228 loc) · 11.1 KB
/
admin-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
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
261
262
263
264
265
266
267
268
269
<?php
session_start();
if (isset($_SESSION['user_id'])) {
// create a database connection
$mysqli = require __DIR__ . '/database.php';
// get the user's email address
$sql = "SELECT * FROM users
WHERE id = {$_SESSION['user_id']}";
$result = $mysqli->query($sql);
$user = $result->fetch_assoc();
} else {
header('Location: home.php');
}
?>
<?php
// fetch the number of total users from the users table
$sql = "SELECT COUNT(*) AS user_count FROM users";
$user_count_result = $mysqli->query($sql);
$user_count = $user_count_result->fetch_assoc();
// fetch the number of artists from the users table
$sql = "SELECT COUNT(*) AS artist_count FROM users
WHERE isArtist = 'yes'";
$artist_count_result = $mysqli->query($sql);
$artist_count = $artist_count_result->fetch_assoc();
// fetch the number of admins from the users table
$sql = "SELECT COUNT(*) AS admin_count FROM users
WHERE isAdmin = 'yes'";
$admin_count_result = $mysqli->query($sql);
$admin_count = $admin_count_result->fetch_assoc();
$enth_count = $user_count['user_count'] - ($artist_count['artist_count'] + $admin_count['admin_count']);
?>
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Moneylisa Users | <?= $user['name'] ?>
</title>
<!-- Styling imports -->
<link rel='stylesheet' href='styles/main.css'>
<link rel='stylesheet' href='styles/utility.css'>
<!-- Bootstrap Icons imports -->
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css'>
</head>
<body>
<?php include __DIR__ . '/admin-navbar.php'; ?>
<!-- Start of main -->
<div class='container-flex' style='padding-left:7%; padding-right:8%;'>
<div class='row'>
<!-- Start of aside navbar -->
<nav class='col-md-3 col-lg-2 d-md-block'>
<div class='position-sticky pt-3 background-cultured'>
<ul class='nav flex-column'>
<li class='nav-item'>
<a class='nav-link' href='admin-dashboard.php'>
<i class='bi bi-bar-chart' style='font-size: 22px;'></i>
Dashboard
</a>
</li>
<li class='nav-item'>
<a class='nav-link active' aria-current='page' href='admin-users.php'>
<i class='bi bi-people-fill imperial-red' style='font-size: 22px;'></i>
Users
</a>
</li>
<li class='nav-item'>
<a class='nav-link' href='admin-pieces.php'>
<i class='bi bi-box-seam' style='font-size: 22px;'></i>
Pieces
</a>
</li>
<li class='nav-item'>
<a class='nav-link' href='admin-galleries.php'>
<i class='bi bi-building' style='font-size: 22px;'></i>
Galleries
</a>
</li>
<li class='nav-item'>
<a class='nav-link' href='admin-orders.php'>
<i class='bi bi-card-checklist' style='font-size: 22px;'></i>
Orders
</a>
</li>
</ul>
</div>
</nav>
<!-- End of aside navbar -->
<!-- Start of main -->
<main class='col-md-9 col-lg-10'>
<?php if (isset($user)) : ?>
My name is <?= $user['name'] ?>.
My artist id is <?= $user['id'] ?>.
<?php else : ?>
<p class='nav-link'>
<a href='signin.php'>Sign In</a>
or
<a href='signup.html'>Sign Up</a>
</p>
<?php endif; ?>
<div class='row'>
<div class='col-lg-6 col-md-6 pt-3 pb-2 mb-3'>
<h1 class='fs-2'>Users.</h1>
<p class='fs-6 ps-4 space-cadet'>
All the users having Moneylisa accounts at the moment.
</p>
</div>
<div class='col-lg-6 col-md-6 pt-3 pb-2 mb-3'>
<div class='row'>
<span class='col-lg-3 badge badge-imperial mr-3'>
<?= $user_count['user_count'] ?> <?= $user_count['user_count'] == 1 ? " User" : " Users" ?>
</span>
<span class='col-lg-3 badge badge-imperial mr-3'>
<?= $artist_count['artist_count'] ?> <?= $artist_count['artist_count'] == 1 ? " Artist" : " Artists" ?>
</span>
<span class='col-lg-3 badge badge-imperial mr-3'>
<?= $enth_count ?> <?= $enth_count == 1 ? " Enthusiast" : " Enthusiasts" ?>
</span>
</div>
</div>
</div>
<hr class='mobile-hide hr' />
<h1 class='fs-2'>Artists.</h1>
<!-- Get and display the Artists from users table -->
<div class='table-responsive'>
<table class='table table-striped table-sm'>
<thead>
<tr>
<th scope='col'>User Id</th>
<th scope='col'>Name</th>
<th scope='col'>Email</th>
<th scope='col'>Role</th>
<th scope='col'>Created At</th>
<th scope='col'>Suspend</th>
</tr>
</thead>
<tbody>
<?php
// get the details from user table of the pieces made by the logged in user
$user_sql = "SELECT * FROM users WHERE isArtist = 'yes'";
$user_result = $mysqli->query($user_sql);
while ($user = $user_result->fetch_assoc()) {
?>
<tr>
<td><?= 'U00' . $user['id'] ?></td>
<td><?= $user['name'] ?></td>
<td><?= $user['email'] ?></td>
<td>
<?php
if ($user['isArtist'] == 'yes') {
echo 'Artist';
} else if ($user['isAdmin'] == 'yes') {
echo 'Admin';
} else {
echo 'Enthusiast';
}
?>
</td>
<td><?= date('d M Y, g:i A', strtotime($user['created_at'])) ?></td>
<td>
<center>
<form action='process-delete-user.php' method='POST'>
<input type='hidden' name='user_id' value='<?= $user['id'] ?>'>
<button type='submit' class='btn btn-sm mb-2'>Suspend</button>
</form>
</center>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<h1 class='fs-2'>Enthusiasts.</h1>
<!-- Get and display the Enthusiasts from users table -->
<div class='table-responsive'>
<table class='table table-striped table-sm'>
<thead>
<tr>
<th scope='col'>User Id</th>
<th scope='col'>Name</th>
<th scope='col'>Email</th>
<th scope='col'>Role</th>
<th scope='col'>Created At</th>
<th scope='col'>Suspend</th>
</tr>
</thead>
<tbody>
<?php
// get the details from user table of the pieces made by the logged in user
$user_sql = "SELECT * FROM users WHERE isArtist = 'no'";
$user_result = $mysqli->query($user_sql);
while ($user = $user_result->fetch_assoc()) {
?>
<tr>
<td><?= 'U00' . $user['id'] ?></td>
<td><?= $user['name'] ?></td>
<td><?= $user['email'] ?></td>
<td>
<?php
if ($user['isArtist'] == 'yes') {
echo 'Artist';
} else if ($user['isAdmin'] == 'yes') {
echo 'Admin';
} else {
echo 'Enthusiast';
}
?>
</td>
<td><?= date('d M Y, g:i A', strtotime($user['created_at'])) ?></td>
<td>
<center>
<form action='process-delete-user.php' method='POST'>
<input type='hidden' name='user_id' value='<?= $user['id'] ?>'>
<button type='submit' class='btn btn-sm mb-2'>Suspend</button>
</form>
</center>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</main>
<!-- End of main -->
</div>
</div>
</body>
</html>