Spaces:
Running
Running
File size: 5,891 Bytes
e38e840 c485f2a |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Attendance Tracking System</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container mt-5">
<h1 class="text-center">Attendance Tracking System</h1>
<div id="studentSection">
<h2>Student Login</h2>
<form id="studentForm" class="mb-4">
<div class="form-group">
<label for="studentId">Student ID</label>
<input type="text" class="form-control" id="studentId" required>
</div>
<div class="form-group">
<label for="studentName">Student Name</label>
<input type="text" class="form-control" id="studentName" required>
</div>
<button type="submit" class="btn btn-primary">Submit Attendance</button>
</form>
</div>
<div id="teacherSection" class="mt-5">
<h2>Teacher/Admin Login</h2>
<form id="teacherForm" class="mb-4">
<div class="form-group">
<label for="teacherUsername">Username</label>
<input type="text" class="form-control" id="teacherUsername" required>
</div>
<div class="form-group">
<label for="teacherPassword">Password</label>
<input type="password" class="form-control" id="teacherPassword" required>
</div>
<button type="submit" class="btn btn-primary">View Attendance Report</button>
</form>
</div>
<div id="attendanceReport" class="mt-5" style="display: none;">
<h2>Attendance Report</h2>
<table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>Student ID</th>
<th>Student Name</th>
<th>Date</th>
<th>Time</th>
</tr>
</thead>
<tbody id="attendanceTableBody">
<!-- Attendance records will be added here -->
</tbody>
</table>
</div>
</div>
<script src="script.js"></script>
<script>
document.getElementById('studentForm').addEventListener('submit', function(event) {
event.preventDefault();
const studentId = document.getElementById('studentId').value;
const studentName = document.getElementById('studentName').value;
const date = new Date().toLocaleDateString();
const time = new Date().toLocaleTimeString();
addAttendanceRecord(studentId, studentName, date, time);
document.getElementById('studentId').value = '';
document.getElementById('studentName').value = '';
});
document.getElementById('teacherForm').addEventListener('submit', function(event) {
event.preventDefault();
const username = document.getElementById('teacherUsername').value;
const password = document.getElementById('teacherPassword').value;
if (authenticateTeacher(username, password)) {
document.getElementById('attendanceReport').style.display = 'block';
} else {
alert('Invalid username or password.');
}
});
function addAttendanceRecord(studentId, studentName, date, time) {
const tableBody = document.getElementById('attendanceTableBody');
const rowCount = tableBody.rows.length;
const row = tableBody.insertRow(rowCount);
const cell1 = row.insertCell(0);
const cell2 = row.insertCell(1);
const cell3 = row.insertCell(2);
const cell4 = row.insertCell(3);
const cell5 = row.insertCell(4);
cell1.innerHTML = rowCount + 1;
cell2.innerHTML = studentId;
cell3.innerHTML = studentName;
cell4.innerHTML = date;
cell5.innerHTML = time;
saveAttendanceData();
}
function authenticateTeacher(username, password) {
// Simple authentication logic (replace with actual authentication logic)
return username === 'admin' && password === 'password';
}
function saveAttendanceData() {
const tableBody = document.getElementById('attendanceTableBody');
const rows = Array.from(tableBody.rows);
const attendanceData = rows.map(row => {
return {
id: row.cells[1].innerText,
name: row.cells[2].innerText,
date: row.cells[3].innerText,
time: row.cells[4].innerText
};
});
localStorage.setItem('attendanceData', JSON.stringify(attendanceData));
}
function loadAttendanceData() {
const attendanceData = JSON.parse(localStorage.getItem('attendanceData')) || [];
const tableBody = document.getElementById('attendanceTableBody');
attendanceData.forEach((record, index) => {
const row = tableBody.insertRow(index);
const cell1 = row.insertCell(0);
const cell2 = row.insertCell(1);
const cell3 = row.insertCell(2);
const cell4 = row.insertCell(3);
const cell5 = row.insertCell(4);
cell1.innerHTML = index + 1;
cell2.innerHTML = record.id;
cell3.innerHTML = record.name;
cell4.innerHTML = record.date;
cell5.innerHTML = record.time;
});
}
// Load attendance data on page load
window.onload = loadAttendanceData;
</script>
</body>
</html>
|