-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsafety-inspection.html
More file actions
671 lines (586 loc) · 26.6 KB
/
Copy pathsafety-inspection.html
File metadata and controls
671 lines (586 loc) · 26.6 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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ISO 45001 Safety Inspection | HSE Digital Toolkit</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
<style>
:root {
--bg: #f8fafc;
--card: #ffffff;
--text: #1e293b;
--muted: #64748b;
--primary: #0f766e;
--primary-dark: #115e59;
--blue: #2563eb;
--danger: #dc2626;
--warning: #f59e0b;
--success: #16a34a;
--border: #e2e8f0;
--radius: 12px;
--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}
* { box-sizing: border-box; font-family: 'Inter', sans-serif; }
body { margin: 0; background-color: var(--bg); color: var(--text); }
/* Topbar */
.topbar {
background: var(--primary-dark);
color: white;
padding: 15px 20px;
display: flex;
justify-content: space-between;
align-items: center;
position: sticky;
top: 0;
z-index: 100;
box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; font-size: 1.2rem; font-weight: 600; }
.nav-btn { color: white; text-decoration: none; padding: 8px 16px; background: rgba(255,255,255,0.1); border-radius: 6px; font-size: 14px; }
.container { max-width: 1100px; margin: 20px auto; padding: 0 15px; }
/* Print Container */
#printArea {
background: var(--card);
border-radius: var(--radius);
box-shadow: var(--shadow);
padding: 40px;
margin-bottom: 20px;
}
/* Report Header */
.report-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
border-bottom: 3px solid var(--primary);
padding-bottom: 20px;
margin-bottom: 30px;
}
.company-logo-box {
width: 150px;
height: 80px;
border: 2px dashed var(--border);
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
position: relative;
background: #f1f5f9;
border-radius: 8px;
}
.company-logo-box img { max-width: 100%; max-height: 100%; display: none; }
.company-logo-box input { position: absolute; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.report-title { text-align: right; }
.report-title h2 { margin: 0 0 5px; color: var(--primary-dark); font-size: 24px; }
.report-title p { margin: 0; color: var(--muted); font-size: 13px; font-weight: 500; }
.iso-badge { display: inline-block; background: #e0f2fe; color: #0284c7; padding: 4px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; margin-top: 5px;}
/* Form Grid */
.section-title { font-size: 16px; font-weight: 700; color: var(--primary); margin: 30px 0 15px; border-bottom: 1px solid var(--border); padding-bottom: 5px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: #475569; }
.required { color: var(--danger); margin-left: 3px; font-weight: bold; }
input, select, textarea {
width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; background: #f8fafc;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); background: white; }
/* 🔥 FIX: Observations Table - Mobile Scrolling Enforced 🔥 */
.table-container { overflow-x: auto; margin-top: 10px; width: 100%; }
table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
min-width: 1000px; /* Yeh table ko squish hone se bachayega aur scroll dega */
}
th, td {
border: 1px solid var(--border);
padding: 10px;
text-align: left;
vertical-align: top;
font-size: 13px;
word-wrap: break-word;
overflow-wrap: break-word;
}
th { background: #f1f5f9; color: var(--text); font-weight: 600; }
tr { page-break-inside: avoid; break-inside: avoid; }
.add-row-btn { background: #e2e8f0; border: none; padding: 8px 15px; border-radius: 6px; cursor: pointer; margin-top: 10px; font-size: 13px; font-weight: 600;}
/* Table Inline Photo Upload */
.upload-btn {
display: inline-block;
background: #e0f2fe;
color: #0284c7;
padding: 6px 10px;
border-radius: 6px;
font-size: 12px;
font-weight: 600;
cursor: pointer;
border: 1px solid #bae6fd;
text-align: center;
width: 100%;
}
.upload-btn:hover { background: #bae6fd; }
.upload-btn input { display: none; }
.row-gallery { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.row-gallery img { width: 50px; height: 50px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); cursor: pointer; }
/* Signatures */
.sig-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-top: 20px; page-break-inside: avoid; break-inside: avoid;}
.sig-box { border-top: 1px solid var(--text); padding-top: 10px; text-align: center; }
.sig-img-container { height: 60px; margin-bottom: 10px; position: relative; }
.sig-img-container img { max-height: 100%; display: none; margin: 0 auto; }
.sig-img-container input { position: absolute; top:0; left:0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
/* Dashboard Summary */
.summary-dash { background: #f8fafc; padding: 20px; border-radius: 8px; border: 1px solid var(--border); margin-top: 30px; page-break-inside: avoid; break-inside: avoid;}
.dash-metrics { display: flex; gap: 20px; margin-bottom: 15px; }
.metric { flex: 1; background: white; padding: 15px; border-radius: 8px; border: 1px solid var(--border); text-align: center; }
.metric h4 { margin: 0 0 5px; font-size: 12px; color: var(--muted); }
.metric p { margin: 0; font-size: 24px; font-weight: 700; color: var(--primary); }
#autoSummaryText { font-size: 13px; line-height: 1.6; white-space: pre-wrap; }
/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; justify-content: center; padding: 20px; background: white; border-radius: 12px; box-shadow: var(--shadow);}
.btn { padding: 12px 20px; border: none; border-radius: 6px; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 8px; font-size: 14px; transition: 0.2s;}
.btn:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-blue { background: var(--blue); color: white; }
.btn-green { background: var(--success); color: white; }
.btn-print { background: var(--text); color: white; }
.btn-pdf { background: var(--danger); color: white; }
.btn-clear { background: #f1f5f9; color: var(--danger); border: 1px solid #cbd5e1; }
/* ==========================================
🔥 BULLETPROOF PDF/PRINT STYLES 🔥
========================================== */
@page { size: landscape; margin: 10mm; }
body.is-printing #mainTopbar,
body.is-printing #actionToolbar,
body.is-printing #addRowBtn,
body.is-printing .upload-btn,
body.is-printing #logoText,
body.is-printing span[id^="sigText"] {
display: none !important;
}
body.is-printing { background: white !important; }
body.is-printing #printArea {
padding: 0 !important;
box-shadow: none !important;
border: none !important;
}
body.is-printing input,
body.is-printing select,
body.is-printing textarea {
border: none !important;
background: transparent !important;
color: black !important;
padding: 0 !important;
margin: 0 !important;
box-shadow: none !important;
appearance: none !important;
-webkit-appearance: none !important;
resize: none !important;
overflow: hidden !important;
white-space: pre-wrap !important;
word-wrap: break-word !important;
}
body.is-printing select::-ms-expand { display: none; }
body.is-printing .company-logo-box { border: none !important; background: transparent !important; }
/* 🔥 PDF ke waqt wapas A4 size fit karo */
body.is-printing .table-container { overflow-x: visible !important; width: 100% !important; }
body.is-printing table {
table-layout: fixed !important;
width: 100% !important;
min-width: 100% !important;
max-width: 100% !important;
}
body.is-printing .container { max-width: 100% !important; margin: 0 !important; padding: 0 !important; }
body.is-printing .row-gallery img { width: 65px !important; height: 65px !important; margin: 2px;}
@media (max-width: 768px) {
.grid-2, .sig-grid { grid-template-columns: 1fr; }
.report-header { flex-direction: column; align-items: center; text-align: center; gap: 15px; }
.dash-metrics { flex-direction: column; }
}
</style>
</head>
<body>
<header class="topbar" id="mainTopbar">
<div class="brand">
<i class="fa-solid fa-clipboard-check"></i>
<h1>HSE Toolkit</h1>
</div>
<a href="index.html" class="nav-btn"><i class="fa-solid fa-house"></i> Home</a>
</header>
<div class="container" id="mainContainer">
<div id="printArea">
<div class="report-header">
<div class="company-logo-box" id="logoBox">
<span id="logoText"><i class="fa-solid fa-upload"></i> Upload Logo</span>
<img id="logoImg" alt="Company Logo">
<input type="file" accept="image/*" onchange="previewImage(event, 'logoImg', 'logoText')">
</div>
<div class="report-title">
<h2>Safety Inspection Report</h2>
<p>Site Walkdown & Hazard Identification Record</p>
<div class="iso-badge">Aligned with ISO 45001 & OSHA 29 CFR 1926</div>
</div>
</div>
<h3 class="section-title">1. Site & Audit Details</h3>
<div class="grid-2">
<div>
<label>Project / Company Name<span class="required">*</span></label>
<input type="text" id="projectName" placeholder="Enter details" required>
</div>
<div>
<label>Specific Area Inspected<span class="required">*</span></label>
<input type="text" id="areaName" placeholder="e.g. Block A, Workshop" required>
</div>
<div>
<label>Lead Inspector<span class="required">*</span></label>
<input type="text" id="inspectorName" placeholder="Name & Job Title" required>
</div>
<div>
<label>Date & Time<span class="required">*</span></label>
<div style="display: flex; gap: 10px;">
<input type="date" id="insDate" required>
<input type="time" id="insTime" required>
</div>
</div>
</div>
<h3 class="section-title">2. Findings & Corrective Actions</h3>
<div class="table-container">
<table id="obsTable">
<thead>
<tr>
<th style="width: 5%;">#</th>
<th style="width: 15%;">Category</th>
<th style="width: 25%;">Observation Details</th>
<th style="width: 10%;">Risk</th>
<th style="width: 20%;">Corrective Action</th>
<th style="width: 15%;">Evidence 📷</th>
<th style="width: 10%;">Status</th>
</tr>
</thead>
<tbody id="obsBody">
</tbody>
</table>
</div>
<button class="add-row-btn" id="addRowBtn" onclick="addObsRow()">+ Add Observation Row</button>
<div class="summary-dash" id="summarySection">
<h3 class="section-title" style="margin-top: 0; border-none;">3. Inspection Summary</h3>
<div class="dash-metrics">
<div class="metric">
<h4>Total Findings</h4>
<p id="sumTotal">0</p>
</div>
<div class="metric">
<h4>High Risk Items</h4>
<p id="sumHigh" style="color: var(--danger);">0</p>
</div>
<div class="metric">
<h4>Open Actions</h4>
<p id="sumOpen" style="color: var(--warning);">0</p>
</div>
</div>
<div id="autoSummaryText">Click "Generate Summary" below to analyze the findings.</div>
</div>
<h3 class="section-title">4. Signatures & Approvals</h3>
<div class="sig-grid">
<div class="sig-col">
<div class="sig-img-container">
<span id="sigText1" style="font-size: 12px; color: var(--muted);"><i class="fa-solid fa-pen"></i> Upload Signature</span>
<img id="sigImg1">
<input type="file" accept="image/*" onchange="previewImage(event, 'sigImg1', 'sigText1')">
</div>
<div class="sig-box">
<label>Inspector Signature</label>
<input type="text" id="sigName1" placeholder="Type Name">
<input type="date" id="sigDate1" style="margin-top: 5px;">
</div>
</div>
<div class="sig-col">
<div class="sig-img-container">
<span id="sigText2" style="font-size: 12px; color: var(--muted);"><i class="fa-solid fa-pen"></i> Upload Signature</span>
<img id="sigImg2">
<input type="file" accept="image/*" onchange="previewImage(event, 'sigImg2', 'sigText2')">
</div>
<div class="sig-box">
<label>Site Manager Approval</label>
<input type="text" id="sigName2" placeholder="Type Name">
<input type="date" id="sigDate2" style="margin-top: 5px;">
</div>
</div>
</div>
</div> <div class="toolbar" id="actionToolbar">
<button class="btn btn-blue" onclick="processReportAction('summary')"><i class="fa-solid fa-bolt"></i> Generate Summary</button>
<button class="btn btn-green" onclick="saveData()"><i class="fa-solid fa-floppy-disk"></i> Save Data</button>
<button class="btn btn-blue" style="background: var(--primary-dark);" onclick="loadData()"><i class="fa-solid fa-rotate"></i> Load</button>
<button class="btn btn-print" onclick="processReportAction('print')"><i class="fa-solid fa-print"></i> Native Print</button>
<button class="btn btn-pdf" onclick="processReportAction('pdf')"><i class="fa-solid fa-file-pdf"></i> Download PDF</button>
<button class="btn btn-clear" onclick="clearForm()"><i class="fa-solid fa-trash"></i> Clear</button>
</div>
</div>
<script>
const STORAGE_KEY = "hseInspectionIsoV6";
const categories = [
"Housekeeping", "PPE Compliance", "Working at Height", "Scaffolding",
"Electrical Safety", "Fire Safety", "Lifting Operations", "Tools/Equipment",
"Chemical/COSHH", "Excavation", "Positive Finding", "Other"
];
function setInitialDates() {
const today = new Date().toISOString().split('T')[0];
document.getElementById('insDate').value = today;
document.getElementById('sigDate1').value = today;
document.getElementById('sigDate2').value = today;
}
function previewImage(event, imgId, textId) {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
const img = document.getElementById(imgId);
img.src = e.target.result;
img.style.display = 'block';
if(document.getElementById(textId)) {
document.getElementById(textId).style.display = 'none';
}
}
reader.readAsDataURL(file);
}
}
function handleRowImages(inputElement) {
const gallery = inputElement.closest('td').querySelector('.row-gallery');
const files = Array.from(inputElement.files);
files.forEach(file => {
const reader = new FileReader();
reader.onload = e => {
const img = document.createElement('img');
img.src = e.target.result;
img.title = "Click to remove";
img.onclick = function() { this.remove(); };
gallery.appendChild(img);
};
reader.readAsDataURL(file);
});
inputElement.value = "";
}
function addObsRow(data = {}) {
const tbody = document.getElementById('obsBody');
const rowCount = tbody.rows.length + 1;
const tr = document.createElement('tr');
let catOptions = '<option value="">Select...</option>';
categories.forEach(cat => {
catOptions += `<option value="${cat}" ${data.cat === cat ? 'selected' : ''}>${cat}</option>`;
});
tr.innerHTML = `
<td class="row-num">${rowCount}</td>
<td><select class="obs-cat">${catOptions}</select></td>
<td><textarea class="obs-desc" placeholder="Describe finding..." oninput="autoResize(this)">${data.desc || ''}</textarea></td>
<td>
<select class="obs-risk">
<option value="Low" ${data.risk === 'Low' ? 'selected' : ''}>Low</option>
<option value="Medium" ${data.risk === 'Medium' ? 'selected' : ''}>Medium</option>
<option value="High" ${data.risk === 'High' ? 'selected' : ''}>High</option>
<option value="N/A" ${data.risk === 'N/A' ? 'selected' : ''}>N/A</option>
</select>
</td>
<td><textarea class="obs-action" placeholder="Action required..." oninput="autoResize(this)">${data.action || ''}</textarea></td>
<td>
<label class="upload-btn">
<i class="fa-solid fa-plus"></i> Add Photo
<input type="file" accept="image/*" multiple onchange="handleRowImages(this)">
</label>
<div class="row-gallery"></div>
</td>
<td>
<select class="obs-status">
<option value="Open" ${data.status === 'Open' ? 'selected' : ''}>Open</option>
<option value="Closed" ${data.status === 'Closed' ? 'selected' : ''}>Closed</option>
</select>
</td>
`;
tbody.appendChild(tr);
if(data.images && data.images.length > 0) {
const gallery = tr.querySelector('.row-gallery');
data.images.forEach(src => {
const img = document.createElement('img');
img.src = src;
img.title = "Click to remove";
img.onclick = function() { this.remove(); };
gallery.appendChild(img);
});
}
setTimeout(() => {
autoResize(tr.querySelector('.obs-desc'));
autoResize(tr.querySelector('.obs-action'));
}, 50);
}
function autoResize(textarea) {
textarea.style.height = 'auto';
textarea.style.height = textarea.scrollHeight + 'px';
}
function validateForm() {
const requiredFields = ['projectName', 'areaName', 'inspectorName', 'insDate', 'insTime'];
for (let id of requiredFields) {
const field = document.getElementById(id);
if (!field.value.trim()) {
alert(`Please fill the required field: ${field.previousElementSibling.textContent.replace('*', '').trim()}`);
field.focus();
return false;
}
}
return true;
}
function prepareForOutput() {
document.body.classList.add('is-printing');
document.querySelectorAll('textarea').forEach(ta => autoResize(ta));
const rows = document.getElementById('obsBody').rows;
for(let i=0; i<rows.length; i++) {
const desc = rows[i].querySelector('.obs-desc').value.trim();
if(desc === "") rows[i].style.display = 'none';
}
}
function restoreAfterOutput() {
document.body.classList.remove('is-printing');
const rows = document.getElementById('obsBody').rows;
for(let i=0; i<rows.length; i++) rows[i].style.display = '';
}
window.addEventListener('beforeprint', prepareForOutput);
window.addEventListener('afterprint', restoreAfterOutput);
function generateSummary() {
const rows = document.getElementById('obsBody').rows;
let total = 0, high = 0, open = 0;
for(let i=0; i<rows.length; i++) {
const desc = rows[i].querySelector('.obs-desc').value;
const risk = rows[i].querySelector('.obs-risk').value;
const status = rows[i].querySelector('.obs-status').value;
if(desc.trim() !== "") {
total++;
if(risk === "High") high++;
if(status === "Open") open++;
}
}
document.getElementById('sumTotal').innerText = total;
document.getElementById('sumHigh').innerText = high;
document.getElementById('sumOpen').innerText = open;
const project = document.getElementById('projectName').value || "the site";
let summaryStr = `An inspection was conducted at ${project}. A total of ${total} findings were recorded. `;
if (high > 0) summaryStr += `CRITICAL: There are ${high} High Risk items requiring immediate management attention. `;
summaryStr += `Currently, ${open} actions remain open and must be tracked to closure as per ISO 45001 standards.`;
document.getElementById('autoSummaryText').innerText = summaryStr;
}
function processReportAction(actionType) {
if (!validateForm()) return;
generateSummary();
if (actionType === 'summary') {
alert("Summary generated successfully!");
}
else if (actionType === 'print') {
window.print();
}
else if (actionType === 'pdf') {
prepareForOutput();
const element = document.getElementById('printArea');
const originalWidth = element.style.width;
element.style.width = '280mm';
element.style.maxWidth = '280mm';
const opt = {
margin: [5, 5, 5, 5],
filename: 'ISO_Safety_Inspection_Report.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2, useCORS: true },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'landscape' },
pagebreak: { mode: ['css', 'legacy'] }
};
html2pdf().set(opt).from(element).save().then(() => {
element.style.width = originalWidth;
element.style.maxWidth = originalWidth;
restoreAfterOutput();
});
}
}
function saveData() {
const data = {
projectName: document.getElementById('projectName').value,
areaName: document.getElementById('areaName').value,
inspectorName: document.getElementById('inspectorName').value,
insDate: document.getElementById('insDate').value,
insTime: document.getElementById('insTime').value,
sigName1: document.getElementById('sigName1').value,
sigDate1: document.getElementById('sigDate1').value,
sigName2: document.getElementById('sigName2').value,
sigDate2: document.getElementById('sigDate2').value,
logoImg: document.getElementById('logoImg').src,
sigImg1: document.getElementById('sigImg1').src,
sigImg2: document.getElementById('sigImg2').src,
rows: []
};
const tableRows = document.getElementById('obsBody').rows;
for(let i=0; i<tableRows.length; i++) {
const imgs = tableRows[i].querySelector('.row-gallery').querySelectorAll('img');
const imgArray = Array.from(imgs).map(img => img.src);
data.rows.push({
cat: tableRows[i].querySelector('.obs-cat').value,
desc: tableRows[i].querySelector('.obs-desc').value,
risk: tableRows[i].querySelector('.obs-risk').value,
action: tableRows[i].querySelector('.obs-action').value,
status: tableRows[i].querySelector('.obs-status').value,
images: imgArray
});
}
localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
alert("Report Data & Photos Saved Locally!");
}
function loadData() {
const raw = localStorage.getItem(STORAGE_KEY);
if(!raw) { alert("No saved data found!"); return; }
const data = JSON.parse(raw);
document.getElementById('projectName').value = data.projectName || '';
document.getElementById('areaName').value = data.areaName || '';
document.getElementById('inspectorName').value = data.inspectorName || '';
document.getElementById('insDate').value = data.insDate || '';
document.getElementById('insTime').value = data.insTime || '';
document.getElementById('sigName1').value = data.sigName1 || '';
document.getElementById('sigDate1').value = data.sigDate1 || '';
document.getElementById('sigName2').value = data.sigName2 || '';
document.getElementById('sigDate2').value = data.sigDate2 || '';
const loadImg = (id, textId, src) => {
if(src && src.startsWith('data:image')) {
document.getElementById(id).src = src;
document.getElementById(id).style.display = 'block';
if(document.getElementById(textId)) document.getElementById(textId).style.display = 'none';
}
};
loadImg('logoImg', 'logoText', data.logoImg);
loadImg('sigImg1', 'sigText1', data.sigImg1);
loadImg('sigImg2', 'sigText2', data.sigImg2);
document.getElementById('obsBody').innerHTML = '';
if(data.rows && data.rows.length > 0) {
data.rows.forEach(r => addObsRow(r));
} else {
addObsRow(); addObsRow(); addObsRow();
}
generateSummary();
alert("Data Loaded Successfully!");
}
function clearForm() {
if(!confirm("Are you sure you want to clear all data and photos?")) return;
document.querySelectorAll('input[type="text"], input[type="time"], textarea').forEach(el => { el.value = ''; el.style.height = 'auto'; });
document.querySelectorAll('select').forEach(el => el.selectedIndex = 0);
const imgs = document.querySelectorAll('.sig-img-container img, .company-logo-box img');
imgs.forEach(img => { img.src = ''; img.style.display = 'none'; });
document.querySelectorAll('span').forEach(span => span.style.display = 'inline-block');
document.getElementById('obsBody').innerHTML = '';
addObsRow(); addObsRow(); addObsRow();
setInitialDates();
document.getElementById('sumTotal').innerText = '0';
document.getElementById('sumHigh').innerText = '0';
document.getElementById('sumOpen').innerText = '0';
document.getElementById('autoSummaryText').innerText = 'Click "Generate Summary" below to analyze the findings.';
localStorage.removeItem(STORAGE_KEY);
}
window.onload = function() {
setInitialDates();
addObsRow(); addObsRow(); addObsRow();
};
</script>
</body>
</html>