-
Notifications
You must be signed in to change notification settings - Fork 0
/
timetable.html
209 lines (194 loc) · 7.51 KB
/
timetable.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta viewport="width=device-width, initial-scale=1.0">
<title>Timetable System</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap">
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
font-family: 'Roboto', sans-serif;
background-color: #e6e6e6;
color: #333;
}
.header {
background-color: #003366;
color: white;
text-align: center;
padding: 20px;
}
.selector, .attendance {
text-align: center;
margin: 20px;
}
button, select {
padding: 10px 20px;
font-size: 16px;
margin: 5px;
cursor: pointer;
}
table {
width: 90%;
border-collapse: collapse;
margin: 20px auto;
}
th, td {
border: 1px solid #0055b3;
padding: 10px;
text-align: left;
background-color: #007bff;
color: white;
}
th {
background-color: #003366;
}
.hidden {
display: none;
}
</style>
</head>
<body>
<div class="header">
<h1>Timetable System</h1>
</div>
<div class="selector">
<button onclick="changeMode('student')">Student Mode</button>
<button onclick="changeMode('tutor')">Tutor Mode</button>
<button onclick="changeMode('admin')">Admin Mode</button>
<select id="adminView" class="hidden" onchange="adminSelectClass()">
<option value="">Select Class for Details</option>
</select>
</div>
<table id="timetable" class="hidden">
<thead>
<tr>
<th>Time</th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div id="attendanceList" class="attendance hidden">
<h2>Attendance</h2>
<ul id="studentAttendance"></ul>
</div>
<script>
const classes = {
"Tutor1": {
"9:00-10:00": {"Monday": { subject: "Maths Lecture", room: "SJ1/2", students: ["William", "Bob"] }},
"10:00-11:00": {"Monday": { subject: "Operating Systems", room: "SJ2/4", students: ["William"] }},
},
"Tutor2": {
"9:00-10:00": {"Monday": { subject: "Cybersecurity", room: "OA1/2", students: ["Hussain", "Steve"] }},
"10:00-11:00": {"Monday": { subject: "Team Project", room: "OA2/1", students: ["Bob", "Hussain"] }},
}
};
const studentClasses = {
"William": ["Maths Lecture", "Operating Systems"],
"Bob": ["Maths Lecture", "Team Project"],
"Hussain": ["Cybersecurity", "Team Project"],
"Steve": ["Cybersecurity"],
};
let currentMode = '';
function changeMode(mode) {
currentMode = mode;
document.getElementById('adminView').classList.add('hidden');
document.getElementById('timetable').classList.add('hidden');
document.getElementById('attendanceList').classList.add('hidden');
if (mode === 'admin') {
populateAdminDropdown();
} else {
displayTimetable(mode);
}
}
document.addEventListener('DOMContentLoaded', function() {
initialiseAttendance();
updateAttendanceDisplay();
});
function initialiseAttendance() {
// Reset William's attendance to "Absent" at each page load
localStorage.setItem('William-Maths Lecture', 'Absent');
localStorage.setItem('William-Operating Systems', 'Absent');
}
function updateAttendanceDisplay() {
const attendanceList = document.getElementById('studentAttendance');
attendanceList.innerHTML = ''; // Clear current list
studentClasses['William'].forEach(classSubject => {
let attendanceStatus = localStorage.getItem(`William-${classSubject}`);
let li = document.createElement('li');
li.textContent = `${classSubject}: ${attendanceStatus}`;
attendanceList.appendChild(li);
});
}
function displayTimetable(mode) {
const timetableBody = document.getElementById('timetable').getElementsByTagName('tbody')[0];
timetableBody.innerHTML = '';
document.getElementById('timetable').classList.remove('hidden');
if (mode === 'student' || mode === 'admin') {
Object.entries(classes).forEach(([tutor, timeSlots]) => {
Object.entries(timeSlots).forEach(([time, days]) => {
Object.entries(days).forEach(([day, {subject, room, students}]) => {
if (mode === 'student' && studentClasses['William'].includes(subject)) {
let row = timetableBody.insertRow();
row.innerHTML = `<td>${time}</td><td>${day}: ${subject} - ${room}</td>`;
}
if (mode === 'admin') {
let row = timetableBody.insertRow();
row.innerHTML = `<td>${time}</td><td>${day}: ${subject} - ${room} <button onclick='showAttendance("${subject}", ${JSON.stringify(students)})'>Show Attendance</button></td>`;
}
});
});
});
} else {
let modeData = classes['Tutor1'];
Object.entries(modeData).forEach(([time, days]) => {
Object.entries(days).forEach(([day, {subject, room, students}]) => {
let row = timetableBody.insertRow();
row.innerHTML = `<td>${time}</td><td>${day}: ${subject} - ${room} <button onclick='showAttendance("${subject}", ${JSON.stringify(students)})'>Show Attendance</button> <a href='admin.html?subject=${encodeURIComponent(subject)}&tutor=${encodeURIComponent("Tutor1")}' target='_blank'><button>QR Code</button></a></td>`;
});
});
}
}
function populateAdminDropdown() {
const adminView = document.getElementById('adminView');
adminView.innerHTML = '<option value="">Select Class for Details</option>';
adminView.classList.remove('hidden');
Object.keys(classes).forEach(tutor => {
Object.keys(classes[tutor]).forEach(time => {
Object.keys(classes[tutor][time]).forEach(day => {
const subject = classes[tutor][time][day].subject;
let option = document.createElement('option');
option.value = `${tutor}-${time}-${day}`;
option.textContent = `Tutor: ${tutor}, Time: ${time}, Day: ${day}, Subject: ${subject}`;
adminView.appendChild(option);
});
});
});
}
function adminSelectClass() {
const selectedValue = document.getElementById('adminView').value;
if (!selectedValue) return;
const [tutor, time, day] = selectedValue.split('-');
displayTimetable('admin');
}
function showAttendance(subject, students) {
document.getElementById('attendanceList').classList.remove('hidden');
const list = document.getElementById('studentAttendance');
list.innerHTML = '';
students.forEach(student => {
let li = document.createElement('li');
li.textContent = `${student} - Present`;
list.appendChild(li);
});
}
</script>
</body>
</html>