-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
246 lines (224 loc) · 13.2 KB
/
index.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
<?php
/**
* Including back-end functions
*
* Includes the file one time
*/
require_once "back-end/app.php";
$itemsPerPage = 5;
$totalItems = count($students);
$totalPages = ceil($totalItems / $itemsPerPage);
$currentPage = isset($_GET['page']) ? $_GET['page'] : 1;
$startIndex = ($currentPage - 1) * $itemsPerPage;
$paginatedStudents = array_slice($students, $startIndex, $itemsPerPage);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Student Management System</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N"
crossorigin="anonymous">
</head>
<body>
<div class="container">
<h2 class="mt-4">Student Management System</h2>
<form autocomplete="off" method="post" action="index.php">
<h3>Add Student</h3>
<div class="form-group row">
<label for="registrationNumber" class="col-sm-2 col-form-label">Registration Number:<sup
class="text-danger">*</sup></label>
<div class="col-sm-10">
<input type="number" id="registrationNumber" name="registrationNumber"
class="form-control" required>
</div>
</div>
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Name:<sup class="text-danger">*</sup></label>
<div class="col-sm-10">
<input type="text" id="name" name="name" class="form-control" required>
</div>
</div>
<div class="form-group row">
<label for="grade" class="col-sm-2 col-form-label">Grade:<sup
class="text-danger">*</sup></label>
<div class="col-sm-10">
<input type="number" id="grade" name="grade" min="0" max="10" class="form-control"
required>
</div>
</div>
<div class="form-group row">
<label for="classroom" class="col-sm-2 col-form-label">Classroom:<sup
class="text-danger">*</sup></label>
<div class="col-sm-10">
<select id="classroom" name="classroom" class="custom-select" required>
<option value="" selected hidden disabled>Select an Option</option>
<option value="Fundamental of Programming">Fundamental of Programming</option>
<option value="Object Oriented Programming">Object Oriented Programming</option>
<option value="Data Structures and Algorithms">Data Structures and Algorithms
</option>
</select>
</div>
</div>
<button type="submit" name="addStudent" class="btn btn-primary float-right">Add Student</button>
</form>
<h3 class="mt-4">Students List</h3>
<?php if (empty($paginatedStudents)) : ?>
<p>No students found.</p>
<?php else : ?>
<!--Table start-->
<table class="table">
<thead>
<tr>
<th>Registration Number</th>
<th>Name</th>
<th>Grade</th>
<th>Classroom</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($paginatedStudents as $student) : ?>
<tr>
<td><?php echo $student['registrationNumber']; ?></td>
<td><?php echo $student['name']; ?></td>
<td><?php echo $student['grade']; ?></td>
<td><?php echo $student['classroom']; ?></td>
<td>
<button type="button" class="btn btn-primary" data-toggle="modal"
data-target="#updateStudentModal<?php echo $student['registrationNumber']; ?>">Update
</button>
<!--Update Student Data Modal start-->
<div class="modal fade" id="updateStudentModal<?php echo $student['registrationNumber']; ?>"
data-backdrop="static" data-keyboard="false"
tabindex="-1" aria-labelledby="updateStudentModalLabel" aria-hidden="true">
<div class="modal-dialog">
<form autocomplete="off" method="post" action="index.php">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="updateStudentModalLabel">Update Student</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<input type="hidden" name="registrationNumber"
value="<?php echo $student['registrationNumber']; ?>">
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Name:<sup
class="text-danger">*</sup></label>
<div class="col-sm-10">
<input type="text" id="name" name="name"
value="<?php echo $student['name']; ?>" class="form-control"
required>
</div>
</div>
<div class="form-group row">
<label for="grade" class="col-sm-2 col-form-label">Grade:<sup
class="text-danger">*</sup></label>
<div class="col-sm-10">
<input type="number" id="grade" name="grade"
value="<?php echo $student['grade']; ?>" min="0" max="10"
class="form-control"
required>
</div>
</div>
<div class="form-group row">
<label for="classroom" class="col-sm-2 col-form-label">Classroom:<sup
class="text-danger">*</sup></label>
<div class="col-sm-10">
<select id="classroom" name="classroom" class="custom-select"
required>
<option value="" selected hidden disabled>Select an Option
</option>
<option
value="Fundamental of Programming" <?php echo $student['classroom'] == 'Fundamental of Programming' ? 'selected' : ''; ?> >
Fundamental of Programming
</option>
<option
value="Object Oriented Programming" <?php echo $student['classroom'] == 'Object Oriented Programming' ? 'selected' : ''; ?> >
Object Oriented Programming
</option>
<option
value="Data Structures and Algorithms" <?php echo $student['classroom'] == 'Data Structures and Algorithms' ? 'selected' : ''; ?> >
Data Structures and Algorithms
</option>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close
</button>
<button type="submit" name="updateStudent" class="btn btn-primary">Update
</button>
</div>
</div>
</form>
</div>
</div>
<!--Update Student Data Modal end-->
<button type="button" class="btn btn-danger" data-toggle="modal"
data-target="#exampleModal<?php echo $student['registrationNumber']; ?>">Delete
</button>
<!--Delete Student Confirmation Modal start-->
<div class="modal fade" id="exampleModal<?php echo $student['registrationNumber']; ?>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Delete</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h4 class="modal-heading">Are You Sure ?</h4>
<p>Do you really want to <b>delete</b> the student? This process
cannot be undo.
</p>
</div>
<div class="modal-footer">
<form method="post" action="index.php">
<input type="hidden" name="registrationNumber"
value="<?php echo $student['registrationNumber']; ?>">
<button type="reset" class="btn btn-secondary"
data-dismiss="modal">No
</button>
<button type="submit" name="deleteStudent"
class="btn btn-danger">Yes
</button>
</form>
</div>
</div>
</div>
</div>
<!--Delete Student Confirmation Modal end-->
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<!--Table end-->
<nav aria-label="Student pagination" class="float-right">
<ul class="pagination">
<?php for ($i = 1; $i <= $totalPages; $i++) : ?>
<li class="page-item <?php echo $i == $currentPage ? 'active' : ''; ?>">
<a class="page-link" href="?page=<?php echo $i; ?>"><?php echo $i; ?></a>
</li>
<?php endfor; ?>
</ul>
</nav>
<?php endif; ?>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+"
crossorigin="anonymous"></script>
</body>
</html>