WASTELESSV6 / students-ate.html
EHDEM's picture
Update students-ate.html
274345c verified
Raw History Blame Contribute Delete
30.6 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WASTE-LESS - Attendance Form B</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link rel="stylesheet" href="style.css">
</head>
<body class="min-h-screen">
<custom-navbar></custom-navbar>
<div class="container mx-auto px-4 py-12 max-w-4xl">
<!-- Header -->
<header class="relative overflow-hidden rounded-2xl shadow-2xl mb-12 text-white p-8">
<div class="absolute inset-0 bg-gradient-to-r from-green-600 via-emerald-600 to-teal-600"></div>
<div class="absolute inset-0 opacity-10" style="background: url('data:image/svg+xml,<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><path d="M0,0 L100,0 L100,100 Q50,80 0,100 Z" fill="white"/></svg>')"></div>
<div class="relative z-10">
<div class="flex flex-col md:flex-row justify-between items-center">
<div class="mb-6 md:mb-0">
<a href="index.html" class="inline-flex items-center text-white/90 hover:text-white mb-4 transition-colors">
<i class="fas fa-arrow-left mr-2"></i> Back to Home
</a>
<h1 class="text-4xl md:text-5xl font-bold tracking-tight">Attendance Form B</h1>
<p class="text-white/90 text-xl mt-3 max-w-2xl">For Students Who Have Eaten At The Dining Hall</p>
</div>
<div class="flex items-center space-x-6">
<div class="text-center">
<div class="text-3xl" id="meal-period-icon"><i class="fas fa-utensils"></i></div>
<div class="text-sm opacity-90">Meal Period</div>
</div>
<div class="text-center">
<div class="text-3xl"><i class="fas fa-calendar-alt"></i></div>
<div class="text-sm opacity-90">Schedule</div>
</div>
<div class="text-center">
<div class="text-3xl"><i class="fas fa-users"></i></div>
<div class="text-sm opacity-90">Students</div>
</div>
</div>
</div>
</div>
</header>
<!-- Current Time Display -->
<div class="card mb-8 text-center bg-gradient-to-r from-green-50 to-emerald-50 border-green-100">
<div class="flex flex-col md:flex-row items-center justify-between">
<div class="mb-4 md:mb-0">
<div class="text-3xl md:text-4xl font-bold text-gray-800" id="current-time">Loading time...</div>
<div class="text-green-600 font-medium text-lg" id="current-date">Loading date...</div>
</div>
<div class="bg-white rounded-xl p-4 shadow-lg">
<div class="text-sm text-gray-600">Current meal period</div>
<div class="text-xl font-bold text-green-600" id="current-meal-time">Loading...</div>
<div class="text-sm text-gray-500">Next: <span id="next-meal-time" class="font-medium">Loading...</span></div>
</div>
</div>
</div>
<!-- RFID Scanner -->
<div class="card mb-8 bg-gradient-to-r from-blue-50 to-indigo-50 border-blue-200">
<div class="flex items-center mb-4">
<div class="bg-blue-100 p-3 rounded-full mr-4">
<i class="fas fa-wifi text-blue-600 text-xl"></i>
</div>
<div>
<h2 class="text-xl font-bold text-gray-800">RFID Card Scan</h2>
<p class="text-gray-600 text-sm">Tap your card or enter the ID manually</p>
</div>
</div>
<div class="flex flex-col md:flex-row gap-4 items-end">
<div class="flex-1">
<input type="text" id="rfid-input" class="w-full px-4 py-3 border-2 border-blue-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 font-mono text-lg tracking-widest" placeholder="Tap card here..." autocomplete="off" autofocus>
</div>
<button id="rfid-scan-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-6 rounded-lg transition shadow-lg">
<i class="fas fa-search mr-2"></i>Lookup
</button>
</div>
<div id="rfid-status" class="mt-4 hidden p-3 rounded-lg text-sm font-medium"></div>
</div>
<!-- Meal Periods & Menu -->
<div class="card mb-8">
<h2 class="text-2xl font-bold mb-6 text-gray-800 border-b pb-4">Meal Periods & Menu</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
<div class="meal-card p-5 rounded-xl border-2 border-yellow-200 bg-gradient-to-br from-yellow-50 to-yellow-100 cursor-pointer transition-all duration-300 hover:scale-105 hover:shadow-lg" data-meal="breakfast" onclick="selectMeal('breakfast')">
<div class="flex items-center">
<div class="bg-yellow-100 p-3 rounded-full mr-4">
<i class="fas fa-sun text-yellow-600 text-2xl"></i>
</div>
<div>
<div class="text-lg font-bold text-yellow-800">Breakfast</div>
<div class="text-yellow-600 text-sm">6:20 AM - 6:50 AM</div>
</div>
</div>
</div>
<div class="meal-card p-5 rounded-xl border-2 border-green-200 bg-gradient-to-br from-green-50 to-green-100 cursor-pointer transition-all duration-300 hover:scale-105 hover:shadow-lg" data-meal="lunch" onclick="selectMeal('lunch')">
<div class="flex items-center">
<div class="bg-green-100 p-3 rounded-full mr-4">
<i class="fas fa-utensils text-green-600 text-2xl"></i>
</div>
<div>
<div class="text-lg font-bold text-green-800">Lunch</div>
<div class="text-green-600 text-sm">1:30 PM - 2:30 PM</div>
</div>
</div>
</div>
<div class="meal-card p-5 rounded-xl border-2 border-indigo-200 bg-gradient-to-br from-indigo-50 to-indigo-100 cursor-pointer transition-all duration-300 hover:scale-105 hover:shadow-lg" data-meal="dinner" onclick="selectMeal('dinner')">
<div class="flex items-center">
<div class="bg-indigo-100 p-3 rounded-full mr-4">
<i class="fas fa-moon text-indigo-600 text-2xl"></i>
</div>
<div>
<div class="text-lg font-bold text-indigo-800">Dinner</div>
<div class="text-indigo-600 text-sm">5:50 PM - 7:00 PM</div>
</div>
</div>
</div>
<div class="meal-card p-5 rounded-xl border-2 border-purple-200 bg-gradient-to-br from-purple-50 to-purple-100 cursor-pointer transition-all duration-300 hover:scale-105 hover:shadow-lg" data-meal="supper" onclick="selectMeal('supper')">
<div class="flex items-center">
<div class="bg-purple-100 p-3 rounded-full mr-4">
<i class="fas fa-bed text-purple-600 text-2xl"></i>
</div>
<div>
<div class="text-lg font-bold text-purple-800">Supper</div>
<div class="text-purple-600 text-sm">10:30 PM - 11:00 PM</div>
</div>
</div>
</div>
</div>
<!-- Menu Panel -->
<div id="menu-panel" class="rounded-xl border-2 border-green-200 bg-gradient-to-br from-green-50 to-emerald-50 p-6 transition-all duration-500">
<div class="flex items-center mb-4">
<div id="menu-icon" class="bg-white p-3 rounded-full shadow mr-4">
<i class="fas fa-utensils text-green-600 text-xl"></i>
</div>
<div>
<h3 class="text-xl font-bold text-gray-800" id="menu-title">Select a Meal Period</h3>
<p class="text-gray-600 text-sm" id="menu-subtitle">Click a card above to view the menu</p>
</div>
</div>
<div id="menu-items" class="grid grid-cols-1 md:grid-cols-2 gap-3">
<div class="text-gray-500 italic p-4 text-center bg-white/50 rounded-lg">Please select a meal period to view its menu</div>
</div>
</div>
</div>
<!-- Attendance Form -->
<div id="attendance-form" class="bg-white rounded-lg shadow-md p-6 mb-8">
<h2 class="text-xl font-semibold mb-4 text-gray-800">Attendance Form</h2>
<div id="eating-details" class="space-y-4">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label for="class" class="block text-gray-700 font-medium mb-2">Class</label>
<select id="class" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500" onchange="loadStudents()">
<option value="">Select Class</option>
</select>
</div>
<div>
<label for="form" class="block text-gray-700 font-medium mb-2">Form</label>
<select id="form" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500" onchange="loadStudents()">
<option value="">Select Form</option>
<option value="1">Form 1</option>
<option value="2">Form 2</option>
<option value="3">Form 3</option>
<option value="4">Form 4</option>
<option value="5">Form 5</option>
</select>
</div>
</div>
<div id="student-container" class="mt-4 hidden">
<label for="student" class="block text-gray-700 font-medium mb-2">Student Name</label>
<select id="student" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500" disabled>
<option value="">Please select Class and Form first</option>
</select>
</div>
</div>
<div class="mt-6">
<button id="submit-btn" class="w-full bg-green-600 hover:bg-green-700 text-white font-bold py-3 px-4 rounded-lg transition duration-200">
<i class="fas fa-check-circle mr-2"></i> Confirm Meal Taken
</button>
</div>
</div>
<!-- Success Message -->
<div id="success-message" class="hidden fade-in bg-green-50 border border-green-200 text-green-700 p-4 rounded-lg mb-8">
<div class="flex items-center mb-3">
<i class="fas fa-check-circle text-green-500 text-2xl mr-3"></i>
<div>
<h3 class="font-bold">Meal Confirmed Successfully!</h3>
<p class="text-sm">Your dining hall meal has been confirmed.</p>
</div>
</div>
<button id="fill-again-btn" class="w-full bg-green-600 hover:bg-green-700 text-white font-medium py-2 px-4 rounded transition duration-200">
<i class="fas fa-redo mr-2"></i> Fill Again
</button>
</div>
<!-- Footer -->
<footer class="text-center text-gray-600 text-sm mt-12">
<p>© 2025 Waste-Less Dining Hall Attendance System. All rights reserved.</p>
<p class="mt-1">Data will be saved to <a href="https://github.com/SMSS-Waste-Less/Waste-LessV5/blob/main/data%20who%20has%20ate%20at%20dm" class="text-green-600 hover:underline">GitHub repository</a></p>
</footer>
</div>
<script src="config.js"></script>
<script>
// Dynamic student list
let students = {};
let availableClasses = [];
async function loadStudentList() {
try {
const response = await fetch(`https://api.github.com/repos/${GITHUB_CONFIG.REPOS.STUDENT_LIST || GITHUB_CONFIG.REPOS.ATTENDANCE}/contents/student-list.json`, {
headers: {
'Authorization': `token ${GITHUB_CONFIG.TOKEN}`,
'Accept': 'application/vnd.github.v3+json'
}
});
if (response.status === 404) {
students = {};
availableClasses = [];
updateClassDropdown();
return;
}
if (!response.ok) throw new Error('Failed to load student list');
const data = await response.json();
students = JSON.parse(atob(data.content));
// Extract unique classes
availableClasses = [...new Set(Object.keys(students).map(key => key.split('-')[0]))].sort();
updateClassDropdown();
} catch (error) {
console.error('Error loading student list:', error);
alert('Could not load student list. Using empty list.');
students = {};
availableClasses = [];
updateClassDropdown();
}
loadStudents(); // Initial load
}
function updateClassDropdown() {
const classSelect = document.getElementById('class');
classSelect.innerHTML = '<option value="">Select Class</option>';
availableClasses.forEach(cls => {
const opt = document.createElement('option');
opt.value = cls;
opt.textContent = cls;
classSelect.appendChild(opt);
});
}
// Load students based on selected class and form
function loadStudents() {
const classVal = document.getElementById('class').value;
const formVal = document.getElementById('form').value;
const studentContainer = document.getElementById('student-container');
const studentSelect = document.getElementById('student');
studentSelect.innerHTML = '<option value="">Select Student</option>';
studentSelect.disabled = true;
studentContainer.classList.add('hidden');
if (classVal && formVal) {
const key = `${classVal}-${formVal}`;
if (students[key] && students[key].length > 0) {
students[key].forEach(name => {
const option = document.createElement('option');
option.value = name;
option.textContent = name;
studentSelect.appendChild(option);
});
studentSelect.disabled = false;
studentContainer.classList.remove('hidden');
} else {
studentSelect.innerHTML = '<option value="">No students found</option>';
}
}
}
// Load student list on page load
window.addEventListener('load', () => { loadStudentList(); loadRfidDatabase(); });
// RFID Database
let rfidDatabase = {};
async function loadRfidDatabase() {
try {
const response = await fetch(`https://api.github.com/repos/${GITHUB_CONFIG.REPOS.ATTENDANCE}/contents/${GITHUB_CONFIG.PATHS.RFID_DB}`, {
headers: { 'Authorization': `token ${GITHUB_CONFIG.TOKEN}`, 'Accept': 'application/vnd.github.v3+json' }
});
if (response.ok) {
const data = await response.json();
rfidDatabase = JSON.parse(atob(data.content));
console.log('RFID DB loaded:', Object.keys(rfidDatabase).length, 'cards');
} else {
rfidDatabase = {};
}
} catch (e) {
console.error('RFID DB load error:', e);
rfidDatabase = {};
}
}
function showRfidStatus(type, message) {
const status = document.getElementById('rfid-status');
status.classList.remove('hidden', 'bg-green-100', 'text-green-700', 'bg-red-100', 'text-red-700');
if (type === 'success') {
status.classList.add('bg-green-100', 'text-green-700');
} else {
status.classList.add('bg-red-100', 'text-red-700');
}
status.innerHTML = `<i class="fas ${type === 'success' ? 'fa-check-circle' : 'fa-exclamation-circle'} mr-2"></i>${message}`;
status.classList.remove('hidden');
}
function lookupRfid(rfidId) {
rfidId = rfidId.trim();
if (!rfidId) return;
const record = rfidDatabase[rfidId];
if (record) {
document.getElementById('class').value = record.class;
document.getElementById('form').value = record.form;
loadStudents();
setTimeout(() => {
const studentSelect = document.getElementById('student');
for (let i = 0; i < studentSelect.options.length; i++) {
if (studentSelect.options[i].value === record.studentName) {
studentSelect.selectedIndex = i;
break;
}
}
}, 200);
showRfidStatus('success', `Card recognized: <strong>${record.studentName}</strong> (${record.class} Form ${record.form})`);
} else {
showRfidStatus('error', 'Card ID not found in database. Please use manual entry or contact admin.');
}
}
document.getElementById('rfid-input').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
lookupRfid(this.value);
this.value = '';
}
});
document.getElementById('rfid-scan-btn').addEventListener('click', function() {
const input = document.getElementById('rfid-input');
lookupRfid(input.value);
input.value = '';
});
// Improved Meal Selection
function selectMeal(mealTime) {
selectedMeal = mealTime;
document.querySelectorAll('.meal-card').forEach(card => {
card.classList.remove('ring-4', 'ring-offset-2', 'ring-blue-400', 'scale-105', 'shadow-xl');
if (card.dataset.meal === mealTime) {
card.classList.add('ring-4', 'ring-offset-2', 'ring-blue-400', 'scale-105', 'shadow-xl');
}
});
const mealInfo = {
breakfast: { title: 'Breakfast Menu', subtitle: '6:20 AM - 6:50 AM', icon: 'fa-sun', color: 'text-yellow-600', border: 'border-yellow-200', bg: 'from-yellow-50 to-yellow-100' },
lunch: { title: 'Lunch Menu', subtitle: '1:30 PM - 2:30 PM', icon: 'fa-utensils', color: 'text-green-600', border: 'border-green-200', bg: 'from-green-50 to-green-100' },
dinner: { title: 'Dinner Menu', subtitle: '5:50 PM - 7:00 PM', icon: 'fa-moon', color: 'text-indigo-600', border: 'border-indigo-200', bg: 'from-indigo-50 to-indigo-100' },
supper: { title: 'Supper Menu', subtitle: '10:30 PM - 11:00 PM', icon: 'fa-bed', color: 'text-purple-600', border: 'border-purple-200', bg: 'from-purple-50 to-purple-100' }
};
const info = mealInfo[mealTime];
document.getElementById('menu-title').textContent = info.title;
document.getElementById('menu-subtitle').textContent = info.subtitle;
const iconEl = document.getElementById('menu-icon').querySelector('i');
iconEl.className = `fas ${info.icon} ${info.color} text-xl`;
const panel = document.getElementById('menu-panel');
panel.className = `rounded-xl border-2 ${info.border} bg-gradient-to-br ${info.bg} p-6 transition-all duration-500`;
const items = document.getElementById('menu-items');
items.innerHTML = '';
menus[mealTime].regular.forEach(item => {
const div = document.createElement('div');
div.className = 'flex items-center bg-white p-3 rounded-lg shadow-sm';
div.innerHTML = `<i class="fas fa-circle text-xs ${info.color} mr-3"></i><span class="font-medium text-gray-700">${item}</span>`;
items.appendChild(div);
});
document.getElementById('attendance-form').classList.remove('hidden');
}
// Auto-select current meal on load
if (isCurrentTimeMealPeriod()) {
setTimeout(() => selectMeal(getCurrentMealTime()), 500);
}
// === Rest of your existing code (time, meal menu, submission, etc.) unchanged ===
function updateDateTime() {
const now = new Date();
document.getElementById('current-time').textContent = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
document.getElementById('current-date').textContent = now.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
const currentMeal = getCurrentMealTime();
document.getElementById('current-meal-time').textContent = currentMeal.charAt(0).toUpperCase() + currentMeal.slice(1);
const hours = now.getHours();
let nextMeal = '';
if (hours < 6) nextMeal = 'Breakfast (6:20 AM)';
else if (hours < 13) nextMeal = 'Lunch (1:30 PM)';
else if (hours < 17) nextMeal = 'Dinner (5:50 PM)';
else if (hours < 22) nextMeal = 'Supper (10:30 PM)';
else nextMeal = 'Breakfast (6:20 AM)';
document.getElementById('next-meal-time').textContent = nextMeal;
}
setInterval(updateDateTime, 1000);
updateDateTime();
function getCurrentMealTime() {
const now = new Date();
const hours = now.getHours();
const minutes = now.getMinutes();
if ((hours === 6 && minutes >= 20) || (hours === 6 && minutes <= 50)) return 'breakfast';
if ((hours === 13 && minutes >= 30) || (hours === 14 && minutes <= 30)) return 'lunch';
if ((hours === 17 && minutes >= 50) || hours === 18 || (hours === 19 && minutes <= 0)) return 'dinner';
if ((hours === 22 && minutes >= 30) || hours === 23) return 'supper';
if (hours < 6) return 'breakfast';
if (hours < 13) return 'lunch';
if (hours < 17) return 'dinner';
if (hours < 22) return 'supper';
return 'breakfast';
}
function isCurrentTimeMealPeriod() {
const now = new Date();
const hours = now.getHours();
const minutes = now.getMinutes();
return (
(hours === 6 && minutes >= 20 && minutes <= 50) ||
(hours === 13 && minutes >= 30 || hours === 14 && minutes <= 30) ||
(hours === 17 && minutes >= 50 || hours === 18 || (hours === 19 && minutes <= 0)) ||
(hours === 22 && minutes >= 30 || hours === 23)
);
}
const menus = {
breakfast: { regular: ["Nasi Lemak with Fried Chicken", "Fried Noodles with Vegetables", "Fruits (Watermelon & Papaya)", "Teh Tarik / Coffee"] },
lunch: { regular: ["Steamed Rice with Beef Rendang", "Stir-fried Vegetables", "Fish Ball Soup", "Fruits (Pineapple & Dragon Fruit)"] },
dinner: { regular: ["Fried Rice with Chicken Satay", "Mixed Vegetables", "Egg Drop Soup", "Fruits (Apple & Pear)"] },
supper: { regular: ["Sandwiches with Egg Mayo", "Milo and Biscuits", "Fruits (Banana)"] }
};
let selectedMeal = getCurrentMealTime();
async function sendDataToGitHub(data) {
try {
// First check if file exists and get current content
let currentContent = '';
let sha = '';
const filePath = 'data%20who%20has%20ate%20at%20dm';
const repoUrl = `https://api.github.com/repos/${GITHUB_CONFIG.REPOS.ATTENDANCE}/contents/${filePath}`;
const getResponse = await fetch(repoUrl, {
headers: {
'Authorization': `token ${GITHUB_CONFIG.TOKEN}`,
'Accept': 'application/vnd.github.v3+json'
}
});
if (getResponse.ok) {
const fileData = await getResponse.json();
sha = fileData.sha;
currentContent = atob(fileData.content);
} else if (getResponse.status !== 404) {
throw new Error('Failed to fetch existing data');
}
// Prepare new content
const record = JSON.stringify(data);
const newContent = currentContent + record + '\n';
// Create or update file
const response = await fetch(repoUrl, {
method: 'PUT',
headers: {
'Authorization': `token ${GITHUB_CONFIG.TOKEN}`,
'Content-Type': 'application/json',
'Accept': 'application/vnd.github.v3+json'
},
body: JSON.stringify({
message: `Attendance record - ${new Date().toLocaleString()}`,
content: btoa(newContent),
sha: sha || undefined,
branch: 'main'
})
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.message || 'Submission failed');
}
return true;
} catch (error) {
console.error('Submission error:', error);
throw new Error('Failed to submit attendance: ' + error.message);
}
}
// Submit handler
document.getElementById('submit-btn').addEventListener('click', async function() {
this.disabled = true;
this.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i> Submitting...';
const studentClass = document.getElementById('class').value;
const form = document.getElementById('form').value;
const student = document.getElementById('student').value;
if (!student) {
alert('Please select a student name');
this.disabled = false;
this.innerHTML = '<i class="fas fa-check-circle mr-2"></i> Confirm Meal Taken';
return;
}
if (!studentClass || !form) {
alert('Please select both class and form');
this.disabled = false;
this.innerHTML = '<i class="fas fa-check-circle mr-2"></i> Confirm Meal Taken';
return;
}
const now = new Date();
const data = {
timestamp: now.toISOString(),
date: now.toISOString().split('T')[0],
mealTime: selectedMeal || getCurrentMealTime(),
attendance: 'yes',
class: studentClass,
form: form,
studentName: student
};
try {
const success = await sendDataToGitHub(data);
if (success) {
document.getElementById('attendance-form').classList.add('hidden');
document.getElementById('success-message').classList.remove('hidden');
document.getElementById('success-message').classList.add('fade-in');
}
} catch (error) {
alert('Failed to submit: ' + error.message);
} finally {
this.disabled = false;
this.innerHTML = '<i class="fas fa-check-circle mr-2"></i> Confirm Meal Taken';
}
});
function resetForm() {
document.getElementById('class').value = '';
document.getElementById('form').value = '';
document.getElementById('student').innerHTML = '<option value="">Select Student</option>';
document.getElementById('student').disabled = true;
document.getElementById('student-container').classList.add('hidden');
document.getElementById('success-message').classList.add('hidden');
document.getElementById('attendance-form').classList.remove('hidden');
if (isCurrentTimeMealPeriod()) {
selectMeal(getCurrentMealTime());
}
}
document.getElementById('fill-again-btn').addEventListener('click', resetForm);
setInterval(() => {
const currentMeal = getCurrentMealTime();
if (currentMeal !== selectedMeal) {
selectedMeal = currentMeal;
if (document.getElementById('menu-panel')) {
selectMeal(selectedMeal);
}
}
}, 60000);
</script>
</body>
</html>