-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmanageuser_update.php
526 lines (481 loc) · 24 KB
/
manageuser_update.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
<style>
body {
background-color: white;
}
.pagination {
display: flex;
justify-content: center;
padding-top: 30px;
padding-bottom: 30px;
}
.pagination a {
color: white;
float: left;
padding: 8px 16px;
text-decoration: none;
transition: background-color .3s;
border: 1px solid #ddd;
}
.pagination a.active {
background-color: #4CAF50;
color: white;
border: 1px solid #4CAF50;
}
.pagination a:hover:not(.active) {
background-color: #ddd;
}
.form-group-search {
margin-left: 8%;
}
.form-label-s {
width: 380px;
height: 30px;
margin: 5px 0px 5px 2%;
/* style="width: 80px; height: 34px"; */
}
#btn_search {
width: 80px;
height: 34px;
border: 1px solid #777;
background-color: #FB8122;
color: #fff;
}
#btn_search:hover {
transition: 0.3s;
cursor: pointer;
}
@media screen and (max-width: 900px) {
.form-group-search {
margin-left: 8%;
}
.form-label-s {
width: 230px;
height: 22px;
margin: 5px 0px 5px 2%;
/* style="width: 80px; height: 34px"; */
}
#btn_search {
width: 60px;
height: 26px;
border: 1px solid #777;
background-color: #FB8122;
color: #fff;
}
#btn_search:hover {
transition: 0.3s;
cursor: pointer;
}
}
</style>
<!-- body -->
<div id="manage-container">
<p class="head-label">Manage User</p>
<div class="detail-mn">
<script type="text/javascript">
function confirm_delete() {
return confirm('Are you sure?');
}
</script>
<!-- modal -->
<div class="modal js-modal open">
<form id="form-update" class="modal-container js-modal-container" action="manageuserpro.php?function=update" method="POST">
<?php
include_once("connectDB.php");
if (isset($_GET['stuid'])) {
$id = $_GET['stuid'];
$result = mysqli_query($conn, "SELECT *FROM users where StudentID='$id'");
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
}
?>
<div class="modal-header">
<div class="modal-label">
<p> User Info </p>
</div>
<div class="model-close js-modal-close">
<i class=" icon-close">x</i>
</div>
</div>
<div class="modal-body">
<div class="modal-input">
<div class="form-group">
<input value="<?php echo $row['id']; ?>" type="hidden" name="id" id="id" class="input-info">
<input value="<?php echo $row['username']; ?>" type="text" name="username" id="username" class="input-info" placeholder="UserName">
<p class="error" style="margin-bottom: 0;"></p>
</div>
<div class="form-group">
<input value="<?php echo $row['StudentID']; ?>" type="text" name="stid" id="stid" class="input-info" placeholder="StudentID.....">
<p class="error" style="margin-bottom: 0;"></p>
</div>
<div class="form-group">
<input value="<?php echo $row['email']; ?>" type="text" id="email" name="email" class="input-info" placeholder="User email,....">
<p class="error" style="margin-bottom: 0;"></p>
</div>
<div class="form-group">
<input value="<?php echo $row['card_uid']; ?>" type="number" id="card_id" name="cart_id" class="input-info" placeholder="CardID,....">
<p class="error" style="margin-bottom: 0;"></p>
</div>
<div class="form-group">
<input value="<?php echo $row['user_date']; ?>" type="date" id="dob" name="dob" class="input-info" placeholder="DoB,...." style="padding-left: 10px;">
<p class="error" style="margin-bottom: 0;"></p>
</div>
<div class="form-group">
<input value="<?php echo $row['github']; ?>" type="text" id="github" name="github" class="input-info" placeholder="Github,...." style="padding-left: 10px;">
<p class="error" style="margin-bottom: 0;"></p>
</div>
</div>
<div class="modal-sublabel">
<h4>Additional Info</h4>
</div>
<label class="department-label">User Department:</label>
<div class="modal-input">
<!-- Display current department -->
<select class="input-info" placeholder="Department" name="department" id="department">
<?php $department = array(
"<option value='Font-end'>Font-end</option>",
"<option value='Back-end'>Back-end</option>",
"<option value='Design'>Design</option>",
"<option value='Media'>Media</option>",
"<option value='Network'>Network</option>"
) ?>
<?php
$depart = $row['Department'];
switch ($depart) {
case "Font-end":
echo $department[0];
echo $department[1];
echo $department[2];
echo $department[3];
echo $department[4];
break;
case "Back-end":
echo $department[1];
echo $department[0];
echo $department[2];
echo $department[3];
echo $department[4];
break;
case "Design":
echo $department[2];
echo $department[1];
echo $department[0];
echo $department[3];
echo $department[4];
break;
case "Media":
echo $department[3];
echo $department[0];
echo $department[2];
echo $department[1];
echo $department[4];
break;
case "Network":
echo $department[3];
echo $department[0];
echo $department[2];
echo $department[1];
echo $department[4];
break;
default:
echo $department[3];
echo $department[0];
echo $department[2];
echo $department[1];
echo $department[4];
break;
}
?>
</select>
</div>
<label class="department-label">Gender:</label>
<div class="gender">
<?php if ($row['gender'] == 'male') {
echo '<input type="radio" name="gender" value="male" checked> <span>Male</span>';
echo ' <input type="radio" name="gender" value="female"> <span>Female</span>';
} else {
echo '<input type="radio" name="gender" value="male"> <span>Male</span>';
echo ' <input type="radio" name="gender" value="female" checked> <span>Female</span>';
}
?>
</div>
</div>
<div class="modal-footer">
<div class="button">
<button type="submit" id="btn-update" name="btn-update" class="modal-button">Update User</button>
<a style="text-align: center; background-color: red; font-size: 14px; text-decoration: none; color:black" href="?page=manageuserpro&&stid=<?php echo $row['StudentID']; ?>" onclick="return confirm_delete()" id="btn-delete" name="btn-delete" class="modal-button">Remove User</a>
</div>
</div>
</form>
</div>
<!-- finish modal -->
<!-- /model adduser -->
<div class="modaluser js-modal-user">
<form id="form-add" name="form-add" class="modal-container js-modal-container-user" action="manageuserpro.php?function=add" method="POST">
<div class="modal-header">
<div class="modal-label">
<p> User Info </p>
</div>
<div class="model-close js-modal-close-user">
<i class=" icon-close">x</i>
</div>
</div>
<div class="modal-body">
<div class="modal-input">
<div class="form-group">
<input type="text" name="username" id="username" class="input-info" placeholder="UserName">
<p class="error" style="margin-bottom: 0;"></p>
</div>
<div class="form-group">
<input type="text" name="stid" id="stid" class="input-info" placeholder="StudentID.....">
<p class="error" style="margin-bottom: 0;"></p>
</div>
<div class="form-group">
<input type="text" id="email" name="email" class="input-info" placeholder="User email,....">
<p class="error" style="margin-bottom: 0;"></p>
</div>
<div class="form-group">
<input type="number" id="card_id" name="cart_id" class="input-info" placeholder="CardID,....">
<p class="error" style="margin-bottom: 0;"></p>
</div>
<div class="form-group">
<input type="date" id="dob" name="dob" class="input-info" placeholder="DoB,...." style="padding-left: 10px;">
<p class="error" style="margin-bottom: 0;"></p>
</div>
<div class="form-group">
<input type="text" id="github" name="github" class="input-info" placeholder="Github,...." style="padding-left: 10px;">
<p class="error" style="margin-bottom: 0;"></p>
</div>
</div>
<div class="modal-sublabel">
<h4>Additional Info</h4>
</div>
<label class="department-label">User Department:</label>
<div class="modal-input">
<select class="input-info" name="department" id="department" placeholder="Department">
<option value="1">All Department</option>
<option value="Font-end">Font-end</option>
<option value="Back-end">Back-end</option>
<option value="Design">Design</option>
<option value="Media">Media</option>
</select>
</div>
<label class="department-label">Gender:</label>
<div class="gender">
<input type="radio" name="gender" value="male" checked> <span>Male</span>
<input type="radio" name="gender" value="female"> <span>Female</span>
</div>
</div>
<div class="modal-footer">
<div class="button">
<button type="submit" name="btn_add" id="btn_add" class="modal-button">Add User</button>
</div>
</div>
</form>
</div>
<!-- finish modal user -->
<div>
<form action="" method="POST">
<div class="form-group-search">
<input type="text" name="id" placeholder="" class="form-label-s">
<button type="submit" name="btn_search" id="btn_search">Search</button>
</div>
<!-- <div class="btn-add1">
<button class="add-user js-add-user" style="width: 80px; height: 30px"> Add new</button>
</div> -->
</form>
</div>
<div class="detail-right">
<div class="table-1">
<table class="table">
<thead class="table-head">
<tr>
<th>ID | Name</th>
<th>Department</th>
<th>Gender</th>
<th>Card UID</th>
<th>DoB</th>
<th>Github</th>
<th>Email</th>
<th>Total Score</th>
</tr>
</thead>
<tbody class="table-body">
<?php
include_once('connectDB.php');
$currentDate = date('Y-m-d', time());
$month = date('m', strtotime($currentDate));
if (isset($_POST['btn_search'])) {
$id = $_POST['id'];
$results_per_page = 10;
// find out the number of results stored in database
$sql = "SELECT * FROM users WHERE StudentID like '%$id%' or username like '%$id%'";
$result = mysqli_query($conn, $sql);
$number_of_results = mysqli_num_rows($result);
// determine number of total pages available
(int)$number_of_pages = ceil($number_of_results / $results_per_page);
// determine which page number visitor is currently on
if (!isset($_GET['pages'])) {
$page = 1;
} else {
$page = $_GET['pages'];
}
// determine the sql LIMIT starting number for the results on the displaying page
$this_page_first_result = 0;
$sql1 = "SELECT * FROM users WHERE StudentID like '%$id%' or username like '%$id%' LIMIT " . $this_page_first_result . ',' . $results_per_page;
$result = mysqli_query($conn, $sql1);
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$name = $row['username'];
$sql = "SELECT SUM(scores) as score FROM `users_logs` WHERE username='$name' and month(checkindate) = '$month'";
$result_score = mysqli_query($conn, $sql);
$score = mysqli_fetch_array($result_score);
// echo $score['score'];
?>
<tr>
<td>
<a href="?page=manageuser_update&&stuid=<?php echo $row['StudentID']; ?>" class="update-name js-update-name"> <?php echo $row['StudentID']; ?> | <?php echo $row['username']; ?> </a>
</td>
<td> <?php echo $row['Department']; ?> </td>
<td> <?php echo $row['gender']; ?> </td>
<td> <?php echo $row['card_uid']; ?> </td>
<td> <?php echo $row['user_date']; ?> </td>
<td> <?php echo $row['github']; ?> </td>
<td> <?php echo $row['email']; ?> </td>
<td> <?php echo $score['score']; ?> </td>
</tr>
<?php }
} else {
$results_per_page = 15;
// find out the number of results stored in database
$sql = 'SELECT * FROM users';
$result = mysqli_query($conn, $sql);
$number_of_results = mysqli_num_rows($result);
// determine number of total pages available
(int)$number_of_pages = ceil($number_of_results / $results_per_page);
// determine which page number visitor is currently on
if (!isset($_GET['pages'])) {
$page = 1;
} else {
$page = $_GET['pages'];
}
// determine the sql LIMIT starting number for the results on the displaying page
$this_page_first_result = ($page - 1) * $results_per_page;
$sql1 = 'SELECT * FROM users LIMIT ' . $this_page_first_result . ',' . $results_per_page;
$result = mysqli_query($conn, $sql1);
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$name = $row['username'];
$sql = "SELECT SUM(scores) as score FROM `users_logs` WHERE username='$name' and month(checkindate) = '$month'";
$result_score = mysqli_query($conn, $sql);
$score = mysqli_fetch_array($result_score);
?>
<tr>
<td>
<a href="?page=manageuser_update&&stuid=<?php echo $row['StudentID']; ?>" class="update-name js-update-name"> <?php echo $row['StudentID']; ?> | <?php echo $row['username']; ?> </a>
</td>
<td> <?php echo $row['Department']; ?> </td>
<td> <?php echo $row['gender']; ?> </td>
<td> <?php echo $row['card_uid']; ?> </td>
<td> <?php echo $row['user_date']; ?> </td>
<td> <?php echo $row['github']; ?> </td>
<td> <?php echo $row['email']; ?> </td>
<td> <?php echo $score['score']; ?> </td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<div class="pagination">
</br>
</br>
<?php
// display the links to the pages
if ($number_of_pages > 1) {
for ($i = 1; $i <= $number_of_pages; $i++) {
if ($i == $page) {
echo '<span style="background-color:#ccc;padding: 8px 16px; float:left;">' . $i . '</span> ';
} else {
echo '<a href="admin.php?page=manageuser&&pages=' . $i . '"><div class="pag-number">' . $i . '</div></a> ';
}
}
}
?>
</div>
</div>
</div>
</div>
</div>
<script script>
const editInfors = document.querySelectorAll('.js-update-name') //sellect the class use to use js
const modalclose = document.querySelector('.js-modal-close')
const modal = document.querySelector('.js-modal')
const modalcontainer = document.querySelector('.js-modal-container')
function showModal() {
modal.classList.add('open')
}
for (const editInfor of editInfors) {
editInfor.addEventListener('click', showModal)
}
function hideModal() {
modal.classList.remove('open')
}
modalclose.addEventListener('click', hideModal)
modal.addEventListener('click', hideModal)
modalcontainer.addEventListener('click', function(event) {
event.stopPropagation() //stop nổi bọt
})
const addUsers = document.querySelectorAll('.js-add-user') //sellect the class use to use js
const modalcloseUser = document.querySelector('.js-modal-close-user')
const modalUser = document.querySelector('.js-modal-user')
const modalcontainerUser = document.querySelector('.js-modal-container-user')
function showModalAdd() {
modalUser.classList.add('open')
}
for (const addUser of addUsers) {
addUser.addEventListener('click', showModalAdd)
}
function hideModalAdd() {
modalUser.classList.remove('open')
}
modalcloseUser.addEventListener('click', hideModalAdd)
modalUser.addEventListener('click', hideModalAdd)
modalcontainerUser.addEventListener('click', function(event) {
event.stopPropagation() //stop nổi bọt
})
</script>
<script src="./js/validator_all.js"></script>
<script>
Validator({
form: '#form-add',
formGroupSelector: '.form-group',
errorSelector: '.error',
rules: [
Validator.isRequired('#username', 'This field can not empty'),
Validator.isRequired('#stid', 'This field can not empty'),
Validator.isRequired('#email', 'This field can not empty'),
Validator.isRequired('#card_id', 'This field can not empty'),
Validator.isRequired('#dob', 'this feild can not empty'),
Validator.isRequired('#github', 'This field can not empty'),
Validator.isEmail('#email', 'Invalid email'),
],
// onSubmit: function(data) {
// console.log(data)
// }
});
Validator({
form: '#form-update',
formGroupSelector: '.form-group',
errorSelector: '.error',
rules: [
Validator.isRequired('#username', 'This field can not empty'),
Validator.isRequired('#stid', 'This field can not empty'),
Validator.isRequired('#email', 'This field can not empty'),
Validator.isRequired('#card_id', 'This field can not empty'),
Validator.isRequired('#dob', 'this feild can not empty'),
Validator.isRequired('#github', 'This field can not empty'),
Validator.isEmail('#email', 'Invalid email'),
],
// onSubmit: function(data) {
// console.log(data)
// }
});
</script>