-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.php
422 lines (414 loc) · 30.4 KB
/
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
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
<?php
include('includes/include_once/session.php');
include('includes/include_once/header.php');
include('includes/include_once/nav.php');
?>
<div id="main-wrapper">
<div class="page-wrapper">
<div class="container-fluid">
<div class="row page-titles">
<div class="col-md-5 align-self-center">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="dash.php">Home</a></li>
<li class="breadcrumb-item active">Users</li>
</ol>
</div>
</div>
<div>
<p>
<button class="btn btn-primary" type="button" data-toggle="modal" data-target="#adduser" data-whatever="@mdo">
Add User
</button>
</p>
<div class="modal fade" id="adduser" tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add User</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="POST" action="process/userProcess.php">
<div class="form-row">
<div class="form-group col-md-6">
<label>Fullname<span style="color:red">*</span></label>
<input type="text" class="form-control" name="fname" required>
<p style="color: red;">Field cannot be empty</p>
</div>
<div class="form-group col-md-6">
<label>Contact Number<span style="color:red">*</span></label>
<input type="text" class="form-control" name="cntno" required>
<p style="color: red;">Field cannot be empty</p>
</div>
</div>
<div class="form-group">
<label>email<span style="color:red">*</span></label>
<input type="email" class="form-control" name="email" id="email" required onchange="validateE()">
<p style="color: red;">Field cannot be empty</p>
<p id="email-message"></p>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Password<span style="color:red">*</span></label>
<input type="text" class="form-control" name="password" id="password" autocomplete="false" required>
<p style="color: red;">Field cannot be empty</p>
</div>
<div class="form-group col-md-5">
<label>Want System To Generate Password ?</label>
<a class="btn btn-outline-danger" id="generatePassword">Generate</a>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6 progress">
<div class="progress-bar" role="progressbar" style="width: 0%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Confirm Password<span style="color:red">*</span></label>
<input type="password" class="form-control" name="cnfpass" id="cnfpass" onchange="matchPassword();" required>
<p id="password-wrong"></p>
<p style="color: red;">Field cannot be empty</p>
</div>
<div class="form-group col-md-3">
<label>User Type<span style="color:red">*</span></label>
<select class="form-control" name="usertype" required>
<option selected disabled>Choose...</option>
<option>Admin</option>
<option>Manager</option>
<option>Staff</option>
<option>User</option>
</select>
<p style="color: red;">Please select user type</p>
</div>
<div class="form-group col-md-3">
<label>Status<span style="color:red">*</span></label>
<select class="form-control" name="status" required>
<option selected disabled>Choose...</option>
<option>Active</option>
<option>Inactive</option>
</select>
<p style="color: red;">please select status</p>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="submit">Add User</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="edit_user_modal" tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add User</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="POST" action="process/userProcess.php" id="edit_user_form">
<div class="form-row">
<div class="form-group col-md-6">
<label>Fullname<span style="color:red">*</span></label>
<input type="text" class="form-control" name="fname" id="fname" required>
<p style="color: red;"></p>
</div>
<div class="form-group col-md-6">
<label>Contact Number<span style="color:red">*</span></label>
<input type="text" class="form-control" name="cntno" id="cntno" required>
<p style="color: red;"></p>
</div>
</div>
<div class="form-group">
<label>email<span style="color:red">*</span></label>
<input type="email" class="form-control" name="email" id="uemail" required onchange="validateE()">
<p id="email-message"></p>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Password<span style="color:red">*</span></label>
<input type="text" class="form-control" name="password" id="password" autocomplete="false" required>
<p style="color: red;"></p>
</div>
<div class="form-group col-md-5">
<label>Want System To Generate Password ?</label>
<a class="btn btn-outline-danger" id="generatePassword">Generate</a>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6 progress">
<div class="progress-bar" role="progressbar" style="width: 0%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Confirm Password<span style="color:red">*</span></label>
<input type="password" class="form-control" name="cnfpass" id="cnfpass" onchange="matchPassword();" required>
<p id="password-wrong"></p>
</div>
<div class="form-group col-md-3">
<label>User Type<span style="color:red">*</span></label>
<select class="form-control" name="usertype" id="role" required>
<option selected disabled>Choose...</option>
<option>Admin</option>
<option>Manager</option>
<option>Staff</option>
<option>User</option>
</select>
</div>
<div class="form-group col-md-3">
<label>Status<span style="color:red">*</span></label>
<select class="form-control" name="status" id="status" required>
<option selected disabled>Choose...</option>
<option>Active</option>
<option>Suspended</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="submit">Add User</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- ============================================================== -->
<script>
function random_password_generate(max, min)
{
var passwordChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%&*/()";
var randPwLen = Math.floor(Math.random() * (max - min + 1)) + min;
var randPassword = Array(randPwLen).fill(passwordChars).map(function (x) {
return x[Math.floor(Math.random() * x.length)]
}).join('');
return randPassword;
}
document.getElementById("generatePassword").addEventListener("click", function () {
random_password = random_password_generate(16, 8);
document.getElementById("password").value = random_password;
});
var percentage = 0;
function check(n, m) {
if (n < 6) {
percentage = 0;
$(".progress-bar").css("background", "#dd4b39");
} else if (n < 8) {
percentage = 20;
$(".progress-bar").css("background", "#9c27b0");
} else if (n < 10) {
percentage = 40;
$(".progress-bar").css("background", "#ff9800");
} else {
percentage = 60;
$(".progress-bar").css("background", "#4caf50");
}
// Check for the character-set constraints
// and update percentage variable as needed.
//Lowercase Words only
if ((m.match(/[a-z]/) != null))
{
percentage += 10;
}
//Uppercase Words only
if ((m.match(/[A-Z]/) != null))
{
percentage += 10;
}
//Digits only
if ((m.match(/0|1|2|3|4|5|6|7|8|9/) != null))
{
percentage += 10;
}
//Special characters
if ((m.match(/\W/) != null) && (m.match(/\D/) != null))
{
percentage += 10;
}
// Update the width of the progress bar
$(".progress-bar").css("width", percentage + "%");
}
// Update progress bar as per the input
$(document).ready(function () {
// Whenever the key is pressed, apply condition checks.
$("#password").keyup(function () {
var m = $(this).val();
var n = m.length;
// Function for checking
check(n, m);
});
});
// ---------------------------------- Password match --------------------------
function matchPassword() {
var x = document.getElementById("password");
var y = document.getElementById("cnfpass");
if (x.value == y.value) {
document.getElementById("password-wrong").innerHTML = 'Password match';
document.getElementById("password-wrong").style.color = "green";
} else {
document.getElementById("password-wrong").innerHTML = 'Password do not match';
document.getElementById("password-wrong").style.color = "red";
}
}
// ------------------------------------- Email Validation
function validateEmail() {
var email = document.getElementById("email").value;
if (email.indexOf('@') <= 0) {
document.getElementById('email-message').innerHTML = "Invalid email address";
return false;
} else if ((email.charAt(email.length - 4) != '.') && (email.charAt(email.length - 3) != '.')) {
document.getElementById('email-message').innerHTML = "Invalid email address";
return false;
} else {
document.getElementById('email-message').innerHTML = "";
}
}
</script>
<!-- ============================================================== -->
<div class="row">
<!-- Column -->
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<div class="d-flex">
<div class="table-responsive m-t-20 no-wrap">
<table id="example" class="table vm no-th-brd pro-of-month" style="width:100%">
<thead>
<tr>
<th>Sr. No.</th>
<!--<th>Profile</th>-->
<th>Name</th>
<th>Email</th>
<th>Contact No.</th>
<th>Role</th>
<th>Account Status</th>
</tr>
</thead>
<tbody>
<?php
$sr = 0;
include('includes/include_once/db.php');
$data = "SELECT * FROM users";
$query = mysqli_query($connect, $data);
while ($result = mysqli_fetch_assoc($query)) {
// print_r($result);
// exit();
?>
<tr>
<td><?php echo ++$sr; ?></td>
<!--<td style="width:50px;"><img class="round" src="<?php //echo 'images/' . $result['profile_image']; ?>" > </td>-->
<td>
<h6><?php echo $result['fullName']; ?></h6><small class="text-muted"><?php //echo $result['dob']; ?></small>
</td>
<td><h6><?php echo $result['email']; ?></h6></td>
<td><?php echo $result['contactNo']; ?></td>
<td><?php echo $result['role']; ?></td>
<td><?php echo $result['status']; ?></td>
<td class="table-action">
<a class="fa fa-pencil-square-o btn btn-outline-primary edit_user_data<?php echo $result['uID']; ?>" data-toggle="tooltip" onclick="showModal(this)" name="edit_user" id="<?php echo $result['uID']; ?>"></a>
<span data-toggle="modal" data-target="#suspendModel"><a class="fa fa-ban btn btn-outline-warning" value="<?php echo $result['uID']; ?>" onclick="suspend(<?php echo $result['uID']; ?>)" type="button" data-toggle="tooltip" data-placement="right" title="suspend"></a></span>
<span data-toggle="modal" data-target="#deleteModel"><a class="fa fa-trash btn btn-outline-danger" value="<?php echo $result['uID']; ?>" onclick="myButton(<?php echo $result['uID']; ?>)" type="button" data-toggle="tooltip" data-placement="right" title="Delete"></a></span>
<!-- Modal -->
<div class="modal fade" id="deleteModel" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Delete User</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"></button>
</div>
<form action="process/userProcess.php" id="deleteForm" method="POST">
<div class="modal-body">
<h3>Are You Sure You Want To Delete ?</h3>
<h5>Once you delete the account account, you won't able to<br> recover it back.</h5>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="delete">Yes ! Delete</button>
</div>
</form>
<script>
function myButton(id) {
//alert(document.getElementById("deleteForm").action);
document.getElementById("deleteForm").action = "process/userProcess.php?id=" + id;
}
//---------------------- edit user ----------------------
function showModal(e){
//alert('hello');
//e.preventDefault();
var edit_id = $(e).attr('id');
document.getElementById("edit_user_form").action = "process/userProcess.php?id=" + edit_id;
//alert(pay_id);
$.ajax({
url:'https://localhost/caldikind/process/userProcess.php',
type:'POST',
data:{edit_id:edit_id},
success:function(data){
//alert(data);
var output = JSON.parse(data);
//alert(output.name);
$('#id').val(output.id);
$('#fname').val(output.name);
$('#cntno').val(output.contactNo);
$('#uemail').val(output.email);
$('#role').val(output.role);
$('#status').val(output.status);
jQuery.noConflict();
$("#edit_user_modal").modal('show');
}
})}
</script>
</div>
</div>
</div>
<div class="modal fade" id="suspendModel" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Suspend Account</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"></button>
</div>
<form action="process/userProcess.php" id="suspendForm" method="POST">
<div class="modal-body">
<h4>Are You Sure You Want To Suspend This Account ?</h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="suspend">Suspend</button>
</div>
</form>
<script>
function suspend(id) {
//alert(document.getElementById("deleteForm").action);
document.getElementById("suspendForm").action = "process/userProcess.php?id=" + id;
}
</script>
</div>
</div>
</div>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<footer class="footer"><img src="images/logo/logo3.png" class="my-logo" /> Made by <a href="https://tryon.caldikind.xyz">Group 7</a> </footer>
</div>
<?php
include('includes/include_once/footer.php');
?>