function openStampList() { if (auth_user == 1) { document.getElementById("stamp_list").style.display = 'block'; document.getElementById("open_stamp_list").click(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#stamp_list_content").innerHTML = this.responseText; $(document).ready( function () { new DataTable('#stamp_list_table', { paging: false, scrollCollapse: true, scrollY: '70vh', order: [[2, 'desc']], dom: 'Bftip', buttons: [ 'print', 'excel', 'pdf' ] }); } ); } }; xmlhttp.open("GET", "php/stamp/stamp_list_content.php"); xmlhttp.send(); } else { openLoginSection(); } } function openNewStamp() { if (auth_user == 1) { document.getElementById("new_stamp").style.display = 'block'; document.getElementById("open_new_stamp").click(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#new_stamp_content").innerHTML = this.responseText; } }; xmlhttp.open("GET", "php/stamp/new_stamp.php"); xmlhttp.send(); } else { openLoginSection(); } } function sendStamp() { document.querySelector('#send_stamp_button').style.display = 'none'; if(document.getElementById('stamp_day').checked == true) { var stamp_type1 = document.querySelector('#stamp_type_1').value; var stamp_date1 = document.querySelector('#stamp_date_1').value; var stamp_time1 = document.querySelector('#stamp_time_1').value; var stamp_note1 = document.querySelector('#stamp_note_1').value; var in_transfer1 = document.querySelector('#in_transfer_1').checked; var stamp_type2 = document.querySelector('#stamp_type_2').value; var stamp_date2 = document.querySelector('#stamp_date_2').value; var stamp_time2 = document.querySelector('#stamp_time_2').value; var stamp_note2 = document.querySelector('#stamp_note_2').value; var in_transfer2 = document.querySelector('#in_transfer_2').checked; var stamp_type3 = document.querySelector('#stamp_type_3').value; var stamp_date3 = document.querySelector('#stamp_date_3').value; var stamp_time3 = document.querySelector('#stamp_time_3').value; var stamp_note3 = document.querySelector('#stamp_note_3').value; var in_transfer3 = document.querySelector('#in_transfer_3').checked; var stamp_type4 = document.querySelector('#stamp_type_4').value; var stamp_date4 = document.querySelector('#stamp_date_4').value; var stamp_time4 = document.querySelector('#stamp_time_4').value; var stamp_note4 = document.querySelector('#stamp_note_4').value; var in_transfer4 = document.querySelector('#in_transfer_4').checked; var insert = 0; if(stamp_type1 != "" && stamp_date1 != "" && stamp_time1 != "") { insert++; $.ajax({ type: "POST", url: "php/stamp/send_new_stamp.php", data: { stamp_type: stamp_type1, stamp_date: stamp_date1, stamp_time: stamp_time1, stamp_note: stamp_note1, in_transfer : in_transfer1 }, success: function (res) { if (res === 'error') { Swal.fire({ type: 'error', text: 'Errore: ' + res }); } } }); } if(stamp_type2 != "" && stamp_date2 != "" && stamp_time2 != "") { insert++; $.ajax({ type: "POST", url: "php/stamp/send_new_stamp.php", data: { stamp_type: stamp_type2, stamp_date: stamp_date2, stamp_time: stamp_time2, stamp_note: stamp_note2, in_transfer : in_transfer2 }, success: function (res) { if (res === 'error') { Swal.fire({ type: 'error', text: 'Errore: ' + res }); } } }); } if(stamp_type3 != "" && stamp_date3 != "" && stamp_time3 != "") { insert++; $.ajax({ type: "POST", url: "php/stamp/send_new_stamp.php", data: { stamp_type: stamp_type3, stamp_date: stamp_date3, stamp_time: stamp_time3, stamp_note: stamp_note3, in_transfer : in_transfer3 }, success: function (res) { if (res === 'error') { Swal.fire({ type: 'error', text: 'Errore: ' + res }); } } }); } if(stamp_type4 != "" && stamp_date4 != "" && stamp_time4 != "") { insert++; $.ajax({ type: "POST", url: "php/stamp/send_new_stamp.php", data: { stamp_type: stamp_type4, stamp_date: stamp_date4, stamp_time: stamp_time4, stamp_note: stamp_note4, in_transfer : in_transfer4 }, success: function (res) { if (res === 'error') { Swal.fire({ type: 'error', text: 'Errore: ' + res }); } else { Swal.fire({ type: 'success', title: 'Timbratura inserita con successo!', showConfirmButton: false, timer: 2000 }); } } }); } if(insert == 0) { Swal.fire({ type: 'error', text: 'Nessuna timbratura eseguita' }); } document.querySelector('#close_new_stamp').click(); openStampList(); } else { var stamp_type = document.querySelector('#stamp_type').value; var stamp_date = document.querySelector('#stamp_date').value; var stamp_time = document.querySelector('#stamp_time').value; var stamp_note = document.querySelector('#stamp_note').value; var in_transfer = document.querySelector('#in_transfer').checked; if (stamp_type == "") { Swal.fire({ type: 'error', text: 'Tipo deve essere valorizzato' }); exit; } if (stamp_date == "") { Swal.fire({ type: 'error', text: 'Data deve essere valorizzata' }); exit; } if (stamp_time == "") { Swal.fire({ type: 'error', text: 'Ora deve essere valorizzata' }); exit; } $.ajax({ type: "POST", url: "php/stamp/send_new_stamp.php", data: { stamp_type: stamp_type, stamp_date: stamp_date, stamp_time: stamp_time, stamp_note: stamp_note, in_transfer : in_transfer }, success: function (res) { if (res === 'error') { Swal.fire({ type: 'error', text: 'Errore: ' + res }); } else { Swal.fire({ type: 'success', title: 'Timbratura inserita con successo!', showConfirmButton: false, timer: 2000 }); document.querySelector('#close_new_stamp').click(); openStampList(); } } }); } } function dayClick() { if(document.getElementById('stamp_day').checked == true) { document.getElementById('no_day').style.display = 'none'; document.getElementById('day_1').style.display = 'block'; document.getElementById('day_2').style.display = 'block'; document.getElementById('day_3').style.display = 'block'; document.getElementById('day_4').style.display = 'block'; } else { document.getElementById('no_day').style.display = 'block'; document.getElementById('day_1').style.display = 'none'; document.getElementById('day_2').style.display = 'none'; document.getElementById('day_3').style.display = 'none'; document.getElementById('day_4').style.display = 'none'; } } function stampDetailUser(id) { if (auth_user == 1) { document.getElementById("stamp_detail_user").style.display = 'block'; document.getElementById("open_stamp_detail_user").click(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#stamp_detail_content_user").innerHTML = this.responseText; } }; xmlhttp.open("GET", "php/admin/stamp_detail_content.php?id="+id); xmlhttp.send(); } else { openLoginSection(); } } function deleteStamp(id) { Swal.fire({ title: "Inserire il motivo dell'eliminazione", input: "text", inputAttributes: { autocapitalize: "off" }, showCancelButton: true, confirmButtonText: "Invia richiesta", showLoaderOnConfirm: true }).then((result) => { $.ajax({ type: "POST", url: "php/stamp/delete_stamp_request.php", data: { id : id, result : result.value }, success: function (res) { if (res === 'richiesta') { Swal.fire({ type: 'success', title: 'Richiesta inviata con successo, attendi approvazione!', showConfirmButton: true, timer: 2000 }); } if (res === 'eliminata') { Swal.fire({ type: 'success', title: 'Timbratura eliminata con successo!', showConfirmButton: false, timer: 2000 }); } openStampList(); } }); }); } function SetDate() { date = document.querySelector('#stamp_date_1').value; document.querySelector('#stamp_date_2').value = date; document.querySelector('#stamp_date_3').value = date; document.querySelector('#stamp_date_4').value = date; }