-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall_users.php
More file actions
452 lines (406 loc) · 21.9 KB
/
all_users.php
File metadata and controls
452 lines (406 loc) · 21.9 KB
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
<?php include("includes/header.php");
$sql = "SELECT * FROM master_admin WHERE is_active = '1'";
$query = $db->query($sql);
if (empty($_SESSION['session'])) {
header("Location:index.php");
} else {
if(!empty($_SESSION['type'] != "ADM")){
header("Location:dashboard.php");
}
if (!empty($_SESSION['session'])) {
if (!empty($_SESSION['type'] == "ADM")) {
//delete
if (!empty($_GET['del'])) {
$query = $db->prepare("delete from master_admin WHERE master_id = :dl");
$delete = $query->execute(array('dl' => $_GET['del']));
header("Location: all_users.php");
}
//activate
if (!empty($_GET['ac'])) {
$query = $db->prepare("update master_admin set access_status = '1' WHERE master_id = :ac");
$delete = $query->execute(array('ac' => $_GET['ac']));
header("Location: all_users.php");
}
//deactivate
if (!empty($_GET['dac'])) {
$query = $db->prepare("update master_admin set access_status = '0' WHERE master_id = :dac");
$delete = $query->execute(array('dac' => $_GET['dac']));
header("Location: all_users.php");
}
//insert
if (!empty($_POST['add_user'])) {
if(trim($_POST['password'])=='' OR empty($_POST)) {
echo "Password empty!";
} elseif (strlen($_POST['password']) < 5) {
$errMSGs = "<strong>Error!</strong> The password must be at least 5 characters.";
} elseif ( ! preg_match('#[0-9]+#', $_POST['password'])) {
$errMSGs = "<strong>Error!</strong> The password must contain at least 1 number.";
} elseif ( ! preg_match('#[A-Z]+#', $_POST['password'])) {
$errMSGs = "<strong>Error!</strong> The password should contain at least 1 uppercase character.";
} elseif ( ! preg_match('#[a-z]+#', $_POST['password'])) {
$errMSGs = "<strong>Error!</strong> The password must contain at least 1 lowercase letter.";
} else {
$password = md5($_POST['password']);
$reg_date = date('Y-m-d H:i:s');
$control = $db->prepare("Select * from master_admin where email = ? or phone = ? ");
$control->execute(array($_POST['email'], $_POST['phone']));
if($control->rowCount()){
$errMSGs = "<strong>Truncate!</strong> This email or phone has already been used.";
} else {
$add_role = $db->prepare("INSERT INTO master_admin SET type = ?, f_name = ?, l_name = ?, email = ?, phone = ?, password = ?, gender = ?, gst = ?, company_name = ?, address = ?, reg_date = ?");
$add_role->execute(array($_POST['user_type'],$_POST['f_name'],$_POST['l_name'],$_POST['email'],$_POST['phone'],md5($_POST['password']),$_POST['gender'],$_POST['gst'],$_POST['company_name'],$_POST['address'],$reg_date));
if ($add_role->rowCount()) {
$fname = trim($_POST["f_name"]);
$lname = trim($_POST["l_name"]);
$phone = trim($_POST["phone"]);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$password = $_POST["password"];
//email
$mail_to = $email;
# Sender Data
$subject = "Welcome | Omega Enterprises";
# Mail Content
$content = "Your Login Details are below:\n";
$content .= "Email: $email\n";
$content .= "Password: $password\n";
# email headers.
$headers = "From: $fname $lname <$email>" . "\r\n";
# Send the email.
$success = mail($mail_to, $subject, $content, $headers);
if ($success) {
# Set a 200 (okay) response code.
http_response_code(200);
$successMSG = "<strong>Success!</strong> New User Added. Relaod Page.";
header("Location: all_users.php");
} else {
# Set a 500 (internal server error) response code.
http_response_code(500);
$errMSGs = "User was added but could not send Email Notification! Contact your service provider.";
}
} else {
$errMSGs = "Cannot Update! Contact your service provider.";
}
}
}
} else {}
//update
if (!empty($_POST['edit_user'])) {
$update = "UPDATE master_admin SET type = :typ, f_name =:fnm, l_name =:lmn, phone = :ph, gender =:gn, gst =:gt, company_name =:cname, address =:add WHERE master_id = :d";
$stmt = $db->prepare($update);
$stmt->bindParam(':typ', $_POST['user_type'], PDO::PARAM_STR);
$stmt->bindParam(':fnm', $_POST['f_name'], PDO::PARAM_STR);
$stmt->bindParam(':lmn', $_POST['l_name'], PDO::PARAM_STR);
$stmt->bindParam(':ph', $_POST['phone'], PDO::PARAM_STR);
$stmt->bindParam(':gn', $_POST['gender'], PDO::PARAM_STR);
$stmt->bindParam(':gt', $_POST['gst'], PDO::PARAM_STR);
$stmt->bindParam(':cname', $_POST['company_name'], PDO::PARAM_STR);
$stmt->bindParam(':add', $_POST['address'], PDO::PARAM_STR);
$stmt->bindParam(':d', $_POST['master_id'], PDO::PARAM_INT);
if ($stmt->execute()) {
$successMSG = "User Updated Successfully. Relaod Page.";
header("Location: all_users.php");
} else {
$errMSGs = "Cannot Update! Contact your service provider.";
}
}else{}
//update end
if(isset($_POST['change_pass'])){
if(trim($_POST['new_password'])==''OR empty($_POST)) {
$errMSGs = "New password empty!";
} elseif(trim($_POST['confirm_new_password'])=='' OR empty($_POST)) {
$errMSGs = "Confirm new password empty!";
} elseif (strlen($_POST['new_password']) < 5) {
$errMSGs = "The new password must be at least 5 characters!";
} elseif (strlen($_POST['confirm_new_password']) < 5) {
$errMSGs = "The confirm new password must be at least 5 characters!";
} elseif ( ! preg_match('#[0-9]+#', $_POST['new_password'])) {
$errMSGs = "The new password must contain at least 1 number!";
} elseif ( ! preg_match('#[0-9]+#', $_POST['confirm_new_password'])) {
$errMSGs = "The confirm new password must contain at least 1 number!";
} elseif ( ! preg_match('#[A-Z]+#', $_POST['new_password'])) {
$errMSGs = "The new password should contain at least 1 uppercase character!";
} elseif ( ! preg_match('#[A-Z]+#', $_POST['confirm_new_password'])) {
$errMSGs = "The confirm new password should contain at least 1 uppercase character!";
} elseif ( ! preg_match('#[a-z]+#', $_POST['new_password'])) {
$errMSGs = "The new password must contain at least 1 lowercase letter!";
} elseif ( ! preg_match('#[a-z]+#', $_POST['confirm_new_password'])) {
$errMSGs = "The confirm new password must contain at least 1 lowercase letter!";
} else {
if (md5($_POST['new_password']) != md5($_POST['confirm_new_password'])) {
$errMSGs = "New passwords are not equal!";
} else {
$new_password = md5($_POST['new_password']);
$updater = "UPDATE master_admin SET password = :password WHERE master_id = :d";
$passwo = $db->prepare($updater);
$passwo->bindParam(':password', $new_password, PDO::PARAM_STR);
$passwo->bindParam(':d', $_POST['master_id'], PDO::PARAM_INT);
if($passwo->execute()) {
$successMSG = "Password Changed Successfully";
} else {
$errMSGs = "Try again later!";
}
}
}
}
}
?>
<div class="row layout-top-spacing" id="cancel-row">
<div class="col-xl-12 col-lg-12 col-sm-12 layout-spacing">
<div class="widget-content widget-content-area br-6">
<div class="row">
<div class="col-lg-8 col-12 mx-auto">
<?php if (!empty($successMSG)) {
echo '<div class="alert alert-success mb-4 alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true"><button type="button" class="close" data-dismiss="alert" aria-label="Close"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x close" data-dismiss="alert"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg></button>'.$successMSG.'</div>';
}
if (!empty($errMSGs)) {
echo '<div class="alert alert-danger mb-4 alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true"><button type="button" class="close" data-dismiss="alert" aria-label="Close"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x close" data-dismiss="alert"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg></button>'.$errMSGs.'</div>';
} ?>
</div>
</div>
<!--<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addRole">Add New User</button>-->
<!-- Add Modal -->
<div class="modal fade" id="addRole" tabindex="-1" role="dialog" aria-labelledby="addModal" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addModal">Add New User</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
</button>
</div>
<div class="modal-body">
<form method="POST">
<div class="form-row">
<div class="form-group col-md-4">
<label>User Role *</label>
<select name="user_type" class="selectpicker form-control" required>
<option value="">Choose...</option>
<option value="ADM">Admin</option>
<option value="EMP">Employee</option>
<option value="CUST">Customer</option>
</select>
</div>
<div class="form-group col-md-4">
<label>First Name *</label>
<input type="text" class="form-control" name="f_name" required>
</div>
<div class="form-group col-md-4">
<label>Last Name *</label>
<input type="text" class="form-control" name="l_name" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Email *</label>
<input type="email" class="form-control" name="email" required>
</div>
<div class="form-group col-md-6">
<label>Password *</label>
<input type="password" class="form-control" name="password" required>
</div>
<div class="mt-1 col-md-12 mb-4">
<span class="badge badge-primary w-100">
<small id="sh-text7" class="form-text mt-0 text-left">The password must be at least 5 characters.</small>
<small id="sh-text7" class="form-text mt-0 text-left">The password must contain at least 1 number.</small>
<small id="sh-text7" class="form-text mt-0 text-left">The password should contain at least 1 uppercase character.</small>
<small id="sh-text7" class="form-text mt-0 text-left">The password should contain at least 1 lowercase character.</small>
</span>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Phone *</label>
<input type="text" class="form-control" name="phone" required>
</div>
<div class="form-group col-md-6">
<label>Gender *</label>
<select type="text" class="selectpicker form-control" name="gender" required>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Company Name</label>
<input type="text" class="form-control" name="company_name">
</div>
<div class="form-group col-md-6">
<label>GST No.</label>
<input type="text" class="form-control" name="gst">
</div>
</div>
<div class="form-group">
<label>Address *</label>
<textarea type="text" class="form-control" name="address" required ></textarea>
</div>
<input type="submit" class="btn btn-primary btn-sm mt-3" value="Add" name="add_user">
</form>
</div>
</div>
</div>
</div>
<div class="table-responsive">
<?php if ($query->rowCount()) { ?>
<table id="zero-config-users" class="table table-hover non-hover" style="width:100%">
<thead>
<tr>
<th>ID</th>
<th>Reg. Date</th>
<th>Type</th>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Gender</th>
<th>Company Name</th>
<th>GST</th>
<th>Address</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($query as $row) { ?>
<tr>
<td><?php echo $row['master_id']; ?></td>
<td><?php echo $row['reg_date']; ?></td>
<td><?php echo $row['type']; ?></td>
<td><?php echo $row['f_name']; ?> <?php echo $row['l_name']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['phone']; ?></td>
<td><?php echo $row['gender']; ?></td>
<td><?php echo $row['company_name']; ?></td>
<td><?php echo $row['gst']; ?></td>
<td><?php echo $row['address']; ?></td>
<td>
<?php if($row['type'] == 'ADM'){}else{
if($row['access_status'] == '1'){?>
<a href="all_users.php?dac=<?php echo $row['master_id']; ?>" onClick="return confirm('Are you sure?');" class="badge badge-danger">Deactivate</a>
<?php } else { ?>
<a href="all_users.php?ac=<?php echo $row['master_id']; ?>" onClick="return confirm('Are you sure?');" class="badge badge-success">Activate</a>
<?php } }?>
</td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-dark btn-sm">Open</button>
<button type="button" class="btn btn-dark btn-sm dropdown-toggle dropdown-toggle-split" id="dropdownMenuReference1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-reference="parent">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-down"><polyline points="6 9 12 15 18 9"></polyline></svg>
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuReference1">
<a class="dropdown-item" data-toggle="modal" data-target="#editUser<?php echo $row['master_id']; ?>">Edit Details</a>
<a class="dropdown-item" data-toggle="modal" data-target="#editPassword<?php echo $row['master_id']; ?>">Reset Password</a>
<a class="dropdown-item" href="all_users.php?del=<?php echo $row['master_id']; ?>" onClick="return confirm('Are you sure you want to delete?');">Delete</a>
</div>
</div>
<!-- Edit Modal -->
<div class="modal fade" id="editUser<?php echo $row['master_id']; ?>" tabindex="-1" role="dialog" aria-labelledby="editingModal<?php echo $row['master_id']; ?>" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editingModal<?php echo $row['master_id']; ?>">Edit User #<?php echo $row['master_id']; ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
</button>
</div>
<div class="modal-body">
<form method="POST">
<input type="hidden" name="master_id" value="<?php echo $row['master_id']; ?>">
<div class="form-row">
<div class="form-group col-md-4">
<label>User Role *</label>
<select name="user_type" class="form-control" required>
<option value="ADM" <?php if($row['type'] == "ADM"){echo'selected';}?>>Admin</option>
<option value="EMP" <?php if($row['type'] == "EMP"){echo'selected';}?>>Employee</option>
<option value="CUST" <?php if($row['type'] == "CUST"){echo'selected';}?>>Customer</option>
</select>
</div>
<div class="form-group col-md-4">
<label>First Name *</label>
<input type="text" class="form-control" name="f_name" value="<?php echo $row['f_name']; ?>" required>
</div>
<div class="form-group col-md-4">
<label>Last Name *</label>
<input type="text" class="form-control" name="l_name" value="<?php echo $row['l_name']; ?>" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Phone *</label>
<input type="text" class="form-control" name="phone" value="<?php echo $row['phone']; ?>" required>
</div>
<div class="form-group col-md-6">
<label>Gender *</label>
<select type="text" class="form-control" name="gender" required>
<option value="Male" <?php if($madmin['gender'] == 'Male'){ echo 'selected="selected"';}else{} ?>>Male</option>
<option value="Female" <?php if($madmin['gender'] == 'Female'){ echo 'selected="selected"';}else{} ?>>Female</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Company Name</label>
<input type="text" class="form-control" name="company_name" value="<?php echo $row['company_name']; ?>">
</div>
<div class="form-group col-md-6">
<label>GST No.</label>
<input type="text" class="form-control" name="gst" value="<?php echo $row['gst']; ?>">
</div>
</div>
<div class="form-group">
<label>Address *</label>
<textarea type="text" class="form-control" name="address" required ><?php echo $row['address']; ?></textarea>
</div>
<input type="submit" class="btn btn-primary mt-3" value="Update" name="edit_user">
</form>
</div>
</div>
</div>
</div>
<!-- Edit Modal -->
<div class="modal fade" id="editPassword<?php echo $row['master_id']; ?>" tabindex="-1" role="dialog" aria-labelledby="editingModal2<?php echo $row['master_id']; ?>" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editingModal2<?php echo $row['master_id']; ?>">Reset Password #<?php echo $row['master_id']; ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
</button>
</div>
<div class="modal-body">
<form method="POST">
<input type="hidden" name="master_id" value="<?php echo $row['master_id']; ?>">
<div class="form-group">
<label>New Password *</label>
<input type="password" name="new_password" class="form-control" required>
</div>
<div class="form-group">
<label>Confirm Password *</label>
<input type="password" name="confirm_new_password" class="form-control" required>
</div>
<input type="submit" class="btn btn-primary mt-3" value="Update" name="change_pass">
</form>
<div class="mt-4 mb-1">
<span class="badge badge-info w-100">
<small id="sh-text7" class="form-text mt-0 text-left">The new password must be at least 5 characters.</small>
<small id="sh-text7" class="form-text mt-0 text-left">The new password must contain at least 1 number.</small>
<small id="sh-text7" class="form-text mt-0 text-left">The new password should contain at least 1 uppercase character.</small>
<small id="sh-text7" class="form-text mt-0 text-left">The new password should contain at least 1 lowercase character.</small>
</span>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } else { echo '<br><p>There were no results</p>'; } ?>
</div>
</div>
</div>
</div>
<?php } } include("includes/footer.php"); ?>