-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccess website.html
376 lines (315 loc) · 12.1 KB
/
Access website.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
374
375
376
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Server Access Scheduler</title>
<style>
:root {
--primary-color: #3498db;
--primary-dark: #2980b9;
--success-color: #2ecc71;
--danger-color: #e74c3c;
--bg-color: #ecf0f1;
--card-bg: #ffffff;
--text-primary: #2c3e50;
--border-color: #dfe6e9;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', sans-serif;
background-color: var(--bg-color);
color: var(--text-primary);
line-height: 1.6;
padding: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
background: var(--card-bg);
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
h1, h2 {
color: var(--primary-color);
margin-bottom: 20px;
text-align: center;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input, select {
width: 100%;
padding: 8px;
border: 1px solid var(--border-color);
border-radius: 4px;
margin-bottom: 10px;
}
.time-period-selector {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.time-slots {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
gap: 10px;
margin: 20px 0;
}
.time-slot {
padding: 10px;
text-align: center;
border-radius: 4px;
cursor: pointer;
}
.time-slot.available {
background-color: var(--success-color);
color: white;
}
.time-slot.booked {
background-color: var(--danger-color);
color: white;
cursor: not-allowed;
}
.time-slot.selected {
background-color: var(--primary-color);
color: white;
}
button {
background-color: var(--primary-color);
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
width: 100%;
font-size: 16px;
}
button:hover {
background-color: var(--primary-dark);
}
#bookedSlotsList {
margin-top: 30px;
padding-top: 20px;
border-top: 1px solid var(--border-color);
}
#bookedSlotsDisplay {
list-style: none;
}
#bookedSlotsDisplay li {
padding: 10px;
margin: 5px 0;
background: #f8f9fa;
border-radius: 4px;
border-left: 4px solid var(--primary-color);
}
.admin-controls {
margin-top: 30px;
padding: 20px;
background: #f8f9fa;
border-radius: 4px;
}
.error-message {
color: var(--danger-color);
margin-top: 10px;
}
.success-message {
color: var(--success-color);
margin-top: 10px;
}
@media (max-width: 600px) {
.time-period-selector {
grid-template-columns: 1fr;
}
.container {
padding: 10px;
}
}
</style>
</head>
<body>
<div class="container">
<h1>Server Access Scheduler</h1>
<form id="scheduleForm">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" id="name" required placeholder="Enter your name">
</div>
<div class="form-group">
<label for="date">Date:</label>
<input type="date" id="date" required>
</div>
<div class="form-group">
<label>Time Period:</label>
<div class="time-period-selector">
<select id="startTime" required>
<option value="">Start Time</option>
</select>
<select id="endTime" required>
<option value="">End Time</option>
</select>
</div>
</div>
<div class="form-group">
<label>Available Time Slots:</label>
<div id="timeSlots" class="time-slots"></div>
</div>
<button type="submit">Book Slot</button>
</form>
<div id="bookedSlotsList">
<h2>Booked Slots</h2>
<ul id="bookedSlotsDisplay"></ul>
</div>
<div class="admin-controls">
<h2>Admin Controls</h2>
<input type="password" id="adminPassword" placeholder="Enter admin password">
<button id="clearSlots">Clear All Booked Slots</button>
<div id="adminMessage"></div>
</div>
</div>
<script>
const form = document.getElementById('scheduleForm');
const timeSlotsContainer = document.getElementById('timeSlots');
const bookedSlotsDisplay = document.getElementById('bookedSlotsDisplay');
const dateInput = document.getElementById('date');
const startTimeSelect = document.getElementById('startTime');
const endTimeSelect = document.getElementById('endTime');
const adminPassword = document.getElementById('adminPassword');
const clearSlotsButton = document.getElementById('clearSlots');
const adminMessage = document.getElementById('adminMessage');
const ADMIN_PASSWORD = "admin123";
let bookedSlots = JSON.parse(localStorage.getItem('bookedSlots')) || [];
function cleanupPastBookings() {
const currentDate = new Date();
currentDate.setHours(0, 0, 0, 0);
bookedSlots = bookedSlots.filter(slot => {
const slotDate = new Date(slot.date);
slotDate.setHours(0, 0, 0, 0);
return slotDate >= currentDate;
});
localStorage.setItem('bookedSlots', JSON.stringify(bookedSlots));
}
function setMinDate() {
const today = new Date().toISOString().split('T')[0];
dateInput.min = today;
if (!dateInput.value) {
dateInput.value = today;
}
}
function generateTimeOptions() {
startTimeSelect.innerHTML = '<option value="">Start Time</option>';
endTimeSelect.innerHTML = '<option value="">End Time</option>';
for (let hour = 9; hour <= 17; hour++) {
for (let minute of ['00', '30']) {
const time = `${hour.toString().padStart(2, '0')}:${minute}`;
startTimeSelect.add(new Option(time, time));
endTimeSelect.add(new Option(time, time));
}
}
}
function generateTimeSlots() {
const start = startTimeSelect.value;
const end = endTimeSelect.value;
if (!start || !end) return;
timeSlotsContainer.innerHTML = '';
const [startHour, startMinute] = start.split(':').map(Number);
const [endHour, endMinute] = end.split(':').map(Number);
const startTime = startHour * 60 + startMinute;
const endTime = endHour * 60 + endMinute;
for (let time = startTime; time <= endTime; time += 30) {
const hour = Math.floor(time / 60);
const minute = time % 60;
const timeSlot = `${hour.toString().padStart(2, '0')}:${minute.toString().padStart(2, '0')}`;
const slotElement = document.createElement('div');
slotElement.classList.add('time-slot');
slotElement.textContent = timeSlot;
const isBooked = bookedSlots.some(
slot => slot.date === dateInput.value && slot.time === timeSlot
);
if (isBooked) {
slotElement.classList.add('booked');
} else {
slotElement.classList.add('available');
slotElement.addEventListener('click', () => selectTimeSlot(timeSlot));
}
timeSlotsContainer.appendChild(slotElement);
}
}
function selectTimeSlot(slot) {
const selectedSlots = document.querySelectorAll('.time-slot.selected');
selectedSlots.forEach(el => el.classList.remove('selected'));
const clickedSlot = Array.from(timeSlotsContainer.children)
.find(el => el.textContent === slot);
if (clickedSlot && !clickedSlot.classList.contains('booked')) {
clickedSlot.classList.add('selected');
}
}
function updateBookedSlots() {
bookedSlotsDisplay.innerHTML = '';
bookedSlots.forEach(slot => {
const li = document.createElement('li');
li.textContent = `${slot.name} - ${slot.date} at ${slot.time}`;
bookedSlotsDisplay.appendChild(li);
});
}
form.addEventListener('submit', function(e) {
e.preventDefault();
const name = document.getElementById('name').value;
const date = dateInput.value;
const selectedSlot = document.querySelector('.time-slot.selected');
if (!selectedSlot) {
alert('Please select a time slot');
return;
}
const newBooking = {
name,
date,
time: selectedSlot.textContent
};
bookedSlots.push(newBooking);
localStorage.setItem('bookedSlots', JSON.stringify(bookedSlots));
updateBookedSlots();
form.reset();
setMinDate();
generateTimeOptions();
timeSlotsContainer.innerHTML = '';
});
dateInput.addEventListener('change', function() {
generateTimeOptions();
generateTimeSlots();
});
startTimeSelect.addEventListener('change', generateTimeSlots);
endTimeSelect.addEventListener('change', generateTimeSlots);
clearSlotsButton.addEventListener('click', function() {
if (adminPassword.value === ADMIN_PASSWORD) {
bookedSlots = [];
localStorage.setItem('bookedSlots', JSON.stringify(bookedSlots));
updateBookedSlots();
generateTimeOptions();
adminMessage.textContent = "All slots cleared successfully!";
adminMessage.className = "success-message";
adminPassword.value = "";
timeSlotsContainer.innerHTML = '';
} else {
adminMessage.textContent = "Incorrect password!";
adminMessage.className = "error-message";
}
});
// Initialize
cleanupPastBookings();
setMinDate();
generateTimeOptions();
updateBookedSlots();
</script>
</body>
</html>