-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.php
297 lines (283 loc) · 10.8 KB
/
dashboard.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<?php
include 'header.php';
// if (isset($_SESSION['authority'])) {
// header("Location: dashboard.php");
// exit();
// // logged in
// } else {
// header("Location: index.php");
// exit();
// }
$user_sql = "SELECT * FROM users";
$data = $con->query($user_sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Dashboard</title>
<!-- plugins:css -->
<link rel="stylesheet" href="assets/vendors/font-awesome/all.min.css">
<link rel="stylesheet" href="assets/vendors/css/vendor.bundle.base.css">
<link rel="stylesheet" href="assets/vendors/css/vendor.bundle.addons.css">
<!-- endinject -->
<!-- inject:css -->
<link rel="stylesheet" href="assets/css/style.css">
<!-- endinject -->
<style>
#user{
text-align: center;
vertical-align: middle;
}
</style>
</head>
<body>
<div class="container-scroller">
<!-- partial:../../partials/_navbar.html -->
<nav class="navbar col-lg-12 col-12 p-0 fixed-top d-flex flex-row">
<div class="text-center navbar-brand-wrapper d-flex align-items-center justify-content-center">
<a class="navbar-brand brand-logo" href="dashboard.php">LOGO</a>
</div>
<div class="navbar-menu-wrapper d-flex align-items-center justify-content-end">
<button class="navbar-toggler navbar-toggler align-self-center" type="button" data-toggle="minimize">
<span class="fas fa-align-justify"></span>
</button>
<ul class="navbar-nav navbar-nav-right">
<li class="nav-item nav-profile dropdown">
<a class="nav-link" href="#" data-toggle="dropdown" id="profileDropdown">
<i class="fa fa-user"></i>
</a>
<div class="dropdown-menu dropdown-menu-right navbar-dropdown" aria-labelledby="profileDropdown">
<a class="dropdown-item" href="index.php">
<!-- session destroy -->
<i class="fa fa-sign-out-alt text-primary"></i>
Logout
</a>
</div>
</li>
</ul>
</div>
</nav>
<!-- partial -->
<div class="container-fluid page-body-wrapper">
<!-- partial -->
<div class="main-panel">
<?php if(isset($_SESSION['authority']) && $_SESSION['authority'] > 1) {?>
<div class="content-wrapper">
<div class="row">
<div class="col-lg-12 grid-margin stretch-card">
<div class="card">
<div class="card-body">
<h4 class="card-title">User management</h4>
<p class="card-description">
User edit and delete, etc.
</p>
<div class="table-responsive pt-3">
<table class="table table-bordered" id="user">
<thead>
<tr>
<th>
#
</th>
<th>
<i class="fa fa-user">
</th>
<th>
<i class="fa fa-lock">
</th>
<th>
<i class="far fa-file">
</th>
<th>
<i class="fas fa-pencil-alt">
</th>
<th>
<i class="fab fa-superpowers">
</th>
<th>
<i class="fa fa-trash">
</th>
</tr>
</thead>
<tbody>
<?php if ($data->num_rows > 0) {
// output data of each row
$i = 1;
while($row = $data->fetch_assoc()) {?>
<tr id="<?php echo $row['id'] ?>">
<td><?php echo $i++; ?> </td>
<td><?php echo $row['username']; ?> </td>
<td><?php echo $row['password']; ?> </td>
<?php if($row['path']==null) {?>
<td></td>
<?php } else {?>
<td><a href="<php echo $row['path'] ?>"><i class="far fa-file"></i></a></td>
<?php }?>
<td>
<button type="button" class="btn btn-info btn-rounded btn-icon edit" data-toggle="modal" data-target="#edit" data-whatever="@mdo">
<i class="fas fa-pencil-alt"></i>
</button>
</td>
<?php if($row['authority']==2){?>
<td>admin</td>
<?php } else {?>
<td>normal</td>
<?php }?>
<td>
<button type="button" class="btn btn-danger btn-rounded btn-icon delete">
<i class="fa fa-trash"></i>
</button>
</td>
</tr>
<?php }
} else { ?>
No data
<?php }?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<?php }?>
<!-- partial:../../partials/_footer.html -->
<footer class="footer">
<div class="d-sm-flex justify-content-center justify-content-sm-between">
<span class="text-muted text-center text-sm-left d-block d-sm-inline-block">Copyright © 2019 All rights reserved.</span>
<span class="float-none float-sm-right d-block mt-1 mt-sm-0 text-center">Hand-crafted & made with <i class="far fa-heart text-danger"></i></span>
</div>
</footer>
<!-- partial -->
</div>
<!-- main-panel ends -->
</div>
<!-- page-body-wrapper ends -->
</div>
<form action="dashboard.php" method="post" enctype="multipart/form-data" name="myform">
<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="ModalLabel">Edit User</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<input type="hidden" id="editid" name="editid">
<label for="username" class="col-form-label">Username:</label>
<input type="text" name="username" id="username" class="form-control">
</div>
<div class="form-group">
<label for="pwd" class="col-form-label">Password:</label>
<input type="password" class="form-control" name="pwd" id="pwd">
</div>
<div class="form-group">
<label for="fileupload" class="col-form-label">Choose File:</label>
<input type="file" name="fileupload" id="fileupload" class="form-control">
</div>
</div>
<div class="modal-footer">
<button type="button" onclick="filepost();" id="save" class="btn btn-success" data-dismiss="modal">Save</button>
<button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
</form>
<?php
if(isset($msg)){ // Check if $msg is not empty
echo "<script type='text/javascript'>alert(\"$msg\");</script>"; // Display our message
} ?>
<!-- container-scroller -->
<!-- plugins:js -->
<script src="assets/vendors/js/vendor.bundle.base.js"></script>
<script src="assets/vendors/js/vendor.bundle.addons.js"></script>
<!-- endinject -->
<!-- Plugin js for this page-->
<!-- End plugin js for this page-->
<!-- inject:js -->
<script src="assets/js/off-canvas.js"></script>
<script src="assets/js/hoverable-collapse.js"></script>
<script src="assets/js/template.js"></script>
<script src="assets/js/settings.js"></script>
<script src="assets/js/todolist.js"></script>
<!-- endinject -->
<!-- Custom js for this page-->
<script>
function filepost(){
var form = document.myform;
var editid = form.editid.value;
// console.log(editid);
form.submit();
// var username = $("#username").val();
// var pwd = $("#pwd").val();
// $.post('header.php',
// {
// edit_id:edit_id,
// username:username,
// pwd:pwd
// },
// function(data,status){
// console.log(data);
// }
// );
}
var table = $("#user");
//user deleting
table.on('click', '.delete', function (e) {
if (confirm("Are you sure to delete this user data ?") == false) {
return;
}
var nRow = $(this).parents('tr')[0];
del_id = nRow.id;
$.post('header.php',
{del_id:del_id},
function(data,status){
nRow.remove();
alert(status);
}
);
});
// user editing
table.on('click', '.edit', function (e) {
var nRow = $(this).parents('tr')[0];
edit_id = nRow.id;
// console.log(edit_id);
$.post('header.php',
{edit_id:edit_id},
function(data,status){
var obj = JSON.parse(data);
// console.log(obj[1]);
$("#editid").val(obj[0]);
$("#username").val(obj[1]);
$("#pwd").val(obj[2]);
}
);
});
// modified user data saveing
// $("#save").click(function(){
// var editid = $("#editid").val();
// var username = $("#username").val();
// var pwd = $("#pwd").val();
// // console.log(editid);
// $.post('header.php',
// {
// edit_id:edit_id,
// username:username,
// pwd:pwd
// },
// function(data,status){
// console.log(data);
// }
// );
// });
</script>
<!-- End custom js for this page-->
</body>
</html>