function LoadUsersList() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#users_list_content").innerHTML = this.responseText; HidePageLoader(); $(document).ready(function() { new DataTable('#users_situation_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/situation/users_list.php"); xmlhttp.send(); } function UserCalendar(user_id, view, date) { 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("situation_list_loader").style.display = "block"; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#user_calendar_content").innerHTML = this.responseText; HidePageLoader(); setTimeout(() => { /* const date = new Date(); */ loadUserCalendar(user_id, view, date); }, 1000); document.getElementById("situation_list_loader").style.display = "none"; } }; xmlhttp.open("GET", "public/situation/user_calendar_content.php?user_id="+user_id); xmlhttp.send(); } function loadUserCalendar(user_id, view, date) { var calendarEl = document.getElementById('calendar'); var calendar = new FullCalendar.Calendar(calendarEl, { initialView: view, locale: 'it', editable: false, height: 600, now: date, initialDate: date, displayEventTime: true, forceEventDuration: true, defaultTimedEventDuration: '00:00:01', firstDay: 1, customButtons: { myCustomButton: { text: 'Nuovo evento', click: function() { OpenNewEvent(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/situation/get_calendar_events.php?user_id="+user_id, eventDisplay: 'block', displayEventTime: true, eventTimeFormat: { hour: '2-digit', minute: '2-digit', hour12: false }, selectable: true, select: function (info) { OpenNewEvent(user_id,info.startStr,info.endStr); }, eventClick: function (info) { if(info.event.groupId == "stamp") { OpenStampDetails(info.event.id, user_id); } else if(info.event.groupId == "permission") { OpenPermissionDetails(info.event.id, user_id); } else if(info.event.groupId == "problem") { OpenErrorDetails(info.event.id, user_id); } } }); calendar.render(); } function UserProblemsList(user_id, start_date, end_date) { document.getElementById("open_problems_list").click(); ShowPageLoader(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#problems_list_content").innerHTML = this.responseText; HidePageLoader(); setTimeout(function(){ $(document).ready( function () { new DataTable('#problems_list_table', { paging: false, scrollCollapse: true, scrollY: '500px', layout: { topStart: { buttons: [ { extend: 'colvis', postfixButtons: ['colvisRestore'], popoverTitle: 'Visibilità colonne' }, { extend: 'print', split: ['print','excel','pdf', 'csv'] }, { text: 'Aggiorna', action: function (e, dt, node, config) { RunProblemsControl('true'); } } ] } }, 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: 4, dir: 'desc' } }); } ); }, 1000); } }; xmlhttp.open("GET", "public/situation/problems_list_content.php?user_id="+user_id); xmlhttp.send(); } function RunProblemsControl(from_problems) { var start_date_check = document.getElementById("start_date_check").value; var end_date_check = document.getElementById("end_date_check").value; document.getElementById("control_button").style.display = 'none'; document.getElementById('control_loader').style.display = 'block'; if(from_problems == "true") { document.getElementById("close_problems_list").click(); } $.ajax({ type: "POST", url: "php/check_problems.php", data: { start_date_check: start_date_check, end_date_check : end_date_check, manual : 'true'}, success: function (res) { if (res == 'ok') { SuccessAlert('Controlli effettuati'); location.reload(); } else { ErrorAlert("Errore: "+res); } } }); } async function OpenNewEvent(user_id,start,end) { const inputOptions = new Promise((resolve) => { resolve({ "stamp": "Timbratura", "permission": "Permesso", }); }); const { value: eventType } = await Swal.fire({ title: "Tipo evento", input: "radio", inputOptions, inputValidator: (value) => { if (!value) { return "Devi selezionare un tipo evento!"; } } }); if (eventType) { if(eventType == "stamp") { NewStamp(user_id, start); } else if(eventType == "permission") { NewPermission(user_id, start, end); } } } function NewStamp(user_id, start) { 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="+start); 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 === 'error') { ErrorAlert("Errore: "+res) } else if (res === 'maxStamps') { ErrorAlert("Numero massimo di timbrature raggiunto"); } else { SuccessAlert('Timbratura inserita'); document.getElementById("close_new_stamp").click(); const date = new Date(); loadUserCalendar(user_id, 'dayGridMonth', date); } HidePageLoader(); } }); } function OpenStampDetails(stamp_id, user_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 === 'error') { ErrorAlert("Errore: "+res); } else if (res === 'maxStamps') { ErrorAlert("Numero massimo di timbrature raggiunto"); } else { SuccessAlert('Timbratura modificata'); document.getElementById("close_stamp_details").click(); const date = new Date(); loadUserCalendar(user_id), 'dayGridMonth',date; } HidePageLoader(); } }); } function deleteStamp(user_id, stamp_id, user_type) { if(user_type == "Admin") { Swal.fire({ title: "Confermi eliminazione?", text: "La timbratura verrà eliminata dal sistema", icon: "warning", showCancelButton: true, confirmButtonColor: "#d33", cancelButtonColor: "#3085d6", 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 === 'error') { ErrorAlert("Errore: "+res) } else if (res === 'deleted') { SuccessAlert('Timbratura eliminata'); const date = new Date(); loadUserCalendar(user_id, 'dayGridMonth',date); document.getElementById("close_stamp_details").click(); } else if (res === 'requestSent') { SuccessAlert('Richiesta eliminazione inviata'); const date = new Date(); loadUserCalendar(user_id, 'dayGridMonth',date); document.getElementById("close_stamp_details").click(); } HidePageLoader(); } }); } }); } else { 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) { ShowPageLoader(); $.ajax({ type: "POST", url: "php/stamps/delete_stamp.php", data: { stamp_id: stamp_id, result : result.value }, success: function (res) { if (res === 'error') { ErrorAlert("Errore: "+res) } else if (res === 'deleted') { SuccessAlert('Timbratura eliminata'); const date = new Date(); loadUserCalendar(user_id, 'dayGridMonth',date); document.getElementById("close_stamp_details").click(); } else if (res === 'requestSent') { SuccessAlert('Richiesta eliminazione inviata'); const date = new Date(); loadUserCalendar(user_id, 'dayGridMonth', date); document.getElementById("close_stamp_details").click(); } HidePageLoader(); } }); } }); } } function NewPermission(user_id, start, end) { document.getElementById("open_new_permission").click(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#new_permission_content").innerHTML = this.responseText; } }; xmlhttp.open("GET", "public/permissions/new_permission_content.php?user_id="+user_id+"&startDate="+start+"&endDate="+end); xmlhttp.send(); } function changeFullDay() { var full_day = document.getElementById("new_permission_full_day").checked; if(full_day == true) { document.getElementById("new_permission_from_time_container").style.display = 'none'; document.getElementById("new_permission_to_time_container").style.display = 'none'; } else { document.getElementById("new_permission_from_time_container").style.display = 'flex'; document.getElementById("new_permission_to_time_container").style.display = 'flex'; } } function CreateNewPermission(user_id) { var permission_justification = document.getElementById("new_permission_justification").value; var permission_full_day = document.getElementById("new_permission_full_day").checked; var permission_start_date = document.getElementById("new_permission_start_date").value; var permission_end_date = document.getElementById("new_permission_end_date").value; var permission_start_time = document.getElementById("new_permission_start_time").value; var permission_end_time = document.getElementById("new_permission_end_time").value; var permission_note = document.getElementById("new_permission_note").value; if(permission_justification == "") { ErrorAlert("Giustificativo è obbligatorio"); exit; } ShowPageLoader(); $.ajax({ type: "POST", url: "php/permissions/new_permission.php", data: { user_id: user_id, permission_justification: permission_justification, permission_full_day: permission_full_day, permission_start_date: permission_start_date, permission_end_date: permission_end_date, permission_start_time: permission_start_time, permission_end_time: permission_end_time, permission_note: permission_note }, success: function (res) { if (res === 'error') { ErrorAlert("Errore: "+res) } else { SuccessAlert('Permesso inserito'); document.getElementById("close_new_permission").click(); const date = new Date(); loadUserCalendar(user_id, 'dayGridMonth', date); } HidePageLoader(); } }); } function OpenPermissionDetails(permission_id, user_id) { document.getElementById("open_permission_details").click(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#permission_details_content").innerHTML = this.responseText; } }; xmlhttp.open("GET", "public/permissions/permission_details_content.php?permission_id="+permission_id+"&user_id="+user_id); xmlhttp.send(); } function changeFullDayEdit() { var full_day = document.getElementById("permission_full_day").checked; if(full_day == true) { document.getElementById("permission_from_time_container").style.display = 'none'; document.getElementById("permission_to_time_container").style.display = 'none'; } else { document.getElementById("permission_from_time_container").style.display = 'flex'; document.getElementById("permission_to_time_container").style.display = 'flex'; } } function updatePermission(user_id, permission_id) { ShowPageLoader(); var permission_justification = document.getElementById("permission_justification").value; var permission_full_day = document.getElementById("permission_full_day").checked; var permission_start_date = document.getElementById("permission_start_date").value; var permission_end_date = document.getElementById("permission_end_date").value; var permission_start_time = document.getElementById("permission_start_time").value; var permission_end_time = document.getElementById("permission_end_time").value; var permission_note = document.getElementById("permission_note").value; $.ajax({ type: "POST", url: "php/permissions/update_permission.php", data: { permission_id: permission_id, permission_justification: permission_justification, permission_full_day: permission_full_day, permission_start_date: permission_start_date, permission_end_date: permission_end_date, permission_start_time: permission_start_time, permission_end_time: permission_end_time, permission_note: permission_note }, success: function (res) { if (res === 'error') { ErrorAlert("Errore: "+res); } else { SuccessAlert('Permesso modificato'); const date = new Date(); loadUserCalendar(user_id, 'dayGridMonth', date); document.getElementById("close_permission_details").click(); } HidePageLoader(); } }); } function deletePermission(user_id, permission_id) { Swal.fire({ title: "Confermi eliminazione?", text: "Il permesso verrà eliminato dal sistema", icon: "warning", showCancelButton: true, confirmButtonColor: "#d33", cancelButtonColor: "#3085d6", confirmButtonText: "Sì, elimina!", cancelButtonText: "Annulla" }).then((result) => { if (result.isConfirmed) { ShowPageLoader(); $.ajax({ type: "POST", url: "php/permissions/delete_permission.php", data: { permission_id: permission_id }, success: function (res) { if (res === 'error') { ErrorAlert("Errore: "+res) } else { SuccessAlert('Permesso eliminato'); const date = new Date(); loadUserCalendar(user_id, 'dayGridMonth', date); document.getElementById("close_permission_details").click(); } HidePageLoader(); } }); } }); } function OpenErrorDetails(error_id, user_id) { document.getElementById("open_error_details").click(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#error_details_content").innerHTML = this.responseText; } }; xmlhttp.open("GET", "public/situation/error_details_content.php?error_id="+error_id+"&user_id="+user_id); xmlhttp.send(); } function resolveProblem(problem_id, user_id) { $.ajax({ type: "POST", url: "php/situation/resolve_problem.php", data: { problem_id: problem_id }, success: function (res) { if (res === 'error') { ErrorAlert("Errore: "+res) } else { SuccessAlert('Problema risolto'); LoadUsersList(); const date = new Date(); UserCalendar(user_id, 'dayGridMonth', date); UserProblemsList(user_id,'', ''); } HidePageLoader(); } }); }