synonim pages and new dump
This commit is contained in:
@@ -3,6 +3,18 @@
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
$page = 'reports'; // Nome della pagina specifica per salvare/ripristinare le impostazioni
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
// Recupera le impostazioni delle colonne e dell'ordinamento dal database
|
||||
$query = "SELECT column_visibility, column_order FROM user_table_settings WHERE iduser = ? AND page = ?";
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->bind_param("is", $iduserlogin, $page);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($column_visibility, $column_order);
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
// Query per ottenere tutti i report e i prodotti associati
|
||||
$query = "
|
||||
SELECT r.*, p.products_refnumber, p.products_description
|
||||
@@ -20,14 +32,26 @@ $result = $conn->query($query);
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
|
||||
<title>Reports</title>
|
||||
|
||||
<!-- Includi prima jQuery -->
|
||||
<!-- Includi prima jQuery -->
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
|
||||
<!-- Includi DataTables CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.min.css">
|
||||
<!-- DataTables CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.1/css/jquery.dataTables.min.css">
|
||||
<!-- DataTables Buttons CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.3.1/css/buttons.dataTables.min.css">
|
||||
<!-- ColReorder CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/colreorder/1.5.6/css/colReorder.dataTables.min.css">
|
||||
|
||||
<!-- DataTables JS -->
|
||||
<script src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js"></script>
|
||||
<!-- DataTables Buttons JS -->
|
||||
<script src="https://cdn.datatables.net/buttons/2.3.1/js/dataTables.buttons.min.js"></script>
|
||||
<!-- Buttons ColVis JS -->
|
||||
<script src="https://cdn.datatables.net/buttons/2.3.1/js/buttons.colVis.min.js"></script>
|
||||
<!-- ColReorder JS -->
|
||||
<script src="https://cdn.datatables.net/colreorder/1.5.6/js/dataTables.colReorder.min.js"></script>
|
||||
|
||||
<!-- Includi DataTables JS -->
|
||||
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
|
||||
|
||||
<!-- Altri riferimenti al CSS e JS -->
|
||||
<link href="../assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
|
||||
@@ -87,7 +111,7 @@ $result = $conn->query($query);
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table id="reportsTable" class="table table-striped table-hover">
|
||||
<table id="reportsTable" class="table table-striped table-hover" data-user="<?php echo $iduserlogin; ?>" data-table="reports">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Report Number</th>
|
||||
@@ -115,6 +139,7 @@ $result = $conn->query($query);
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -129,56 +154,133 @@ $result = $conn->query($query);
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Inizializza DataTables con filtri per le colonne
|
||||
var table = $('#reportsTable').DataTable({
|
||||
responsive: true,
|
||||
"pageLength": 50,
|
||||
"order": [
|
||||
[0, 'asc']
|
||||
], // Ordina per numero di report
|
||||
initComplete: function() {
|
||||
// Aggiungi i filtri per ogni colonna
|
||||
this.api().columns().every(function() {
|
||||
var column = this;
|
||||
var input = $('<input class="form-control form-control-sm" type="text" placeholder="Search"/>')
|
||||
.appendTo($(column.header()))
|
||||
.on('keyup change clear', function() {
|
||||
if (column.search() !== this.value) {
|
||||
column.search(this.value).draw();
|
||||
}
|
||||
});
|
||||
});
|
||||
var hasUserInteracted = false;
|
||||
|
||||
// Recupera le impostazioni salvate dal server prima di inizializzare DataTables
|
||||
var columnSettings = {};
|
||||
var userId = $('#reportsTable').data('user');
|
||||
var tableName = $('#reportsTable').data('table');
|
||||
|
||||
// Recupera le impostazioni salvate
|
||||
$.ajax({
|
||||
url: 'get_user_table_settings_reports.php',
|
||||
method: 'POST',
|
||||
data: {
|
||||
user: userId,
|
||||
table: tableName
|
||||
},
|
||||
async: false,
|
||||
success: function(response) {
|
||||
columnSettings = JSON.parse(response);
|
||||
console.log("Impostazioni recuperate:", columnSettings);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Errore nel caricamento delle impostazioni:', xhr.responseText);
|
||||
}
|
||||
});
|
||||
|
||||
// Gestione del click su "Analysis" per visualizzare la tabella delle analisi
|
||||
// Inizializza DataTables con ColReorder, filtri e ColVis
|
||||
var table = $('#reportsTable').DataTable({
|
||||
responsive: true,
|
||||
pageLength: 50,
|
||||
order: [
|
||||
[0, 'asc']
|
||||
],
|
||||
colReorder: {
|
||||
order: columnSettings && columnSettings.ColReorder ? columnSettings.ColReorder : null
|
||||
},
|
||||
dom: 'Bfrtip', // Integra i bottoni
|
||||
buttons: [{
|
||||
extend: 'colvis',
|
||||
text: 'Select Columns',
|
||||
collectionLayout: 'fixed four-column',
|
||||
postfixButtons: ['colvisRestore'],
|
||||
columns: ':not(:last-child)' // Escludi l'ultima colonna (Actions)
|
||||
}],
|
||||
initComplete: function() {
|
||||
// Applica le impostazioni di visibilità delle colonne, se presenti
|
||||
if (columnSettings && columnSettings.columns) {
|
||||
console.log("Applico visibilità colonne:", columnSettings.columns);
|
||||
this.api().columns().every(function(index) {
|
||||
var column = this;
|
||||
column.visible(columnSettings.columns[index].visible, false);
|
||||
});
|
||||
}
|
||||
|
||||
this.api().columns.adjust().draw(false);
|
||||
|
||||
// Aggiungi i filtri per ogni colonna (eccetto la colonna delle azioni)
|
||||
this.api().columns().every(function() {
|
||||
var column = this;
|
||||
if (column.index() !== 5) { // Escludi la colonna "Action"
|
||||
$('<input class="form-control form-control-sm" type="text" placeholder="Search"/>')
|
||||
.appendTo($(column.header()))
|
||||
.on('keyup change clear', function() {
|
||||
if (column.search() !== this.value) {
|
||||
column.search(this.value).draw();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
stateSave: true,
|
||||
stateSaveCallback: function(settings, data) {
|
||||
if (hasUserInteracted) {
|
||||
$.ajax({
|
||||
url: 'save_user_table_settings_reports.php',
|
||||
method: 'POST',
|
||||
data: {
|
||||
user: userId,
|
||||
table: tableName,
|
||||
settings: JSON.stringify(data)
|
||||
},
|
||||
success: function(response) {
|
||||
console.log('Impostazioni salvate:', response);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Errore nel salvataggio delle impostazioni:', xhr.responseText);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Imposta il flag `hasUserInteracted` quando l'utente modifica qualcosa (colonne o riordina)
|
||||
table.on('column-reorder', function() {
|
||||
hasUserInteracted = true;
|
||||
console.log("Colonne riordinate");
|
||||
});
|
||||
|
||||
table.on('column-visibility', function() {
|
||||
hasUserInteracted = true;
|
||||
console.log("Visibilità colonna cambiata");
|
||||
});
|
||||
|
||||
// Gestione del click su "Analysis" per visualizzare la tabella child con le analisi
|
||||
$('#reportsTable').on('click', '.show-analysis', function() {
|
||||
var tr = $(this).closest('tr');
|
||||
var reportId = tr.data('reportid');
|
||||
var row = $('#reportsTable').DataTable().row(tr);
|
||||
var button = $(this);
|
||||
|
||||
console.log('Loading analysis for reportId:', reportId); // Debug
|
||||
|
||||
button.prop('disabled', true);
|
||||
button.html('<i class="fa fa-spinner fa-spin"></i> Loading...');
|
||||
|
||||
// Se la riga child è già visibile, non facciamo nulla
|
||||
if (row.child.isShown()) {
|
||||
button.prop('disabled', false);
|
||||
row.child.hide();
|
||||
tr.removeClass('shown');
|
||||
button.html('Analysis');
|
||||
button.prop('disabled', false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Carica le analisi tramite AJAX
|
||||
$.ajax({
|
||||
url: 'get_analysis_by_report.php', // Nuovo script PHP per ottenere le analisi del report
|
||||
url: 'get_analysis_by_report.php',
|
||||
type: 'POST',
|
||||
data: {
|
||||
reportId: reportId
|
||||
},
|
||||
success: function(data) {
|
||||
console.log('Analysis data loaded:', data); // Debug
|
||||
row.child(formatAnalysis(data)).show();
|
||||
tr.addClass('shown');
|
||||
},
|
||||
@@ -194,22 +296,20 @@ $result = $conn->query($query);
|
||||
});
|
||||
});
|
||||
|
||||
// Funzione per formattare le analisi
|
||||
function formatAnalysis(data) {
|
||||
var parsedData = JSON.parse(data);
|
||||
var html = '<table class="table table-bordered child-table">';
|
||||
html += '<thead><tr><th>Analysis Name</th><th>Final Rating</th></tr></thead>';
|
||||
html += '<tbody>';
|
||||
|
||||
// Per ogni analisi, aggiungi la riga corrispondente
|
||||
$.each(parsedData, function(index, analysis) {
|
||||
var ratingClass = ''; // Classe CSS per la colorazione della cella
|
||||
var ratingClass = '';
|
||||
if (analysis.finalRating === 'FAIL') {
|
||||
ratingClass = 'bg-danger text-white'; // Colore rosso per i fallimenti
|
||||
ratingClass = 'bg-danger text-white';
|
||||
} else if (analysis.finalRating === 'PASS') {
|
||||
ratingClass = 'bg-success text-white'; // Colore verde per i successi
|
||||
ratingClass = 'bg-success text-white';
|
||||
} else if (analysis.finalRating === '//' || analysis.finalRating === 'N/A') {
|
||||
ratingClass = 'bg-warning text-dark'; // Colore giallo per risultati ambigui
|
||||
ratingClass = 'bg-warning text-dark';
|
||||
}
|
||||
|
||||
html += '<tr>';
|
||||
@@ -221,10 +321,12 @@ $result = $conn->query($query);
|
||||
html += '</tbody></table>';
|
||||
return html;
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user