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; TransfersListUser(user_id); $(document).ready(function() { new DataTable('#users_transfer_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/transfers/users_list.php"); xmlhttp.send(); } function TransfersListUser(user_id) { 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("transfers_list_loader").style.display = "block"; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#transfers_list_content").innerHTML = this.responseText; HidePageLoader(); $(document).ready( function () { new DataTable('#transfers_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 trasferta', action: function (e, dt, node, config) { NewTransfer(user_id); } } ] } }, 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: 0, dir: 'desc' } }); } ); document.getElementById("transfers_list_loader").style.display = "none"; } }; xmlhttp.open("GET", "public/transfers/transfers_list.php?user_id="+user_id); xmlhttp.send(); } function loadTotalTransfersToApprove() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#transfers_to_approve_count").innerHTML = this.responseText; } }; xmlhttp.open("GET", "public/transfers/transfers_to_approve_count.php"); xmlhttp.send(); } function transfersToApprove() { document.getElementById("open_transfers_to_approve").click(); loadTransfersToApprove(); } function loadTransfersToApprove() { ShowPageLoader(); setTimeout(() => { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#transfers_to_approve_content").innerHTML = this.responseText; HidePageLoader(); $(document).ready( function () { new DataTable('#transfers_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/transfers/transfers_to_approve_list.php"); xmlhttp.send(); }, 1000); } function NewTransfer(user_id) { document.getElementById("open_new_transfer").click(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#new_transfer_content").innerHTML = this.responseText; } }; xmlhttp.open("GET", "public/transfers/new_transfer_content.php?user_id="+user_id); xmlhttp.send(); } function CreateNewTransfer(user_id) { ShowPageLoader(); var transfer_start_date = document.getElementById("new_transfer_start_date").value; var transfer_end_date = document.getElementById("new_transfer_end_date").value; var transfer_location = document.getElementById("new_transfer_location").value; var transfer_destination = document.getElementById("new_transfer_destination").value; if(transfer_location == "") { ErrorAlert("Italia o estero è obbligatorio"); exit; } $.ajax({ type: "POST", url: "php/transfers/new_transfer.php", data: { user_id: user_id, transfer_start_date: transfer_start_date, transfer_end_date: transfer_end_date, transfer_location: transfer_location, transfer_destination: transfer_destination }, success: function (res) { if (res === 'error') { ErrorAlert("Errore: "+res) } else { SuccessAlert('Trasferta inserita'); document.getElementById("close_new_transfer").click(); TransfersListUser(user_id); loadUserCalendar(user_id); } HidePageLoader(); } }); } function approveTransfer(user_id, transfer_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/transfers/manage_transfer.php", data: { id: transfer_id, result: 'approvato' }, success: function (res) { if (res === 'error') { ErrorAlert("Errore: "+res); } else { SuccessAlert('Trasferta approvata'); LoadUsersList(user_id); loadTotalTransfersToApprove(); loadUserCalendar(user_id); loadTransfersToApprove(); document.getElementById("close_transfer_details").click(); } HidePageLoader(); } }); } }); } function rejectTransfer(user_id, transfer_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/transfers/manage_transfer.php", data: { id: transfer_id, result: 'rifiutato' }, success: function (res) { if (res === 'error') { ErrorAlert("Errore: "+res); } else { SuccessAlert('Trasferta rifiutata'); LoadUsersList(user_id); loadTotalTransfersToApprove(); loadUserCalendar(user_id); loadTransfersToApprove(); document.getElementById("close_transfer_details").click(); } HidePageLoader(); } }); } }); } function deleteTransfer(user_id, transfer_id) { Swal.fire({ title: "Confermi eliminazione?", text: "La trasferta 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/transfers/delete_transfer.php", data: { transfer_id: transfer_id }, success: function (res) { if (res === 'error') { ErrorAlert("Errore: "+res) } else { SuccessAlert('Trasferta eliminata'); TransfersListUser(user_id); loadUserCalendar(user_id); document.getElementById("close_transfer_details").click(); } HidePageLoader(); } }); } }); } function editTransfer(user_id, transfer_id) { document.getElementById("open_transfer_details").click(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#transfer_details_content").innerHTML = this.responseText; } }; xmlhttp.open("GET", "public/transfers/transfer_details_content.php?transfer_id="+transfer_id+"&user_id="+user_id); xmlhttp.send(); } function updateTransfer(user_id, transfer_id) { ShowPageLoader(); var transfer_start_date = document.getElementById("transfer_start_date").value; var transfer_end_date = document.getElementById("transfer_end_date").value; var transfer_location = document.getElementById("transfer_location").value; var transfer_destination = document.getElementById("transfer_destination").value; $.ajax({ type: "POST", url: "php/transfers/update_transfer.php", data: { transfer_id: transfer_id, transfer_start_date: transfer_start_date, transfer_end_date: transfer_end_date, transfer_location: transfer_location, transfer_destination: transfer_destination }, success: function (res) { if (res === 'error') { ErrorAlert("Errore: "+res); } else { SuccessAlert('Trasferta modificata'); TransfersListUser(user_id); loadUserCalendar(user_id); document.getElementById("close_transfer_details").click(); } HidePageLoader(); } }); } function UserCalendar(user_id) { document.getElementById("open_user_calendar").click(); ShowPageLoader(); setTimeout(() => { loadUserCalendar(user_id); HidePageLoader(); }, 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, firstDay: 1, customButtons: { myCustomButton: { text: 'Nuova trasferta', click: function() { NewTransfer(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/transfers/get_calendar_transfers.php?user_id="+user_id, eventDisplay: 'block', /* eventColor: '#378006', */ displayEventTime: true, eventTimeFormat: { hour: '2-digit', minute: '2-digit', hour12: false }, selectable: true, select: function (info) { document.getElementById("open_new_transfer").click(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#new_transfer_content").innerHTML = this.responseText; } }; xmlhttp.open("GET", "public/transfers/new_transfer_content.php?user_id="+user_id+"&startDate="+info.startStr+"&endDate="+info.endStr); xmlhttp.send(); }, eventClick: function (info) { if(info.event.id < 9000000) { document.getElementById("open_transfer_details").click(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#transfer_details_content").innerHTML = this.responseText; } }; xmlhttp.open("GET", "public/transfers/transfer_details_content.php?transfer_id="+info.event.id+"&user_id="+user_id); xmlhttp.send(); } } }); calendar.render(); } }; xmlhttp.open("GET", "public/transfers/transfers_calendar_content.php?user_id="+user_id); xmlhttp.send(); }