-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.php
265 lines (249 loc) · 13 KB
/
user.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
<?php
include "src/header.php";
if (isset($_SESSION["user_role"])) {
if ($_SESSION["user_role"] != "admin") {
echo '<script>';
echo 'location.href = "index.php";';
echo '</script>';
}
}
$userQuery = "SELECT * FROM user";
$execUserQuery = mysqli_query($conn, $userQuery);
?>
<style>
.role {
color: white;
}
</style>
<!-- ============================================================== -->
<!-- Page wrapper -->
<!-- ============================================================== -->
<div class="page-wrapper">
<!-- ============================================================== -->
<!-- Bread crumb and right sidebar toggle -->
<!-- ============================================================== -->
<div class="page-breadcrumb">
<div class="row">
<div class="col-7 align-self-center">
<h4 class="page-title text-truncate text-dark font-weight-medium mb-1">User</h4>
<div class="d-flex align-items-center">
<nav aria-label="breadcrumb">
<ol class="breadcrumb m-0 p-0">
<li class="breadcrumb-item text-muted active" aria-current="page">User List</li>
</ol>
</nav>
</div>
</div>
<div class="col-5 align-self-center">
<div class="customize-input float-right">
<form class="mt-4">
<div class="form-group">
<button type="button" class="btn btn-success border-0 custom-shadow" data-toggle="modal"
data-target="#new-user-modal">
<i class="fas fa-plus"></i> User
</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- ============================================================== -->
<!-- End Bread crumb and right sidebar toggle -->
<!-- ============================================================== -->
<!-- ============================================================== -->
<!-- Container fluid -->
<!-- ============================================================== -->
<div class="container-fluid">
<!-- ============================================================== -->
<!-- Start Page Content -->
<!-- ============================================================== -->
<div class="row">
<!-- Start List Directory Table -->
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table id="zero_config" class="table table-striped table-bordered no-wrap">
<thead>
<tr>
<th>No</th>
<th>Email</th>
<th>Name</th>
<th>Username</th>
<th>Role</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
<?php
if (mysqli_num_rows($execUserQuery)>0) {
$count = 1;
foreach ($execUserQuery as $userData) {
?>
<tr>
<td><?php echo $count; ?></td>
<td><?php echo $userData['email']; ?></td>
<td><?php echo $userData['fullname']; ?></td>
<td><?php echo $userData['username']; ?></td>
<?php if ($userData['user_role']=='user') { ?>
<td>
<div class="text-center">
<span class="badge mr-2 badge badge-warning role">User</span>
</div>
</td>
<?php } else { ?>
<td>
<div class="text-center">
<span class="badge mr-2 badge badge-info role">Admin</span>
</div>
</td>
<?php } ?>
<td class="text-center">
<a href="user-detail.php?email=<?php echo $userData["email"]; ?>" class="btn btn-sm btn-primary btn-rounded">
View
</a>
<?php if($userData["username"] != $_SESSION["username"]) { ?>
<button type="button" class="btn btn-sm btn-danger btn-rounded" onclick="deleteUser('<?php echo $userData['id']; ?>','<?php echo $userData['username']; ?>')">
Delete
</button>
<?php } ?>
</td>
</tr>
<?php
$count++;
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- End List Directory Table -->
</div>
<!-- ============================================================== -->
<!-- End PAge Content -->
<!-- ============================================================== -->
<!-- ============================================================== -->
<!-- Right sidebar -->
<!-- ============================================================== -->
<!-- .right-sidebar -->
<!-- ============================================================== -->
<!-- End Right sidebar -->
<!-- ============================================================== -->
</div>
<!-- ============================================================== -->
<!-- End Container fluid -->
<!-- ============================================================== -->
</div>
<!-- ============================================================== -->
<!-- End Page wrapper -->
<!-- ============================================================== -->
<?php
include "src/footer.php";
?>
<script src="src/dist/js/ajaxForm/userAdd.js"></script>
<script src="src/dist/js/ajaxForm/userDelete.js"></script>
</body>
<!-- Add new user modal content -->
<div id="new-user-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header"><b>Add New User</b></div>
<div class="modal-body">
<form action="#" class="pl-3 pr-3">
<div class="form-group">
<label for="email">Email</label>
<input class="form-control" type="email" required=""
id="email" name="email" placeholder="Enter user email">
<div class="invalid-feedback" id="email-error-exist" style="display: none">
Email already exist, please insert another email
</div>
<div class="invalid-feedback" id="email-error-null" style="display: none">
Please enter user email
</div>
<div class="invalid-feedback" id="email-error-format" style="display: none">
Email format invalid
</div>
</div>
<div class="form-group">
<label for="username">Username</label>
<input class="form-control" type="text" required=""
id="username" name="username" placeholder="Enter username" style="text-transform: lowercase">
<div class="invalid-feedback" id="username-error-exist" style="display: none">
Username already exist, please insert another username.
</div>
<div class="invalid-feedback" id="username-error-null" style="display: none">
Please insert username.
</div>
</div>
<div class="form-group">
<label for="fullname">Fullname</label>
<input class="form-control" type="text" required=""
id="fullname" name="fullname" placeholder="Enter user full name">
<div class="invalid-feedback" id="fullname-error-null" style="display: none">
Please enter full name
</div>
</div>
<div class="form-group mb-4">
<label for="exampleFormControlSelect1" >Select No</label>
<select class="form-control" id="role" name="role" required>
<option value="user">User</option>
<option value="admin">Admin</option>
</select>
</div>
<div class="form-group">
<label for="password">Password</label>
<input class="form-control" type="password" required=""
id="password" name="password" placeholder="Enter new password">
<div class="invalid-feedback" id="password-error-null" style="display: none">
Please enter password
</div>
</div>
<div class="form-group">
<label for="password1">Confirm Password</label>
<input class="form-control" type="password" required=""
id="confirmPassword" name="confirmPassword" placeholder="Confirm new password">
<div class="invalid-feedback" id="password-confirm-error-null" style="display: none">
Please enter confirm password
</div>
<div class="invalid-feedback" id="password-confirm-error-match" style="display: none">
Password do not match
</div>
</div>
<div class="form-group text-center">
<button class="btn btn-rounded btn-primary" type="button" id="userAdd">Add User</button>
<button class="btn btn-rounded btn-danger" type="button" data-dismiss="modal">Cancel</button>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- Delete User Modal -->
<div id="delete-user-modal" class="modal fade" tabindex="-1" role="dialog"
aria-labelledby="danger-header-modalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-center">
<div class="modal-content">
<div class="modal-header modal-colored-header bg-danger">
<h4 class="modal-title" id="danger-header-modalLabel">Confirm Action</h4>
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
</div>
<div class="modal-body">
<h5 class="mt-0"></h5>
<p>Confirm delete user? Action cannot be reverted.</p>
<p id="modalUserId"></p>
<input type="hidden" id="idDelete">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light"
data-dismiss="modal">Close</button>
<button type="button" class="btn btn-danger" onclick="confirmDelete(id)">Delete</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</html>