-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
279 lines (245 loc) · 11.8 KB
/
script.js
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
//---------------------------------------------------------------------------------------------------------------------------
// Script in attend2.html
//---------------------------------------------------------------------------------------------------------------------------
document.addEventListener("DOMContentLoaded", function() {
// Select the end session button
const endSessionBtn = document.querySelector('.end-session-btn');
// Add click event listener to the end session button
endSessionBtn.addEventListener('click', function() {
// Show confirmation dialog
const confirmation = confirm("End Session will stop taking attendance for today's class. \nAre you sure want to stop taking attendance?");
// If user clicks OK, redirect to anr.html
if (confirmation) {
window.location.href = "anr.html";
}
});
});
//---------------------------------------------------------------------------------------------------------------------------
// Script in record.html
//---------------------------------------------------------------------------------------------------------------------------
function renderSortedRows(sortedRows) {
const tableBody = document.getElementById("recordTableBody");
tableBody.innerHTML = "";
sortedRows.forEach(row => {
tableBody.appendChild(row);
});
}
function rotateIcon(button) {
button.classList.toggle("rotate180");
}
// Add event listeners to filter buttons
document.getElementById("dateFilterBtn").addEventListener("click", toggleDateFilter);
document.getElementById("percentageFilterBtn").addEventListener("click", togglePercentageFilter);
document.addEventListener('DOMContentLoaded', function() {
const urlParams = new URLSearchParams(window.location.search);
const class_id = urlParams.get('class_id');
fetch(`view_record.php?class_id=${class_id}`)
.then(response => response.json())
.then(data => {
console.log(data); // Log the data to the console
const tbody = document.getElementById('attendanceTableBody');
tbody.innerHTML = '';
let index = 1;
data.present.forEach(student => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${index}</td>
<td>${student.full_name}</td>
<td>${student.matric_ID}</td>
<td>${student.gender.toUpperCase()}</td>
<td class="status" data-student-id="${student.id}" data-status="PRESENT">
<span class="status-text">PRESENT</span>
<select class="status-dropdown">
<option value="PRESENT">Mark as PRESENT</option>
<option value="ABSENT">Mark as ABSENT</option>
</select>
</td>
`;
tbody.appendChild(row);
index++;
});
data.absent.forEach(student => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${index}</td>
<td>${student.full_name}</td>
<td>${student.matric_ID}</td>
<td>${student.gender.toUpperCase()}</td>
<td class="status" data-student-id="${student.id}" data-status="ABSENT">
<span class="status-text">ABSENT</span>
<select class="status-dropdown">
<option value="PRESENT">Mark as PRESENT</option>
<option value="ABSENT">Mark as ABSENT</option>
</select>
</td>
`;
tbody.appendChild(row);
index++;
});
// Add event listener to handle status change
document.querySelectorAll('.status-dropdown').forEach(dropdown => {
dropdown.addEventListener('change', function() {
const cell = this.closest('.status');
const studentId = cell.dataset.studentId;
const newStatus = this.value;
updateStatus(class_id, studentId, newStatus, cell);
});
});
})
.catch(error => console.error('Error fetching data:', error));
});
function updateStatus(classId, studentId, status, cell) {
fetch('update_status.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ class_id: classId, student_id: studentId, status: status }),
})
.then(response => response.json())
.then(data => {
if (data.status === 'success') {
cell.querySelector('.status-text').textContent = status;
cell.dataset.status = status;
if (status === 'PRESENT') {
cell.classList.remove('status-absent');
cell.classList.add('status-present');
} else {
cell.classList.remove('status-present');
cell.classList.add('status-absent');
}
} else {
alert('Error updating status: ' + data.message);
}
})
.catch(error => console.error('Error updating status:', error));
}
//---------------------------------------------------------------------------------------------------------------------------
// Script in manage.html
//---------------------------------------------------------------------------------------------------------------------------
function clearSearch() {
// Clear the search input value
document.getElementById("searchInput").value = "";
searchTable();
}
function searchTable() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("searchInput");
filter = input.value.toUpperCase();
table = document.getElementById("tableBody");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td");
for (var j = 0; j < td.length; j++) {
txtValue = td[j].textContent || td[j].innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
break;
} else {
tr[i].style.display = "none";
}
}
}
}
function registerStudent() {
// Redirect to manage2.html
window.location.href = "process_registration.php";
}
document.querySelectorAll('.delete-btn').forEach(button => {
button.addEventListener('click', function() {
const deleteId = this.getAttribute('data-id');
if (confirm("Are you sure you want to delete this student?")) {
// Send AJAX request to delete_student.php
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
// Update table or show a message
location.reload();
} else {
console.error('Error:', xhr.statusText);
}
}
};
xhr.open('POST', 'delete_student.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send('delete_id=' + deleteId);
}
});
});
//---------------------------------------------------------------------------------------------------------------------------
// Script in manage2.html
//---------------------------------------------------------------------------------------------------------------------------
function previewImage(event) {
var reader = new FileReader();
reader.onload = function() {
var imagePreview = document.getElementById('imagePreview');
imagePreview.src = reader.result;
}
reader.readAsDataURL(event.target.files[0]);
}
// Attach event listener to image input
document.getElementById('image').addEventListener('change', previewImage);
document.addEventListener("DOMContentLoaded", function() {
// Get the form and submit button
const form = document.getElementById("studentForm");
const submitBtn = document.getElementById("submitBtn");
// Add event listener to the form submit button
document.getElementById("myForm").addEventListener("submit", function(event) {
// Prevent the default form submission
event.preventDefault();
});
});
//---------------------------------------------------------------------------------------------------------------------------
// Script in visual.html
//---------------------------------------------------------------------------------------------------------------------------
document.addEventListener("DOMContentLoaded", function() {
const yearSelect = document.getElementById('year-select');
const currentYear = new Date().getFullYear();
const startYear = 2000;
for (let year = startYear; year <= currentYear; year++) {
const option = document.createElement('option');
option.value = year;
option.textContent = year;
yearSelect.appendChild(option);
}
document.getElementById('display-data-btn').addEventListener('click', function() {
const month = document.getElementById('month-select').value;
const year = document.getElementById('year-select').value;
// Implement the logic to display data based on the selected month and year
console.log(`Displaying data for ${month} ${year}`);
});
});
//---------------------------------------------------------------------------------------------------------------------------
// Script in view_stat.php
//---------------------------------------------------------------------------------------------------------------------------
document.addEventListener("DOMContentLoaded", function () {
const statusCells = document.querySelectorAll(".status-cell");
statusCells.forEach(cell => {
cell.addEventListener("click", function () {
const dropdown = cell.nextElementSibling;
dropdown.style.display = "inline";
cell.style.display = "none";
dropdown.value = cell.textContent;
dropdown.addEventListener("change", function () {
const selectedStatus = dropdown.value;
const matricId = dropdown.getAttribute("data-matric-id");
// Update status in the database using AJAX
updateStatus(matricId, selectedStatus).then(() => {
cell.textContent = selectedStatus;
cell.style.display = "inline";
dropdown.style.display = "none";
});
});
});
});
});
function updateStatus(matricId, status) {
return fetch('update_status.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `matric_id=${matricId}&status=${status}`
});
}