`;
document.getElementById('access-control-checklist').innerHTML = checklists.accessControl.map(createChecklistItemHTML).join('');
document.getElementById('data-protection-checklist').innerHTML = checklists.dataProtection.map(createChecklistItemHTML).join('');
document.getElementById('incident-response-checklist').innerHTML = checklists.incidentResponse.map(createChecklistItemHTML).join('');
}
/**
* Displays the specified tab and updates UI elements.
*/
window.showTab = function(n) {
tabs.forEach((tab, index) => {
tab.style.display = (index === n) ? 'block' : 'none';
tab.classList.toggle('active', index === n);
});
tabLinks.forEach((link, index) => {
link.classList.toggle('active', index === n);
});
prevBtn.disabled = (n === 0);
nextBtn.textContent = (n === tabs.length - 1) ? 'Finish' : 'Next';
nextBtn.disabled = (n === tabs.length - 1);
if (n === tabs.length - 1) {
generateReport();
downloadPdfBtn.disabled = false;
} else {
downloadPdfBtn.disabled = true;
}
}
/**
* Navigates between tabs.
*/
window.navigateTabs = function(n) {
if (currentTab + n >= tabs.length || currentTab + n < 0) return;
currentTab += n;
showTab(currentTab);
}
/**
* Gathers data and generates the compliance report preview.
*/
function generateReport() {
const orgName = document.getElementById('orgName').value || 'N/A';
const reviewDateValue = document.getElementById('reviewDate').value;
const reviewDate = reviewDateValue ? new Date(reviewDateValue + 'T00:00:00').toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }) : 'N/A';
let reportHTML = `
`;
return sectionHTML;
};
reportHTML += generateSection('Access Control', 'access-control-checklist');
reportHTML += generateSection('Data Protection', 'data-protection-checklist');
reportHTML += generateSection('Incident Response', 'incident-response-checklist');
document.getElementById('reportPreview').innerHTML = reportHTML;
document.getElementById('pdf-content-wrapper').innerHTML = reportHTML;
}
/**
* Downloads the generated report as a PDF file.
*/
async function downloadPDF() {
const { jsPDF } = window.jspdf;
const pdfContent = document.getElementById('pdf-render-area');
if (!pdfContent) return;
downloadPdfBtn.textContent = 'Generating...';
downloadPdfBtn.disabled = true;
pdfContent.classList.remove('hidden');
try {
const canvas = await html2canvas(pdfContent, { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'portrait', unit: 'in', format: 'letter' });
const imgProps = pdf.getImageProperties(imgData);
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save('Cybersecurity_Compliance_Report.pdf');
} catch (error) {
console.error('Error generating PDF:', error);
} finally {
pdfContent.classList.add('hidden');
downloadPdfBtn.textContent = 'Download Report as PDF';
downloadPdfBtn.disabled = false;
}
}
// --- EVENT LISTENERS ---
downloadPdfBtn.addEventListener('click', downloadPDF);
// --- INITIALIZATION ---
populateChecklists();
showTab(currentTab);
});
Cybersecurity Compliance Report
Organization: ${orgName} | Review Date: ${reviewDate}
`; const generateSection = (title, checklistId) => { let sectionHTML = `${title}
| Control Item | Status | Notes |
|---|---|---|
| ${question} | ${status} | ${notes} |
