forked from Henry33y/Safo-hall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
297 lines (289 loc) · 19.4 KB
/
edit.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
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
<?php
$title = 'Edit Record';
require_once 'includes/session.php';
require_once 'includes/header.php';
require_once 'includes/auth_check.php';
require_once 'includes/db_conn.php';
$id = $firstName = $lastName = $studentId = $category = $level = $programme = $contact = $email = $parentName = $parentContact = $physicallyChallenged = $disability = $underScholarship = $scholarshipSpecify = $roomNumber = '';
$roomResults = $crud->getRoomDetails();
if(isset($_POST['submit'])){
if(!empty($_POST['id'])){
$id = $_POST['id'];
}
if(!empty($_POST['first_name'])){
$firstName = $_POST['first_name'];
}
if(!empty($_POST['last_name'])){
$lastName = $_POST['last_name'];
}
if(!empty($_POST['student_id'])){
$studentId = $_POST['student_id'];
}
if(!empty($_POST['category'])){
$category = $_POST['category'];
}
if(!empty($_POST['programme'])){
$programme = $_POST['programme'];
}
if(!empty($_POST['level'])){
$level = $_POST['level'];
}
if(!empty($_POST['contact'])){
$contact = $_POST['contact'];
}
if(!empty($_POST['email'])){
$email = $_POST['email'];
}
if(!empty($_POST['parent_name'])){
$parentName = $_POST['parent_name'];
}
if(!empty($_POST['parent_contact'])){
$parentContact = $_POST['parent_contact'];
}
if(!empty($_POST['disability'])){
$disability = $_POST['disability'];
}
else{
$disability = 'None';
}
if($_POST['is_under_scholarship'] == 'Yes' && $_POST['scholarship'] != 'others'){
$scholarshipSpecify = $_POST['scholarship'];
}
else if($_POST['is_under_scholarship'] == 'No'){
$scholarshipSpecify = 'None';
}
else{
$scholarshipSpecify = $_POST['specified_scholarship'];
}
if(!empty($_POST['old_room_number'])){
$oldRoomNumber = $_POST['old_room_number'];
}
if(!empty($_POST['new_room_number'])){
$newRoomNumber = $_POST['new_room_number'];
}
$result = $crud->editStudentDetails($id,$firstName,$lastName,$studentId,$category,$level,$programme,$contact,$email,$parentName,$parentContact,$disability,$scholarshipSpecify,$oldRoomNumber,$newRoomNumber);
if($result){
echo "<script>window.location.href='viewRegisteredStudents.php'</script>";
}else{
include 'includes/errMessage.php';
}
}
if(!isset($_GET['id'])){
include 'includes/errMessage.php';
}
else{
$id = $_GET['id'];
$studentInfo = $crud->getSingleStudentDetails($id);
?>
<main class="pt-3">
<h2 class="text-center">Edit Record</h2>
<div class="d-flex justify-content-center justify-content-center">
<form action="edit.php" method="post" id="register_form" class="form py-3 px-5 rounded-3 shadow-lg bg-white needs-validation" novalidate>
<input type="hidden" name="id" value="<?php echo $studentInfo['id'] ?>">
<div>
<label for="first_name" class="form-label">First Name</label>
<div>
<input type="text" name="first_name" id="first_name" value="<?php echo $studentInfo['first_name'] ?>" class="form-control pe-5" required>
<div class="invalid-feedback">Wrong Input</div>
</div>
</div>
<div>
<label for="last_name" class="form-label">Last Name</label>
<div>
<input type="text" name="last_name" id="last_name" value="<?php echo $studentInfo['last_name'] ?>" class="form-control" required>
<div class="invalid-feedback">Wrong Input</div>
</div>
</div>
<div>
<label for="student_id" class="form-label">Student ID</label>
<div>
<input type="text" name="student_id" id="student_id" value="<?php echo $studentInfo['student_id'] ?>" class="form-control" required>
<div class="invalid-feedback">Wrong Input</div>
</div>
</div>
<div>
<label for="category" class="form-label">Category</label>
<div>
<select name="category" id="category" class="form-select" required>
<option selected disabled value="">Select Category</option>
<option value="undergraduate" <?php echo ($studentInfo['category'] == 'undergraduate')? 'selected': ''?>>Undergraduate</option>
<option value="abe" <?php echo ($studentInfo['category'] == 'abe')? 'selected': ''?>>ABE</option>
<option value="ncce" <?php echo ($studentInfo['category'] == 'ncce')? 'selected': ''?>>NCCE</option>
</select>
<div class="invalid-feedback">Wrong Input</div>
</div>
</div>
<div>
<label for="programme" class="form-label">Programme</label>
<div>
<select name="programme" type="text" class="form-select" required>
<option selected disabled value="">Select Programme</option>
<option value="B.Sc. Actuarial Science" <?php echo ($studentInfo['programme'] == 'B.Sc. Actuarial Science')? 'selected': ''?>>B.Sc. Actuarial Science</option>
<option value="B.Sc. Quantity Surveying and Building Economics" <?php echo ($studentInfo['programme'] == 'B.Sc. Quantity Surveying and Building Economics')? 'selected': ''?>>B.Sc. Quantity Surveying and Building Economics</option>
<option value="B.A. Communication Studies" <?php echo ($studentInfo['programme'] == 'B.A. Communication Studies')? 'selected': ''?>>B.A. Communication Studies</option>
<option value="Association of Business Executives (ABE)" <?php echo ($studentInfo['programme'] == 'Association of Business Executives (ABE)')? 'selected': ''?>>Association of Business Executives (ABE)</option>
<option value="National Centre for Computer Education (NCCE)" <?php echo ($studentInfo['programme'] == 'National Centre for Computer Education (NCCE)')? 'selected': ''?>>National Centre for Computer Education (NCCE)</option>
<option value="B.Eng Pre-Engineering" <?php echo ($studentInfo['programme'] == 'B.Eng Pre-Engineering')? 'selected': ''?>>B.Eng Pre-Engineering</option>
<option value="Bachelor of Laws (LL.B)" <?php echo ($studentInfo['programme'] == 'Bachelor of Laws (LL.B)')? 'selected': ''?>>Bachelor of Laws (LL.B)</option>
<option value="B.Sc. Physician Assistantship Studies - Medical" <?php echo ($studentInfo['programme'] == 'B.Sc. Physician Assistantship Studies - Medical')? 'selected': ''?>>B.Sc. Physician Assistantship Studies - Medical</option>
<option value="B.Sc. Business Administration (Accounting)" <?php echo ($studentInfo['programme'] == 'B.Sc. Business Administration (Accounting)')? 'selected': ''?>>B.Sc. Business Administration (Accounting)</option>
<option value="B.Sc. Industrial Software Engineering" <?php echo ($studentInfo['programme'] == 'B.Sc. Industrial Software Engineering')? 'selected': ''?>>B.Sc. Industrial Software Engineering</option>
<option value="B.Sc. Business Administration (Banking & Finance)" <?php echo ($studentInfo['programme'] == 'B.Sc. Business Administration (Banking & Finance)')? 'selected': ''?>>B.Sc. Business Administration (Banking & Finance)</option>
<option value="Bachelor of Commerce (Accounting with Computing)" <?php echo ($studentInfo['programme'] == 'Bachelor of Commerce (Accounting with Computing)')? 'selected': ''?>>Bachelor of Commerce (Accounting with Computing)</option>
<option value="B.Sc. Business Administration (Corporate & Business Development Studies)" <?php echo ($studentInfo['programme'] == 'B.Sc. Business Administration (Corporate & Business Development Studies)')? 'selected': ''?>>B.Sc. Business Administration (Corporate & Business Development Studies)</option>
<option value="B.Sc. Business Administration (Human Resource Management)" <?php echo ($studentInfo['programme'] == 'B.Sc. Business Administration (Human Resource Management)')? 'selected': ''?>>B.Sc. Business Administration (Human Resource Management)</option>
<option value="B.Sc. Business Administration (Insurance with Actuarial Science)" <?php echo ($studentInfo['programme'] == 'B.Sc. Business Administration (Insurance with Actuarial Science)')? 'selected': ''?>>B.Sc. Business Administration (Insurance with Actuarial Science)</option>
<option value="B.Sc. Business Administration (Logistics and Supply Chain Management)" <?php echo ($studentInfo['programme'] == 'B.Sc. Business Administration (Logistics and Supply Chain Management)')? 'selected': ''?>>B.Sc. Business Administration (Logistics and Supply Chain Management)</option>
<option value="B.Sc. Business Administration (Marketing)" <?php echo ($studentInfo['programme'] == 'B.Sc. Business Administration (Marketing)')? 'selected': ''?>>B.Sc. Business Administration (Marketing)</option>
<option value="B.Sc. Construction Technology and Engineering Management" <?php echo ($studentInfo['programme'] == 'B.Sc. Construction Technology and Engineering Management')? 'selected': ''?>>B.Sc. Construction Technology and Engineering Management</option>
<option value="B.Sc. Information Technology" <?php ($studentInfo['programme'] == 'B.Sc. Information Technology')? 'selected':'' ?>>B.Sc. Information Technology</option>
<option value="B.Sc. Nursing" <?php echo ($studentInfo['programme'] == 'B.Sc. Actuarial Science')? 'selected': ''?>>B.Sc. Nursing</option>
</select>
<div class="invalid-feedback">Wrong Input</div>
</div>
</div>
<div>
<label for="level" class="form-label">Level</label>
<div>
<select name="level" id="level" class="form-select" required>
<option selected disabled value="">Choose level</option>
<option value="100" <?php echo ($studentInfo['level'] == '100')? 'selected': ''?>>100</option>
<option value="200" <?php echo ($studentInfo['level'] == '200')? 'selected': ''?>>200</option>
<option value="300" <?php echo ($studentInfo['level'] == '300')? 'selected': ''?>>300</option>
<option value="400" <?php echo ($studentInfo['level'] == '400')? 'selected': ''?>>400</option>
<option value="400" <?php echo ($studentInfo['level'] == '4')? 'selected': ''?>>4</option>
<option value="400" <?php echo ($studentInfo['level'] == '5')? 'selected': ''?>>5</option>
<option value="400" <?php echo ($studentInfo['level'] == '6')? 'selected': ''?>>6</option>
</select>
<div class="invalid-feedback">Wrong Input</div>
</div>
</div>
<div>
<label for="contact" class="form-label">Contact</label>
<div>
<input name="contact" type="number" value="<?php echo $studentInfo['contact'] ?>" class="form-control" required>
<div class="invalid-feedback">Wrong Input</div>
</div>
</div>
<div>
<label for="email" class="form-label">Email</label>
<div>
<input name="email" type="email" value="<?php echo $studentInfo['email'] ?>" class="form-control" required>
<div class="invalid-feedback">Wrong Input</div>
</div>
</div>
<div>
<label for="parent_name" class="form-label">Parent's name</label>
<div>
<input name="parent_name" type="text" value="<?php echo $studentInfo['parent_name'] ?>" class="form-control" required>
<div class="invalid-feedback">Wrong Input</div>
</div>
</div>
<div>
<label for="parent_contact" class="form-label">Parent's Contact</label>
<div>
<input name="parent_contact" id="parent_contact" type="number" value="<?php echo $studentInfo['parent_contact'] ?>" class="form-control" required>
<div class="invalid-feedback">Wrong Input</div>
</div>
</div>
<div>
<label for="is_under_scholarship" class="form-label">Are you physically challenged?</label>
<div>
<input name="is_challenged" type="radio" class="" id="challenged" value="Yes" <?php echo ($studentInfo['physical_challenges'] == 'None')? '': 'checked'?> required>Yes<br>
<input name="is_challenged" type="radio" class="" id="not_challenged" value="No" <?php echo ($studentInfo['physical_challenges'] == 'None')? 'checked': ''?> required>No
<div class="invalid-feedback">Wrong Input</div>
</div>
</div>
<div class="specify_disability_container">
<label for="disability" class="form-label">Please Specify</label>
<div>
<input name="disability" id="disability" type="text" value="<?php echo $studentInfo['physical_challenges'] ?>" class="form-control">
</div>
</div>
<div>
<label for="is_under_scholarship" class="form-label">Are you under scholarship?</label>
<div>
<input name="is_under_scholarship" type="radio" class="" id="under_scholarship" value="Yes" <?php echo ($studentInfo['scholarship'] == 'None')? '': 'checked'?> required>Yes<br>
<input name="is_under_scholarship" type="radio" class="" id="not_under_scholarship" value="No" <?php echo ($studentInfo['scholarship'] == 'None')? 'checked': ''?> required>No
<div class="invalid-feedback">Wrong Input</div>
</div>
</div>
<div>
<div class="choose_scholarship_container">
<label for="scholarship" class="form-label">Scholarship</label>
<select name="scholarship" id="scholarship_select" class="form-select" required>
<option value="choose_scholarship" selected disabled>Choose Scholarship</option>
<option value="Church Of Pentecost">Church of Pentecost</option>
<option value="Pentecost University">Pentecost University</option>
<option value="Get Fund">GET Fund</option>
<option value="others">Others(Please Specify)</option>
</select>
<div class="invalid-feedback">Wrong Input</div>
<div class="" id="specify_scholarship_container">
<label for="specified_scholarship">Specify Scholarship</label>
<div>
<input type="text" name="specified_scholarship" id="specified_scholarship" value="<?php echo $studentInfo['scholarship'] ?>" class="form-control">
</div>
</div>
</div>
</div>
<div>
<button type="button" class="form-control btn btn-outline-primary" id="choose_room_btn" data-bs-toggle="modal" data-bs-target="#choose_room_modal_container">Choose Room</button>
</div>
<div id="choose_room_modal_container" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">Choose Room</h3>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<?php
while ($r = $roomResults->fetch(PDO::FETCH_ASSOC)) {
echo '<button type="button" value="'.$r['room_number'].'" class="btn btn-outline-primary m-2 room-button ';
if($r['current_students'] == $r['max_students']){
echo 'disabled bg-secondary';
}
echo '" onClick = "updateRoomNumber('.$r["room_number"].')">'.$r['room_number'].'</button>';
}
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary modal-submit-btn" data-bs-dismiss="modal">Submit</button>
</div>
</div>
</div>
</div>
<div class="">
<label for="room_number" class="form-label">Room Number </label>
<span class="" id="room_num_display" value="<?php echo $studentInfo['room_number'] ?>"><?php echo $studentInfo['room_number'] ?></span>
<div>
<input type="hidden" name="old_room_number" id="old_room_number" value="<?php echo $studentInfo['room_number'] ?>" class="form-control">
<input type="hidden" name="new_room_number" id="new_room_number" value="<?php echo $studentInfo['room_number'] ?>" class="form-control">
<div class="invalid-feedback">Please select a room</div>
</div>
</div>
<div class="d-flex justify-content-end mt-3">
<a href="viewRegisteredStudents.php" class="btn btn-info me-3">Back To List</a>
<input type="submit" name="submit" value="Save Changes" class="btn btn-success">
</div>
</form>
</div>
</main>
<?php } ?>
<br>
<br>
<?php require_once './includes/footer.php';?>
<script>
let selectedRoom = '';
function updateRoomNumber(roomNumber) {
selectedRoom = roomNumber;
}
document.querySelector('.modal-submit-btn').addEventListener('click', function() {
document.getElementById('new_room_number').value = selectedRoom;
document.getElementById('room_num_display').innerText = selectedRoom;
document.getElementById('room_number').value = selectedRoom;
});
</script>
<script defer src="js/edit_script.js"></script>