-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattendance.html
373 lines (333 loc) · 13 KB
/
attendance.html
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Class Attendance</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
width: 90%;
margin: 20px auto;
padding: 20px;
background-color: white;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1, h2 {
text-align: center;
margin-bottom: 20px;
}
.section {
margin-bottom: 20px;
}
label {
font-weight: bold;
display: block;
margin: 10px 0 5px;
}
input, select {
width: 100%;
padding: 8px;
margin: 5px 0 20px;
border: 1px solid #ddd;
border-radius: 4px;
}
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
grid-gap: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th, td {
padding: 10px;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
}
/* Sidebar styling */
.sidebar {
height: 100%;
width: 0;
position: fixed;
top: 0;
right: 0;
background-color: #111;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
}
.sidebar button {
padding: 10px;
text-align: left;
margin: 10px 20px;
font-size: 18px;
display: block;
color: white;
background: none;
border: none;
cursor: pointer;
}
.sidebar button:hover {
background-color: #575757;
}
.sidebar .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
}
#sidebarButton {
font-size: 24px;
cursor: pointer;
position: fixed;
right: 20px;
top: 20px;
}
/* Hide buttons during print */
@media print {
.sidebar, #sidebarButton {
display: none;
}
}
</style>
</head>
<body>
<div id="sidebarButton" onclick="openSidebar()">☰</div>
<div id="mySidebar" class="sidebar">
<a href="javascript:void(0)" class="closebtn" onclick="closeSidebar()">×</a>
<button onclick="startNewAttendance()">Start New Lecture Attendance</button>
<button onclick="viewPreviousAttendance()">View Previous Attendance</button>
<button onclick="printAttendance()">Print Attendance</button>
</div>
<div class="container">
<h1>Attendance Sheet</h1>
<div class="section">
<h2>Faculty of Engineering</h2>
<div class="grid-container">
<div>
<label for="programme">Programme</label>
<input type="text" id="programme" placeholder="Enter programme">
</div>
<div>
<label for="intake">Intake (Month)</label>
<select id="intake">
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
</div>
<div>
<label for="date">Date</label>
<input type="date" id="date">
</div>
<div>
<label for="courseTitle">Course Title</label>
<input type="text" id="courseTitle" placeholder="Enter course title">
</div>
<div>
<label for="courseCode">Course Code</label>
<input type="text" id="courseCode" placeholder="Enter course code">
</div>
<div>
<label for="level">Level</label>
<select id="level">
<option value="100">100</option>
<option value="200">200</option>
<option value="300">300</option>
<option value="400">400</option>
</select>
</div>
<div>
<label for="startTime">Start Time</label>
<input type="time" id="startTime">
</div>
<div>
<label for="endTime">End Time</label>
<input type="time" id="endTime">
</div>
<div>
<label for="courseRep">Course Representative Name</label>
<input type="text" id="courseRep" placeholder="Enter course rep name">
</div>
<div>
<label for="lecturer">Lecturer's Name</label>
<input type="text" id="lecturer" placeholder="Enter lecturer name">
</div>
<div>
<label for="lecturerStatus">Lecturer's Status</label>
<select id="lecturerStatus">
<option value="present">Present</option>
<option value="absent">Absent</option>
</select>
</div>
</div>
</div>
<table id="attendanceTable">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<!-- Attendance records will be dynamically added here -->
</tbody>
</table>
</div>
<script>
let previousAttendance = []; // Array to store previous attendance records
let lastDisplayedId = null; // Variable to store the last displayed student's ID
let lastDetails = {}; // Object to store the last details of the attendance session
// Fetch attendance data from the ESP8266
function fetchAttendanceData() {
fetch('/attendance')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Assuming your ESP8266 sends JSON
})
.then(data => {
// Check if the received data is an object (for a single student's data)
if (typeof data === 'object' && !Array.isArray(data)) {
// Check if this student's data is already displayed
if (data.id !== lastDisplayedId) {
// Update the attendance table with the fetched data
const tableBody = document.getElementById('attendanceTable').querySelector('tbody');
// Create a new row for the attendance data
const row = document.createElement('tr');
row.innerHTML = `
<td>${data.id}</td>
<td>${data.name}</td>
<td>${data.status}</td>
`;
tableBody.appendChild(row); // Append the new row to the table
// Update the last displayed ID to prevent duplicates
lastDisplayedId = data.id;
} else {
console.log("Attendance data already displayed for ID: " + data.id);
}
} else {
console.error("Unexpected data format:", data);
}
})
.catch(error => console.error('Fetch error:', error));
}
// Set an interval to fetch data every few seconds
setInterval(fetchAttendanceData, 5000); // Adjust the interval as needed
// Open the sidebar
function openSidebar() {
document.getElementById("mySidebar").style.width = "250px";
}
// Close the sidebar
function closeSidebar() {
document.getElementById("mySidebar").style.width = "0";
}
// Function to start a new attendance sheet
function startNewAttendance() {
// Save the current attendance to previousAttendance
const currentAttendance = [...document.getElementById('attendanceTable').querySelectorAll('tbody tr')].map(row => ({
id: row.cells[0].innerText,
name: row.cells[1].innerText,
status: row.cells[2].innerText
}));
// Save form data
lastDetails = {
programme: document.getElementById('programme').value,
intake: document.getElementById('intake').value,
date: document.getElementById('date').value,
courseTitle: document.getElementById('courseTitle').value,
courseCode: document.getElementById('courseCode').value,
level: document.getElementById('level').value,
startTime: document.getElementById('startTime').value,
endTime: document.getElementById('endTime').value,
courseRep: document.getElementById('courseRep').value,
lecturer: document.getElementById('lecturer').value,
lecturerStatus: document.getElementById('lecturerStatus').value
};
previousAttendance.push({
attendance: currentAttendance,
details: lastDetails
});
// Reset the attendance data on the ESP8266
fetch('/reset')
.then(response => {
if (!response.ok) {
throw new Error('Failed to reset attendance data');
}
return response.text();
})
.then(data => {
console.log(data); // Log success message from ESP8266
// Now proceed to clear the table
const tableBody = document.getElementById('attendanceTable').querySelector('tbody');
tableBody.innerHTML = ''; // Clear previous entries
lastDisplayedId = null; // Reset last displayed ID
alert("Starting a new lecture attendance sheet.");
// Clear the attendance form
document.querySelectorAll('input').forEach(input => input.value = '');
document.getElementById('intake').value = '';
document.getElementById('level').value = '';
document.getElementById('lecturerStatus').value = 'present';
})
.catch(error => console.error('Error resetting attendance data:', error));
}
// Function to view the previous attendance
function viewPreviousAttendance() {
if (previousAttendance.length === 0) {
alert("No previous attendance records available.");
return;
}
const lastSession = previousAttendance.pop(); // Get the last attendance record
// Restore the details in the form
document.getElementById('programme').value = lastSession.details.programme;
document.getElementById('intake').value = lastSession.details.intake;
document.getElementById('date').value = lastSession.details.date;
document.getElementById('courseTitle').value = lastSession.details.courseTitle;
document.getElementById('courseCode').value = lastSession.details.courseCode;
document.getElementById('level').value = lastSession.details.level;
document.getElementById('startTime').value = lastSession.details.startTime;
document.getElementById('endTime').value = lastSession.details.endTime;
document.getElementById('courseRep').value = lastSession.details.courseRep;
document.getElementById('lecturer').value = lastSession.details.lecturer;
document.getElementById('lecturerStatus').value = lastSession.details.lecturerStatus;
// Restore the attendance in the table
const tableBody = document.getElementById('attendanceTable').querySelector('tbody');
tableBody.innerHTML = ''; // Clear the table before inserting previous data
lastSession.attendance.forEach(record => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${record.id}</td>
<td>${record.name}</td>
<td>${record.status}</td>
`;
tableBody.appendChild(row);
});
}
// Function to print the attendance table
function printAttendance() {
window.print();
}
</script>
</body>
</html>