-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_staff.php
106 lines (100 loc) · 4.08 KB
/
new_staff.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
<?php if(!isset($conn)){ include 'db_connect.php'; } ?>
<style>
textarea{
resize: none;
}
</style>
<div class="col-lg-12">
<div class="card card-outline card-primary">
<div class="card-body">
<form action="" id="manage-staff">
<input type="hidden" name="id" value="<?php echo isset($id) ? $id : '' ?>">
<div class="row">
<div class="col-md-12">
<div id="msg" class=""></div>
<div class="row">
<div class="col-sm-6 form-group ">
<label for="" class="control-label">First Name</label>
<input type="text" name="firstname" id="" class="form-control form-control-sm" value="<?php echo isset($firstname) ? $firstname : '' ?>" required>
</div>
<div class="col-sm-6 form-group ">
<label for="" class="control-label">Last Name</label>
<input type="text" name="lastname" id="" class="form-control form-control-sm" value="<?php echo isset($lastname) ? $lastname : '' ?>" required>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group ">
<label for="" class="control-label">Branch</label>
<select name="branch_id" id="" class="form-control input-sm select2">
<option value=""></option>
<?php
$branches = $conn->query("SELECT *,concat(street,', ',city,', ',state,', ',zip_code,', ',country) as address FROM branches");
while($row = $branches->fetch_assoc()):
?>
<option value="<?php echo $row['id'] ?>" <?php echo isset($branch_id) && $branch_id == $row['id'] ? "selected":'' ?>><?php echo $row['branch_code']. ' | '.(ucwords($row['address'])) ?></option>
<?php endwhile; ?>
</select>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group ">
<label for="" class="control-label">Email</label>
<input type="email" name="email" id="" class="form-control form-control-sm" value="<?php echo isset($email) ? $email : '' ?>" required>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group ">
<label for="" class="control-label">Password</label>
<input type="password" name="password" id="" class="form-control form-control-sm" <?php echo isset($id) ? '' : 'required' ?>>
<?php if(isset($id)): ?>
<small class=""><i>Leave this blank if you dont want to change this</i></small>
<?php endif; ?>
</div>
</div>
</div>
</div>
</form>
</div>
<div class="card-footer border-top border-info">
<div class="d-flex w-100 justify-content-center align-items-center">
<button class="btn btn-flat bg-gradient-primary mx-2" form="manage-staff">Save</button>
<a class="btn btn-flat bg-gradient-secondary mx-2" href="./index.php?page=staff_list">Cancel</a>
</div>
</div>
</div>
</div>
<script>
$('#manage-staff').submit(function(e){
e.preventDefault()
start_load()
$.ajax({
url:'ajax.php?action=save_user',
data: new FormData($(this)[0]),
cache: false,
contentType: false,
processData: false,
method: 'POST',
type: 'POST',
success:function(resp){
if(resp == 1){
alert_toast('Data successfully saved',"success");
setTimeout(function(){
location.href = 'index.php?page=staff_list'
},2000)
}else if(resp == 2){
$('#msg').html('<div class="alert alert-danger"><i class="fa fa-exclamation-triangle"></i> Email already exist.</div>')
end_load()
}
}
})
})
function displayImgCover(input,_this) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#cover').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
</script>