function sendStamp() { document.querySelector("#send_stamp_button").style.display = "none"; if (document.getElementById("stamp_day").checked == true) { var stamp_date_day = document.querySelector("#stamp_date_day").value; var stamp_time_day1 = document.querySelector("#stamp_time_day1").value; var stamp_time_day2 = document.querySelector("#stamp_time_day2").value; var stamp_time_day3 = document.querySelector("#stamp_time_day3").value; var stamp_time_day4 = document.querySelector("#stamp_time_day4").value; var in_transfer_day = document.querySelector("#in_transfer_day").checked; var transfer_location_day = document.querySelector( "#transfer_location_day" ).value; var insert = 0; if (in_transfer_day == true) { if (transfer_location_day == "") { const Toast = Swal.mixin({ toast: true, position: "bottom", showConfirmButton: false, timer: 3000, timerProgressBar: true, didOpen: (toast) => { toast.onmouseenter = Swal.stopTimer; toast.onmouseleave = Swal.resumeTimer; }, }); Toast.fire({ icon: "error", title: "Luogo trasferta è obbligatorio", }); document.querySelector("#send_stamp_button").style.display = "block"; exit; } } if (stamp_date_day == "") { const Toast = Swal.mixin({ toast: true, position: "bottom", showConfirmButton: false, timer: 3000, timerProgressBar: true, didOpen: (toast) => { toast.onmouseenter = Swal.stopTimer; toast.onmouseleave = Swal.resumeTimer; }, }); Toast.fire({ icon: "error", title: "Data è obbligatoria", }); document.querySelector("#send_stamp_button").style.display = "block"; exit; } if (stamp_time_day1 != "") { insert++; var postData1 = { stamp_type: "Entrata", stamp_date: stamp_date_day, stamp_time: stamp_time_day1, stamp_note: "", in_transfer: in_transfer_day, transfer_location: transfer_location_day, }; console.log("Invio timbratura giorno 1:", postData1); $.ajax({ type: "POST", url: "php/stamp/send_new_stamp.php", data: postData1, success: function (res) { console.log("Risposta timbratura giorno 1:", res); if (res.indexOf("error") === 0) { var errorParts = res.split("|"); if (errorParts.length > 1) { console.error("Errore dettagliato giorno 1:", errorParts[1]); } Swal.fire({ type: "error", text: "Errore: " + res, }); } else { console.log("Timbratura giorno 1 creata con successo"); } }, error: function (xhr, status, error) { console.error("Errore AJAX timbratura giorno 1:", status, error); console.error("Risposta server:", xhr.responseText); }, }); } if (stamp_time_day2 != "") { insert++; var postData2 = { stamp_type: "Uscita", stamp_date: stamp_date_day, stamp_time: stamp_time_day2, stamp_note: "", in_transfer: in_transfer_day, transfer_location: transfer_location_day, }; console.log("Invio timbratura giorno 2:", postData2); $.ajax({ type: "POST", url: "php/stamp/send_new_stamp.php", data: postData2, success: function (res) { console.log("Risposta timbratura giorno 2:", res); if (res.indexOf("error") === 0) { var errorParts = res.split("|"); if (errorParts.length > 1) { console.error("Errore dettagliato giorno 2:", errorParts[1]); } Swal.fire({ type: "error", text: "Errore: " + res, }); } else { console.log("Timbratura giorno 2 creata con successo"); } }, error: function (xhr, status, error) { console.error("Errore AJAX timbratura giorno 2:", status, error); console.error("Risposta server:", xhr.responseText); }, }); } if (stamp_time_day3 != "") { insert++; var postData3 = { stamp_type: "Entrata", stamp_date: stamp_date_day, stamp_time: stamp_time_day3, stamp_note: "", in_transfer: in_transfer_day, transfer_location: transfer_location_day, }; console.log("Invio timbratura giorno 3:", postData3); $.ajax({ type: "POST", url: "php/stamp/send_new_stamp.php", data: postData3, success: function (res) { console.log("Risposta timbratura giorno 3:", res); if (res.indexOf("error") === 0) { var errorParts = res.split("|"); if (errorParts.length > 1) { console.error("Errore dettagliato giorno 3:", errorParts[1]); } Swal.fire({ type: "error", text: "Errore: " + res, }); } else { console.log("Timbratura giorno 3 creata con successo"); } }, error: function (xhr, status, error) { console.error("Errore AJAX timbratura giorno 3:", status, error); console.error("Risposta server:", xhr.responseText); }, }); } if (stamp_time_day4 != "") { insert++; var postData4 = { stamp_type: "Uscita", stamp_date: stamp_date_day, stamp_time: stamp_time_day4, stamp_note: "", in_transfer: in_transfer_day, transfer_location: transfer_location_day, }; console.log("Invio timbratura giorno 4:", postData4); $.ajax({ type: "POST", url: "php/stamp/send_new_stamp.php", data: postData4, success: function (res) { console.log("Risposta timbratura giorno 4:", res); if (res.indexOf("error") === 0) { var errorParts = res.split("|"); if (errorParts.length > 1) { console.error("Errore dettagliato giorno 4:", errorParts[1]); } Swal.fire({ type: "error", text: "Errore: " + res, }); } else { console.log("Timbratura giorno 4 creata con successo"); } }, error: function (xhr, status, error) { console.error("Errore AJAX timbratura giorno 4:", status, error); console.error("Risposta server:", xhr.responseText); }, }); } if (insert == 0) { const Toast = Swal.mixin({ toast: true, position: "bottom", showConfirmButton: false, timer: 3000, timerProgressBar: true, didOpen: (toast) => { toast.onmouseenter = Swal.stopTimer; toast.onmouseleave = Swal.resumeTimer; }, }); Toast.fire({ icon: "warning", title: "Nessuna timbratura registrata", }); document.querySelector("#send_stamp_button").style.display = "block"; } else { const Toast = Swal.mixin({ toast: true, position: "bottom", showConfirmButton: false, timer: 3000, timerProgressBar: true, didOpen: (toast) => { toast.onmouseenter = Swal.stopTimer; toast.onmouseleave = Swal.resumeTimer; }, }); Toast.fire({ icon: "success", title: "Timbrature registrate", }); setTimeout(function () { window.location.href = "stamps_list.php"; }, 2000); } } 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; var transfer_location = document.querySelector("#transfer_location").value; if (stamp_type == "") { const Toast = Swal.mixin({ toast: true, position: "bottom", showConfirmButton: false, timer: 3000, timerProgressBar: true, didOpen: (toast) => { toast.onmouseenter = Swal.stopTimer; toast.onmouseleave = Swal.resumeTimer; }, }); Toast.fire({ icon: "error", title: "Tipo è obbligatorio", }); document.querySelector("#send_stamp_button").style.display = "block"; exit; } if (in_transfer == true) { if (transfer_location == "") { const Toast = Swal.mixin({ toast: true, position: "bottom", showConfirmButton: false, timer: 3000, timerProgressBar: true, didOpen: (toast) => { toast.onmouseenter = Swal.stopTimer; toast.onmouseleave = Swal.resumeTimer; }, }); Toast.fire({ icon: "error", title: "Luogo trasferta è obbligatorio", }); document.querySelector("#send_stamp_button").style.display = "block"; exit; } } if (stamp_date == "") { const Toast = Swal.mixin({ toast: true, position: "bottom", showConfirmButton: false, timer: 3000, timerProgressBar: true, didOpen: (toast) => { toast.onmouseenter = Swal.stopTimer; toast.onmouseleave = Swal.resumeTimer; }, }); Toast.fire({ icon: "error", title: "Data è obbligatoria", }); document.querySelector("#send_stamp_button").style.display = "block"; exit; } if (stamp_time == "") { const Toast = Swal.mixin({ toast: true, position: "bottom", showConfirmButton: false, timer: 3000, timerProgressBar: true, didOpen: (toast) => { toast.onmouseenter = Swal.stopTimer; toast.onmouseleave = Swal.resumeTimer; }, }); Toast.fire({ icon: "error", title: "Ora è obbligatoria", }); document.querySelector("#send_stamp_button").style.display = "block"; exit; } var postData = { stamp_type: stamp_type, stamp_date: stamp_date, stamp_time: stamp_time, stamp_note: stamp_note, in_transfer: in_transfer, transfer_location: transfer_location, }; console.log("Invio dati timbratura:", postData); $.ajax({ type: "POST", url: "php/stamp/send_new_stamp.php", data: postData, success: function (res) { console.log("Risposta server:", res); if (res.indexOf("error") === 0) { var errorParts = res.split("|"); if (errorParts.length > 1) { console.error("Errore dettagliato:", errorParts[1]); } const Toast = Swal.mixin({ toast: true, position: "bottom", showConfirmButton: false, timer: 3000, timerProgressBar: true, didOpen: (toast) => { toast.onmouseenter = Swal.stopTimer; toast.onmouseleave = Swal.resumeTimer; }, }); Toast.fire({ icon: "error", title: "Si è verificato un errore", }); document.querySelector("#send_stamp_button").style.display = "block"; } else { console.log("Timbratura creata con successo"); const Toast = Swal.mixin({ toast: true, position: "bottom", showConfirmButton: false, timer: 3000, timerProgressBar: true, didOpen: (toast) => { toast.onmouseenter = Swal.stopTimer; toast.onmouseleave = Swal.resumeTimer; }, }); Toast.fire({ icon: "success", title: "Timbratura registrata", }); openStampsList(); } }, error: function (xhr, status, error) { console.error("Errore AJAX:", status, error); console.error("Status code:", xhr.status); console.error("Risposta server:", xhr.responseText); const Toast = Swal.mixin({ toast: true, position: "bottom", showConfirmButton: false, timer: 3000, timerProgressBar: true, didOpen: (toast) => { toast.onmouseenter = Swal.stopTimer; toast.onmouseleave = Swal.resumeTimer; }, }); Toast.fire({ icon: "error", title: "Errore di connessione: " + error, }); document.querySelector("#send_stamp_button").style.display = "block"; }, }); } } function ChangeInTransfer() { if (document.getElementById("in_transfer").checked == true) { document.getElementById("transfer_location_container").style.display = "block"; } else { document.getElementById("transfer_location_container").style.display = "none"; } } function ChangeInTransferDay() { if (document.getElementById("in_transfer_day").checked == true) { document.getElementById("transfer_location_container_day").style.display = "block"; } else { document.getElementById("transfer_location_container_day").style.display = "none"; } } function ChangeDay() { if (document.getElementById("stamp_day").checked == true) { document.getElementById("full_day").style.display = "block"; document.getElementById("no_day").style.display = "none"; } else { document.getElementById("full_day").style.display = "none"; document.getElementById("no_day").style.display = "block"; } } function stampDetailUser(id) { 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(); } function deleteStamp(id) { Swal.fire({ title: "Motivo dell'eliminazione", input: "text", inputAttributes: { autocapitalize: "off", }, showCancelButton: true, confirmButtonText: "Invia richiesta", confirmButtonColor: "black", showLoaderOnConfirm: true, }).then((result) => { if (result.isConfirmed) { $.ajax({ type: "POST", url: "../ds/php/stamps/delete_stamp.php", data: { id: id, result: result.value }, success: function (res) { if (res === "ok") { const Toast = Swal.mixin({ toast: true, position: "top-end", showConfirmButton: false, timer: 5000, timerProgressBar: true, didOpen: (toast) => { toast.onmouseenter = Swal.stopTimer; toast.onmouseleave = Swal.resumeTimer; }, }); Toast.fire({ icon: "success", title: "Richiesta inviata con successo", }); } else { const Toast = Swal.mixin({ toast: true, position: "top-end", showConfirmButton: false, timer: 5000, timerProgressBar: true, didOpen: (toast) => { toast.onmouseenter = Swal.stopTimer; toast.onmouseleave = Swal.resumeTimer; }, }); Toast.fire({ icon: "error", title: "Si è verificato un errore", }); } location.reload(); }, }); } }); } 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; } function UserCalendar(user_id) { document.getElementById("open_user_calendar").click(); setTimeout(() => { loadUserCalendar(user_id); }, 1000); } function loadUserCalendar(user_id) { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#user_calendar_content").innerHTML = this.responseText; var calendarEl = document.getElementById("calendar"); var calendar = new FullCalendar.Calendar(calendarEl, { initialView: "dayGridMonth", locale: "it", editable: false, height: 700, displayEventTime: true, forceEventDuration: true, defaultTimedEventDuration: "00:01", firstDay: 1, headerToolbar: { left: "prev,next", right: "title", }, buttonText: { prev: "Prec", next: "Succ", today: "Oggi", year: "Anno", month: "Mese", week: "Settimana", day: "Giorno", list: "Agenda", }, allDayText: "Tutto il giorno", moreLinkText(n) { return "+altri " + n; }, events: "php/stamp/get_calendar_stamps.php?user_id=" + user_id, eventDisplay: "block", /* eventColor: '#378006', */ displayEventTime: true, eventTimeFormat: { hour: "2-digit", minute: "2-digit", hour12: false, }, noEventsText: "Non ci sono eventi da visualizzare", eventRender: function (event, element, view) { if (event.allDay === "true") { event.allDay = true; } else { event.allDay = false; } }, selectable: false, }); calendar.render(); //calendar.changeView('timeGridWeek'); } }; xmlhttp.open( "GET", "public/stamps/stamps_calendar_content.php?user_id=" + user_id ); xmlhttp.send(); }