-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
286 lines (273 loc) · 10.5 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Attendance Form</title>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
background-color: #f0f2f5;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
text-align: center;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
max-width: 1200px; /* Adjusted max-width */
}
.logo {
margin-bottom: 20px;
}
.logo img {
width: 200px; /* Increased logo size */
height: auto;
}
.heading {
margin-bottom: 20px;
font-size: 24px;
font-weight: bold;
color: #333;
}
.form-container {
display: flex;
flex-direction: row;
width: 100%;
max-width: 1000px;
background-color: white;
padding: 30px;
border-radius: 12px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
box-sizing: border-box; /* Ensure padding and borders are included in total width */
}
.form-fields {
flex: 1;
margin-right: 20px;
}
.camera-container {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
border: 2px dashed #0087f7;
border-radius: 8px;
background-color: #f9f9f9;
height: 300px; /* Fixed height */
width: 300px;
position: relative;
cursor: pointer;
margin-left: auto;
margin-right: auto;
}
.camera-box {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
}
.camera-box i {
font-size: 48px;
color: rgba(0, 0, 0, 0.2);
display: block;
}
.camera-box video {
display: none;
width: 100%;
height: 100%;
object-fit: cover;
}
.camera-box.active video {
display: block;
}
.camera-box.active button {
display: block;
}
.camera-box button {
display: none;
margin-top: 10px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 8px;
font-weight: bold;
color: #555;
}
.form-group input[type="text"] {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 14px;
color: #333;
}
.form-group button {
width: 100%;
padding: 12px;
background-color: #28a745;
border: none;
border-radius: 6px;
color: white;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}
.form-group button:hover {
background-color: #218838;
}
#fileInfo {
text-align: center;
margin-top: 20px;
font-size: 14px;
color: #28a745;
font-weight: bold;
}
#errorMessage {
text-align: center;
margin-top: 20px;
font-size: 14px;
color: #dc3545;
font-weight: bold;
}
.form-header {
margin-bottom: 10px;
font-size: 18px;
color: #333;
font-weight: bold;
}
.blue{
color: #0087f7;
}
#imageUpload{
visibility: hidden;
}
</style>
<!-- Font Awesome CDN for Camera Icon -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
</head>
<body>
<div class="container">
<div class="logo">
<img src="./public/kiit-logo.png" alt="KIIT Logo" />
</div>
<div class="heading">Attendance Form</div>
<div class="form-container">
<div class="form-fields">
<div class="form-header" id="formHeader">Form filled by: [Name]</div>
<form id="imageScannerForm" action="" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="email">Email</label>
<input type="text" id="email" name="email" required />
</div>
<div class="form-group">
<label for="rollNumber">Roll No</label>
<input type="text" id="rollNumber" name="rollNumber" required />
</div>
<input type="file" id="imageUpload" name="image" accept="image/*">
<div class="form-group centered">
<label for="image">Capture Image</label>
<div class="camera-container" onclick="toggleCamera()">
<div class="camera-box">
<i class="fas fa-camera"></i>
<video id="cameraStream" autoplay></video>
<button type="button" onclick="captureImage()">Capture Image</button>
</div>
</div>
<div id="fileInfo"></div>
</div>
<div class="form-group">
<button type="submit">Submit</button>
</div>
<div id="errorMessage"></div>
</form>
</div>
<!-- Add space between left and right sections if needed -->
</div>
</div>
<script>
"use strict";
let stream;
const cameraContainer = document.querySelector(".camera-container");
const cameraBox = document.querySelector(".camera-box");
const cameraIcon = document.querySelector(".fa-camera");
const cameraStream = document.getElementById("cameraStream");
function toggleCamera() {
if (cameraBox.classList.contains("active")) {
stopCamera();
cameraBox.classList.remove("active");
cameraIcon.style.display="block";
cameraContainer.style.border = "2px dashed #0087f7";
} else {
cameraBox.classList.add("active");
cameraIcon.style.display="none";
cameraContainer.style.border = "none";
startCamera();
}
}
async function startCamera() {
try {
stream = await navigator.mediaDevices.getUserMedia({video: true});
cameraStream.srcObject = stream;
} catch (error) {
console.error("Error accessing camera:", error);
}
}
function stopCamera() {
if (stream) {
stream.getTracks().forEach((track) => track.stop());
cameraStream.srcObject = null;
}
}
function captureImage() {
const canvas = document.createElement("canvas");
canvas.width = cameraStream.videoWidth;
canvas.height = cameraStream.videoHeight;
const ctx = canvas.getContext("2d");
ctx.drawImage(cameraStream, 0, 0, canvas.width, canvas.height);
canvas.toBlob((blob) => {
const file = new File([blob], "captured-image.png", {type: "image/png"});
const dataTransfer = new DataTransfer();
dataTransfer.items.add(file);
document.getElementById("imageUpload").files = dataTransfer.files;
const fileInfo = document.getElementById("fileInfo");
fileInfo.innerHTML = `Captured image uploaded successfully!`;
});
}
document.getElementById("imageScannerForm").addEventListener("submit", function (e) {
e.preventDefault();
const form = new FormData(this);
const errorMessage = document.getElementById("errorMessage");
fetch("http://localhost:3000/mark-attendance", {
method: "POST",
body: form,
headers: {
"auth": "true"
}
})
.then(async (response) => {
console.log(response.status)
if(response.status=== 404){
errorMessage.innerHTML = '<span>User not Found! Please <a href="/user/register" class="blue">Register</a> the User.</span>';
return;
}
const data = await response.json();
errorMessage.innerHTML = data.message;
})
.catch((error) => {
console.error("Error:", error);
errorMessage.innerHTML = "An error occurred while submitting the form!";
});
});
</script>
</body>
</html>