-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-staff.php
216 lines (168 loc) · 6.96 KB
/
add-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
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
<?php
include 'includes/pre-head.php';
if (!isset($_SESSION['user'])) {
header("Location: index.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Header include -->
<?php include 'includes/head.php';?>
<!-- END Header include -->
</head>
<body>
<!-- NAV bar include -->
<?php include 'includes/navbar.php'; ?>
<!-- END NAV bar include -->
<!-- Alert include -->
<?php include 'includes/alert-header.php' ?>
<!-- END Alert include -->
<div class="container">
<div class="row">
<div class="col">
<!-- NAV include -->
<?php include 'includes/nav-menu.php' ?>
<!-- END NAV include -->
</div>
</div>
<div class="row justify-content-center">
<div class="col">
<br>
<!-- Main Content -->
<div class="container">
<form id="add-staff-form">
<div class="row justify-content-center">
<div class="col-sm-8">
<h2>Add a new Staff</h2>
<hr />
</div>
</div>
<div class="row justify-content-center">
<div class="col-sm-8 form-control-feedback hidden" id="staff-name-group-feedback"></div>
</div>
<div class="row justify-content-center">
<div class="col-sm-4 form-group">
<label for="first-name">First Name</label>
<input type="text" class="form-control" id="first-name" name="first-name" placeholder="First Name"
data-parsley-required data-parsley-trigger="change" autocomplete="off" spellcheck="false"
data-parsley-errors-messages-disabled>
</div>
<div class="col-sm-4 form-group">
<label for="last-name">Last Name</label>
<input type="text" class="form-control" id="last-name" name="last-name" placeholder="Last Name"
data-parsley-required data-parsley-trigger="change" autocomplete="off" spellcheck="false"
data-parsley-errors-messages-disabled>
</div>
</div>
<div class="row justify-content-center">
<div class="col-sm-8 form-group" id="cat-id-group">
<label for="category-id">Select the staff category (eg. RN, LPN, NA, etc..)</label>
<select class="form-control" id="category-id" name="category-id" data-parsley-required>
<option value="" disabled selected hidden>Please Choose...</option>
<?php
//Build Option List
//use the CRUD object to access the database and build an option list of the categories
$form_select_categories = $crud->getAllCategories();
foreach ($form_select_categories as $k => $v) {?>
<option value="<?php echo ($k); ?>"><?php echo ($v); ?></option>
<?php }
//END Build Option List
?>
</select>
</div>
</div>
<div class="row justify-content-end">
<div class="col-sm-4 form-group">
<button type="submit" class="btn btn-primary" id="btn-submit-new-staff">Add New Staff</button>
</div>
</div>
</form>
</div>
<!-- END Main Content -->
</div>
</div>
</div>
<!-- Spacer for the bottom -->
<div class="container">
<br />
<br />
<br />
</div>
<!-- Spacer for the bottom -->
<!-- Prefooter Include -->
<?php include 'includes/script-include.php'; ?>
<!-- END Prefooter Include -->
<!-- Aux Scripts -->
<script>
var debug = true;
/*
* Bind parsley.js event listeners here.
*/
$(function () {
$('#add-staff-form')
.parsley({errorClass: "form-control-danger", successClass: "form-control-success"})
.on('field:validated', function (e) {
if (e.validationResult.constructor!==Array) {
this.$element.closest('.form-group').removeClass('has-danger').addClass('has-success');
} else {
this.$element.closest('.form-group').removeClass('has-success').addClass('has-danger');
}
})
.on('form:submit', function () {
var data = $('#add-staff-form').serialize();
if (debug) { console.log(data + '&btn-submit-new-staff=1'); }
$.ajax({
type: 'POST',
url: 'resource/post_staff.php',
data: data + '&btn-submit-new-staff=1',
beforeSend: function () {
$('#btn-submit-new-staff').html('<span class="fa fa-transfer"></span> adding ...');
},
success: function (response) {
if (debug) { console.log(response); }
if (response == "ok") {
//clear the feedback message
$('#staff-name-group-feedback').html('');
//clear the form group classes
$('#staff-name-group').removeClass('has-danger').removeClass('has-success');
$('#cat-id-group').removeClass('has-danger').removeClass('has-success');
//clear the form control classes
$('#first-name').removeClass('form-control-danger').removeClass('form-control-success');
$('#last-name').removeClass('form-control-danger').removeClass('form-control-success');
$('#category-id').removeClass('form-control-danger').removeClass('form-control-success');
//display the alert to success
$('#form-alert').addClass('alert-success');
$('#form-alert p').html('<h4>Staff successfully added!</h4>');
$('#alert-container').collapse('show');
$("#alert-container").focus();
//set timeout to hide the alert in x milliseconds
setTimeout(function(){
$("#alert-container").collapse('hide');
setTimeout(function(){
$("#form-alert p").html('');
$('#form-alert').removeClass('alert-success');
}, 1000);
}, 5000);
//reset the form, return focus to first name
$('#add-staff-form').trigger('reset');
$("#first-name").focus();
} else {
$('#staff-name-group-feedback').html('<span class="fa fa-info-circle"></span> That name is already entered.');
$('#staff-name-group').removeClass('has-success').addClass('has-danger');
$('#first-name').removeClass('form-control-success').addClass('form-control-danger');
$('#login-password').removeClass('form-control-success').addClass('form-control-danger');
}
$('#btn-submit-new-staff').html('Add New Staff');
}
});
return false;
});
});
</script>
<!-- END Aux Scripts -->
<!-- Footer Include -->
<?php include 'includes/footer.php'; ?>
<!-- END Footer Include -->
</body>
</html>