-
Notifications
You must be signed in to change notification settings - Fork 0
/
attend2.html
133 lines (122 loc) · 5.92 KB
/
attend2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PSSCMUSM Management System</title>
<link rel="stylesheet" href="styles.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type="text/javascript">
function fetchLatestMessage() {
// Add a unique timestamp to the URL to prevent caching
var timestamp = new Date().getTime();
var url = 'latest_message.txt?t=' + timestamp;
$.ajax({
url: url,
success: function(data) {
// Check if the latest_message.txt content is empty
if (!data.trim()) {
console.log("Latest message is empty. Clearing student details.");
clearStudentDetails();
return;
}
console.log("Latest message (hexadecimal ID):", data);
// Fetch student details based on the hexadecimal ID
$.ajax({
url: 'get_attend2_details.php',
method: 'POST',
data: { id: data },
success: function(response) {
console.log("Student details response:", response);
try {
var student = JSON.parse(response);
if (student && student.full_name) {
document.getElementById("student-name").innerText = student.full_name;
document.getElementById("student-matric-id").innerText = student.matric_id;
document.getElementById("student-gender").innerText = student.gender.toUpperCase();
document.getElementById("student-school").innerText = student.school;
document.getElementById("student-picture").src = student.image;
} else {
console.log("No student details found or student object is invalid.");
alert("No student details found or student object is invalid.");
}
} catch (e) {
console.log("Error parsing student details:", e);
alert("Error parsing student details: " + e);
}
},
error: function(xhr, status, error) {
console.log("Error fetching student details. Status: " + status + ", Error: " + error);
alert("Error fetching student details. Status: " + status + ", Error: " + error);
}
});
},
error: function(xhr, status, error) {
console.log("Error fetching the latest message. Status: " + status + ", Error: " + error);
alert("Error fetching the latest message. Status: " + status + ", Error: " + error);
}
});
}
function clearStudentDetails() {
document.getElementById("student-name").innerText = "";
document.getElementById("student-matric-id").innerText = "";
document.getElementById("student-gender").innerText = "";
document.getElementById("student-school").innerText = "";
document.getElementById("student-picture").src = "images/default_picture.png";
}
$(document).ready(function() {
// Fetch the latest message every 2 seconds
setInterval(fetchLatestMessage, 2000);
});
document.addEventListener("DOMContentLoaded", function() {
// Select the end session button
const endSessionBtn = document.querySelector('.end-session-btn');
// Add click event listener to the end session button
endSessionBtn.addEventListener('click', function() {
// Show confirmation dialog
const confirmation = confirm("End Session will stop taking attendance for today's class. \nAre you sure want to stop taking attendance?");
// If user clicks OK (true), redirect to anr.html
if (confirmation) {
window.location.href = "anr.html";
}
});
});
</script>
</head>
<body>
<header>
<div class="logo">
<img src="images/logo.png" alt="Logo">
</div>
<h1>PSSCMUSM Management System</h1>
</header>
<div class="navigation-text">
<br><br><br><br><br>Attendance & Records > Set Up Class > Recording Attendance<br><br><br>
Please Scan Your PSSCMUSM Member Card
</div>
<div class="student-details">
<table class="student-details-table">
<tr>
<td rowspan="8" class="student-picture">
<img id="student-picture" src="images/default_picture.png" alt="Student Picture">
</td>
<td><strong>Name:</strong></td>
<td id="student-name"></td>
</tr>
<tr>
<td><strong>Matric ID:</strong></td>
<td id="student-matric-id"></td>
</tr>
<tr>
<td><strong>Gender:</strong></td>
<td id="student-gender"></td>
</tr>
<tr>
<td><strong>School:</strong></td>
<td id="student-school"></td>
</tr>
</table>
</div>
<button class="end-session-btn">End Session</button>
</body>
</html>