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++; $.ajax({ type: "POST", url: "php/stamp/send_new_stamp.php", data: { 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 }, success: function (res) { if (res === 'error') { Swal.fire({ type: 'error', text: 'Errore: ' + res }); } } }); } if(stamp_time_day2 != "") { insert++; $.ajax({ type: "POST", url: "php/stamp/send_new_stamp.php", data: { 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 }, success: function (res) { if (res === 'error') { Swal.fire({ type: 'error', text: 'Errore: ' + res }); } } }); } if(stamp_time_day3 != "") { insert++; $.ajax({ type: "POST", url: "php/stamp/send_new_stamp.php", data: { 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 }, success: function (res) { if (res === 'error') { Swal.fire({ type: 'error', text: 'Errore: ' + res }); } } }); } if(stamp_time_day4 != "") { insert++; $.ajax({ type: "POST", url: "php/stamp/send_new_stamp.php", data: { 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 }, success: function (res) { if (res === 'error') { Swal.fire({ type: 'error', text: 'Errore: ' + res }); } } }); } 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; } $.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, transfer_location : transfer_location }, success: function (res) { if (res === 'error') { 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 { 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(); } } }); } } 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(); }