-
Notifications
You must be signed in to change notification settings - Fork 7
/
manage_user.php
75 lines (74 loc) · 2.31 KB
/
manage_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
<?php
include('db_connect.php');
if(isset($_GET['id'])){
$user = $conn->query("SELECT * FROM users where id =".$_GET['id']);
foreach($user->fetch_array() as $k =>$v){
$meta[$k] = $v;
}
}
?>
<div class="container-fluid">
<form action="" id="manage-user" autocomplete="off">
<input type="hidden" name="id" value="<?php echo isset($meta['id']) ? $meta['id']: '' ?>">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" id="name" class="form-control" value="<?php echo isset($meta['name']) ? $meta['name']: '' ?>" required>
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" name="username" id="username" class="form-control" value="<?php echo isset($meta['username']) ? $meta['username']: '' ?>" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" id="password" class="form-control" value="<?php echo isset($meta['password']) ? $meta['password']: '' ?>" required>
</div>
<div class="form-group">
<label for="type">User Type</label>
<select name="type" id="type" class="custom-select">
<option value="1" <?php echo isset($meta['type']) && $meta['type'] == 1 ? 'selected': '' ?>>Admin</option>
<option value="2" <?php echo isset($meta['type']) && $meta['type'] == 2 ? 'selected': '' ?>>Staff</option>
</select>
</div>
</form>
</div>
<script>
$('#manage-user').submit(function(e){
e.preventDefault();
start_load()
$.ajax({
url:'ajax.php?action=save_user',
method:'POST',
data:$(this).serialize(),
success:function(resp){
if(resp==1){
$('.modal').modal('hide')
alert_toast("User successfully added",'success')
setTimeout(function(){
location.reload()
},1500)
}
else if(resp==2){
$('.modal').modal('hide')
alert_toast("User successfully updated",'success')
setTimeout(function(){
location.reload()
},1500)
}
else if(resp==0){
$('.modal').modal('hide')
alert_toast("Please fill out all fields of form",'danger')
setTimeout(function(){
location.reload()
},1500)
}
else {
$('.modal').modal('hide')
alert_toast("Unable to add this user",'danger')
setTimeout(function(){
location.reload()
},1500)
}
}
})
})
</script>