function genZip(selected, errordel) {console.log('zip gen')
var getWS=document.getElementById('wsAttach').checked ? "yes" : "no" ;
var schAttach=document.getElementById('schAttach').checked ? "attach" : "" ;
var wsattach=(getWS==="yes" ) ? selected : 'bypass' ;
document.getElementById('statusCount').innerHTML='Generating Zip
' ;
var xhr=new XMLHttpRequest();
xhr.open("POST", ROOT_URL + '/functions/generators/genZIP.php' , true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded' );
xhr.onreadystatechange=function () {
if (xhr.readyState===4 && xhr.status===200) {
var data=xhr.responseText.trim();
if (data !=="" ) {
var str=data.split('|');
document.getElementById('delivery').style.display='block' ;
var output={
source: 'output/reports/' ,
file: str[0],
type: 'zip'
};
var outputString=JSON.stringify(output);
document.getElementById('mailerContainer').innerHTML='' ;
var url=ROOT_URL + '/includes/master/deliveryMailer.php?zips=' + encodeURIComponent(outputString) + '&clientnumber=&tenant=' + TENANT_URL;
loadContentAndExecuteScripts(url, 'mailerContainer' );
}
document.getElementById('loading').style.display='none' ;
setTimeout(function() {
var el = document.getElementById('defectList');
if (!el) {
console.error('defectList not found.');
} else {
const hasContent = el.textContent.replace(/\u00A0/g, ' ').trim().length > 0;
if (hasContent) {
console.log('defectList has content. Proceeding.');
genHSEZip(selected, errordel);
} else {
console.log('defectList empty. Skipping.');
}
}
}, 300);
}
};
xhr.send('clientnumber=&items=' + encodeURIComponent(selected) + ' &ws=' + encodeURIComponent(wsattach) + ' &schMode=' + encodeURIComponent(schAttach) + ' &tenant=' + encodeURIComponent(TENANT_URL));
}
function genHSEZip(selected, errordel) {
if (errordel !== "") {document.getElementById('statusCount').innerHTML='Generating HSE Zip
' ;
var xhr=new XMLHttpRequest();
xhr.open("POST", ROOT_URL + '/functions/generators/genZIP.php' , true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded' );
xhr.onreadystatechange=function () {
if (xhr.readyState===4 && xhr.status===200) {
var data=xhr.responseText.trim();
if (data !=="" ) {
document.getElementById('defectList').value=data;
document.getElementById('defectTemp').textContent=data;
document.getElementById('hseNotice').innerHTML='