-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
74 lines (65 loc) · 2.58 KB
/
Copy pathapp.js
File metadata and controls
74 lines (65 loc) · 2.58 KB
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
const express = require('express');
const multer = require('multer');
const path = require('path');
const app = express();
// Temporary storage (List of all submissions)
let reports = [];
// Setup image uploads
const upload = multer({ dest: 'uploads/' });
app.use(express.static('public'));
app.use('/uploads', express.static('uploads')); // This lets the Admin see the photos
app.use(express.urlencoded({ extended: true }));
// 1. EMPLOYEE PAGE
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'views/index.html'));
});
// 2. RECEIVING DATA
app.post('/submit-report', upload.single('workImage'), (req, res) => {
const reportData = {
name: req.body.empName,
lat: req.body.latitude,
lng: req.body.longitude,
time: new Date().toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' }), // Indian Timing
image: req.file ? req.file.filename : null
};
reports.push(reportData);
res.send('<h1>Report Submitted!</h1><a href="/">Back</a>');
});
// 3. ADMIN ACCESS PAGE (The "Control Room")
app.get('/admin', (req, res) => {
let rows = reports.map(r => `
<tr>
<td><b>${r.name}</b></td>
<td>${r.time}</td>
<td><a href="https://www.google.com/maps?q=${r.lat},${r.lng}" target="_blank">View on Map</a></td>
<td><img src="/uploads/${r.image}" width="120" style="border-radius:5px;"></td>
</tr>
`).join('');
res.send(`
<html>
<head>
<title>SCA Admin Panel</title>
<style>
body { font-family: sans-serif; padding: 40px; background: #f0f2f5; }
table { width: 100%; border-collapse: collapse; background: white; border-radius: 8px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
th, td { padding: 15px; border: 1px solid #ddd; text-align: left; }
th { background-color: #004a99; color: white; }
h1 { color: #004a99; }
</style>
</head>
<body>
<h1>Sadguru Controls - Employee Monitoring Dashboard</h1>
<p>Total Submissions: ${reports.length}</p>
<table>
<tr><th>Employee</th><th>Date & Time</th><th>Location</th><th>Work Proof</th></tr>
${rows}
</table>
</body>
</html>
`);
});
// This tells the app to use the server's port OR 3000 if running locally
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});