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 defectListElement = document.getElementById('defectList');
if (defectListElement) {
console.log("defectList found, calling genHSEZip");
genHSEZip(selected, errordel); // Call genHSEZip after delay
} else {
console.error("defectList not found.");
}
}, 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='
You have URGENT in your reporting data. Notify HSE
' ;
//document.getElementById('notifyHeader').classList.remove('card-header');
//document.getElementById('notifyHeader').classList.add('danger-color-dark' );
pulseElementBackgroundClass('notifyHeader', 'bg_secondary', 'danger-color-dark', 900);
}
}
};
xhr.send('mode=hse&clientnumber=&items=' + encodeURIComponent(errordel) + ' &tenant=' + encodeURIComponent(TENANT_URL));
} else {
document.getElementById(' hseNotice').innerHTML='' ;
}
}
function genZips(hse) {
console.log('loaded zip');
var selected=document.getElementById('itemList').textContent;
var schAttach=document.getElementById('schAttach').checked ? "attach" : "" ;
var getWS=document.getElementById('wsAttach').checked ? "yes" : "no" ;
var wsattach=(getWS==="yes" ) ? selected : 'bypass' ;
document.getElementById('statusCount').innerHTML='Generating Zip
' ;
var ml=document.getElementById('multiList').textContent;
var xhrShed=new XMLHttpRequest();
xhrShed.open("POST", 'functions/genShed.php' , true);
xhrShed.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded' );
xhrShed.send('clientnumber=');
var xhrZip=new XMLHttpRequest();
xhrZip.open("POST", ROOT_URL + '/functions/generators/genZIP.php' , true);
xhrZip.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded' );
xhrZip.onreadystatechange=function () {
if (xhrZip.readyState===4 && xhrZip.status===200) {
var data=xhrZip.responseText.trim();
if (data !=="" ) {
console.log('zip created');
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);
console.log('outputString created');
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' ;
document.getElementById('delivery').style.display='block' ;
console.log('zip done');
}
};
xhrZip.send('clientnumber=&items=' + encodeURIComponent(ml) + ' &ws=' + encodeURIComponent(wsattach) + ' &schMode=' + encodeURIComponent(schAttach) + ' &tenant=' + encodeURIComponent(TENANT_URL));
if (hse !== '') {
setTimeout(function() {
var defectListElement = document.getElementById('defectList');
if (defectListElement) {
console.log("defectList found, calling genHSEZip");
genHSEZip(selected, errordel); // Call genHSEZip after delay
} else {
console.error("defectList not found.");
}
}, 300);
}
}