-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_staff.php
More file actions
91 lines (86 loc) · 3.49 KB
/
Copy pathnew_staff.php
File metadata and controls
91 lines (86 loc) · 3.49 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
<?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">Staff Id</label>
<input type="text" name="id" id="" class="form-control form-control-sm" value="<?php echo isset($id) ? $id : '' ?>" required>
</div>
<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">Department</label>
<select name="dept_id" id="" class="form-control input-sm">
<option value=""></option>
<?php
$departments = $conn->query("SELECT name,id FROM departments where active = 1");
while($row = $departments->fetch_assoc()):
?>
<option value="<?php echo $row['id'] ?>" <?php echo isset($dept_id) && $dept_id == $row['id'] ? "selected":'' ?>><?php echo $row['name'] ?></option>
<?php endwhile; ?>
</select>
</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()
}
}
})
})
</script>