function LoadUsersList(user_id) { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#users_list_content").innerHTML = this.responseText; StampsListUser(user_id); $(document).ready(function () { new DataTable("#users_stamp_table", { paging: false, scrollCollapse: true, scrollY: "500px", language: { emptyTable: "Nessun dato presente nella tabella", search: "Cerca:", infoEmpty: "Visualizzati da 0 a 0 di 0 risultati", info: "Visualizzati da _START_ a _END_ di _TOTAL_ risultati", buttons: { print: "Stampa", colvis: "Visualizza", colvisRestore: "Ripristina visualizzazione", }, }, }); }); } }; xmlhttp.open("GET", "public/stamps/users_list.php"); xmlhttp.send(); } function StampsListUser(user_id) { console.log("ok"); ShowPageLoader(); /* for (i = 0; i < 50; i++) { if (document.getElementById(i) != null) { document.getElementById(i).style.backgroundColor = "transparent"; } } document.getElementById(user_id).style.backgroundColor = "#e0f2f1"; */ document.getElementById("stamps_list_loader").style.display = "block"; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#stamps_list_content").innerHTML = this.responseText; HidePageLoader(); $(document).ready(function () { new DataTable("#stamps_list_table", { paging: false, scrollCollapse: true, scrollY: "500px", layout: { topStart: { buttons: [ { extend: "print", split: ["print", "excel", "pdf", "csv"], }, { text: "Calendario", action: function (e, dt, node, config) { UserCalendar(user_id); }, }, { text: "Nuova timbratura", action: function (e, dt, node, config) { NewStamp(user_id); }, }, ], }, }, language: { url: "//cdn.datatables.net/plug-ins/2.1.7/i18n/it-IT.json", }, order: [ [0, "desc"], [1, "desc"], ], }); }); document.getElementById("stamps_list_loader").style.display = "none"; } }; xmlhttp.open("GET", "public/stamps/stamps_list.php?user_id=" + user_id); xmlhttp.send(); } function loadTotalStampsToApprove() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#stamps_to_approve_count").innerHTML = this.responseText; } }; xmlhttp.open("GET", "public/stamps/stamps_to_approve_count.php"); xmlhttp.send(); } function loadStampsToApprove() { document.getElementById("open_permissions_to_approve").click(); stampsToApprove(); } function stampsToApprove() { document.getElementById("open_stamps_to_approve").click(); ShowPageLoader(); setTimeout(() => { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#stamps_to_approve_content").innerHTML = this.responseText; HidePageLoader(); $(document).ready(function () { new DataTable("#stamps_to_approve_table", { paging: false, scrollCollapse: true, scrollY: "400px", layout: { topStart: { buttons: [ { extend: "colvis", postfixButtons: ["colvisRestore"], popoverTitle: "Visibilità colonne", }, { extend: "print", split: ["print", "excel", "pdf", "csv"], }, ], }, }, language: { emptyTable: "Nessun dato presente nella tabella", search: "Cerca:", infoEmpty: "Visualizzati da 0 a 0 di 0 risultati", info: "Visualizzati da _START_ a _END_ di _TOTAL_ risultati", buttons: { print: "Stampa", colvis: "Visualizza", colvisRestore: "Ripristina visualizzazione", }, }, order: { idx: 1, dir: "desc", }, }); }); } }; xmlhttp.open("GET", "public/stamps/stamps_to_approve_list.php"); xmlhttp.send(); }, 1000); } function NewStamp(user_id) { document.getElementById("open_new_stamp").click(); ShowPageLoader(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#new_stamp_content").innerHTML = this.responseText; HidePageLoader(); } }; xmlhttp.open("GET", "public/stamps/new_stamp_content.php?user_id=" + user_id); xmlhttp.send(); } function changeNewStampTransfertType() { var new_stamp_transfert = document.getElementById( "new_stamp_transfert" ).checked; if (new_stamp_transfert == true) { document.getElementById("stamp_transfer_location_container").style.display = "flex"; } else { document.getElementById("stamp_transfer_location_container").style.display = "none"; } } function CreateNewStamp(user_id) { ShowPageLoader(); var stamp_type_entry = document.getElementById( "new_stamp_type_entry" ).checked; var stamp_type_exit = document.getElementById("new_stamp_type_exit").checked; var stamp_transfert = document.getElementById("new_stamp_transfert").checked; var stamp_transfer_location = document.getElementById( "new_stamp_transfer_location" ).value; var stamp_date = document.getElementById("new_stamp_date").value; var stamp_time = document.getElementById("new_stamp_time").value; var stamp_note = document.getElementById("new_stamp_note").value; $.ajax({ type: "POST", url: "php/stamps/new_stamp.php", data: { user_id: user_id, stamp_type_entry: stamp_type_entry, stamp_type_exit: stamp_type_exit, stamp_transfert: stamp_transfert, stamp_transfer_location: stamp_transfer_location, stamp_date: stamp_date, stamp_time: stamp_time, stamp_note: stamp_note, }, success: function (res) { if (res === "attendancePresent") { ErrorAlert("Il cartellino del mese è già stato chiuso."); } else if (res === "error") { ErrorAlert("Errore: " + res); } else if (res === "maxStamps") { ErrorAlert("Numero massimo di timbrature raggiunto"); } else { SuccessAlert("Timbratura inserita"); document.getElementById("close_new_stamp").click(); StampsListUser(user_id); const date = new Date(); loadUserCalendar(user_id, "dayGridMonth", date); } HidePageLoader(); }, }); } function editStamp(user_id, stamp_id) { document.getElementById("open_stamp_details").click(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#stamp_details_content").innerHTML = this.responseText; } }; xmlhttp.open( "GET", "public/stamps/stamp_details_content.php?stamp_id=" + stamp_id + "&user_id=" + user_id ); xmlhttp.send(); } function changeStampTransfertType() { var new_stamp_transfert = document.getElementById("stamp_transfert").checked; if (new_stamp_transfert == true) { document.getElementById("stamp_transfer_location_container").style.display = "flex"; } else { document.getElementById("stamp_transfer_location_container").style.display = "none"; } } function updateStamp(user_id, stamp_id) { ShowPageLoader(); var stamp_type_entry = document.getElementById("stamp_type_entry").checked; var stamp_type_exit = document.getElementById("stamp_type_exit").checked; var stamp_transfert = document.getElementById("stamp_transfert").checked; var stamp_transfer_location = document.getElementById( "stamp_transfer_location" ).value; var stamp_date = document.getElementById("stamp_date").value; var stamp_time = document.getElementById("stamp_time").value; var stamp_note = document.getElementById("stamp_note").value; $.ajax({ type: "POST", url: "php/stamps/update_stamp.php", data: { stamp_id: stamp_id, stamp_type_entry: stamp_type_entry, stamp_type_exit: stamp_type_exit, stamp_transfert: stamp_transfert, stamp_date: stamp_date, stamp_time: stamp_time, stamp_note: stamp_note, stamp_transfer_location: stamp_transfer_location, }, success: function (res) { if (res === "attendancePresent") { ErrorAlert("Il cartellino del mese è già stato chiuso"); } else if (res === "error") { ErrorAlert("Errore: " + res); } else if (res === "maxStamps") { ErrorAlert("Numero massimo di timbrature raggiunto"); } else { SuccessAlert("Timbratura modificata"); document.getElementById("close_stamp_details").click(); StampsListUser(user_id); const date = new Date(); loadUserCalendar(user_id), "dayGridMonth", date; } HidePageLoader(); }, }); } async function deleteStamp(user_id, stamp_id, user_type) { document.getElementById("close_stamp_details").click(); if (user_type == "Admin") { Swal.fire({ title: "Confermi eliminazione?", text: "La timbratura verrà eliminata dal sistema", icon: "warning", showCancelButton: true, confirmButtonColor: "#d33", cancelButtonColor: "gray", confirmButtonText: "Sì, elimina!", cancelButtonText: "Annulla", }).then((result) => { if (result.isConfirmed) { ShowPageLoader(); $.ajax({ type: "POST", url: "php/stamps/delete_stamp.php", data: { stamp_id: stamp_id }, success: function (res) { if (res === "attendancePresent") { ErrorAlert("Il cartellino del mese è già stato chiuso."); } else if (res === "error") { ErrorAlert("Errore: " + res); } else if (res === "deleted") { SuccessAlert("Timbratura eliminata"); StampsListUser(user_id); const date = new Date(); loadUserCalendar(user_id, "dayGridMonth", date); document.getElementById("close_stamp_details").click(); } else if (res === "requestSent") { SuccessAlert("Richiesta eliminazione inviata"); StampsListUser(user_id); const date = new Date(); loadUserCalendar(user_id, "dayGridMonth", date); document.getElementById("close_stamp_details").click(); } HidePageLoader(); }, }); } }); } else { const { value: result } = await Swal.fire({ title: "Motivo dell'eliminazione", input: "text", inputLabel: "", inputPlaceholder: "Inserisci il motivo", showCancelButton: true, cancelButtonText: "Annulla", }); if (result) { ShowPageLoader(); $.ajax({ type: "POST", url: "php/stamps/delete_stamp.php", data: { stamp_id: stamp_id, result: result }, success: function (res) { if (res === "attendancePresent") { ErrorAlert("Il cartellino del mese è già stato chiuso"); } else if (res === "error") { ErrorAlert("Errore: " + res); } else if (res === "deleted") { SuccessAlert("Timbratura eliminata"); StampsListUser(user_id); const date = new Date(); loadUserCalendar(user_id, "dayGridMonth", date); document.getElementById("close_stamp_details").click(); } else if (res === "requestSent") { SuccessAlert("Richiesta eliminazione inviata"); StampsListUser(user_id); const date = new Date(); loadUserCalendar(user_id, "dayGridMonth", date); document.getElementById("close_stamp_details").click(); } HidePageLoader(); }, }); } else { ErrorAlert("Motivazione è obbligatoria"); } } } function approveStampDelete(user_id, stamp_id) { Swal.fire({ title: "Confermi approvazione?", text: "", icon: "question", showCancelButton: true, confirmButtonColor: "#d33", cancelButtonColor: "gray", confirmButtonText: "Procedi", cancelButtonText: "Annulla", }).then((result) => { if (result.isConfirmed) { ShowPageLoader(); $.ajax({ type: "POST", url: "php/stamps/manage_stamp.php", data: { id: stamp_id, result: "approvato" }, success: function (res) { if (res === "attendancePresent") { ErrorAlert("Il cartellino del mese è già stato chiuso"); } else if (res === "error") { ErrorAlert("Errore: " + res); } else { SuccessAlert("Richiesta eliminazione approvata"); StampsListUser(user_id); LoadUsersList(user_id); loadTotalStampsToApprove(); stampsToApprove(); document.getElementById("close_stamp_details").click(); const date = new Date(); loadUserCalendar(user_id, "dayGridMonth", date); } HidePageLoader(); }, }); } }); } function rejectStampDelete(user_id, stamp_id) { Swal.fire({ title: "Confermi rifiuto?", text: "", icon: "question", showCancelButton: true, confirmButtonColor: "#d33", cancelButtonColor: "gray", confirmButtonText: "Procedi", cancelButtonText: "Annulla", }).then((result) => { if (result.isConfirmed) { ShowPageLoader(); $.ajax({ type: "POST", url: "php/stamps/manage_stamp.php", data: { id: stamp_id, result: "rifiutato" }, success: function (res) { if (res === "attendancePresent") { ErrorAlert("Il cartellino del mese è già stato chiuso"); } else if (res === "error") { ErrorAlert("Errore: " + res); } else { SuccessAlert("Richiesta eliminazione rifiutata"); StampsListUser(user_id); LoadUsersList(user_id); loadTotalStampsToApprove(); stampsToApprove(); document.getElementById("close_stamp_details").click(); const date = new Date(); loadUserCalendar(user_id, "dayGridMonth", date); } HidePageLoader(); }, }); } }); } function UserCalendar(user_id) { document.getElementById("open_user_calendar").click(); ShowPageLoader(); setTimeout(() => { const date = new Date(); loadUserCalendar(user_id, "dayGridMonth", date); HidePageLoader(); }, 1000); } function UserCalendarDate(user_id, date) { document.getElementById("open_user_calendar").click(); ShowPageLoader(); setTimeout(() => { loadUserCalendar(user_id, "timeGridDay", date); HidePageLoader(); }, 1000); } function loadUserCalendar(user_id, view, date) { 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: view, locale: "it", editable: false, height: 700, now: date, displayEventTime: true, forceEventDuration: true, defaultTimedEventDuration: "00:00:01", firstDay: 1, customButtons: { myCustomButton: { text: "Nuova timbratura", click: function () { NewStamp(user_id); }, }, }, headerToolbar: { left: "prev,next today myCustomButton", center: "title", right: "dayGridMonth,timeGridWeek,timeGridDay,listMonth", }, 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/stamps/get_calendar_stamps.php?user_id=" + user_id, eventDisplay: "block", displayEventTime: true, eventTimeFormat: { hour: "2-digit", minute: "2-digit", hour12: false, }, selectable: true, select: function (info) { 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", "public/stamps/new_stamp_content.php?user_id=" + user_id + "&date=" + info.startStr ); xmlhttp.send(); }, eventClick: function (info) { document.getElementById("open_stamp_details").click(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#stamp_details_content").innerHTML = this.responseText; } }; xmlhttp.open( "GET", "public/stamps/stamp_details_content.php?stamp_id=" + info.event.id + "&user_id=" + user_id ); xmlhttp.send(); }, }); calendar.render(); //calendar.changeView('timeGridWeek'); } }; xmlhttp.open( "GET", "public/stamps/stamps_calendar_content.php?user_id=" + user_id ); xmlhttp.send(); }