synonim pages and new dump
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
include('../include/headscript.php');
|
||||
|
||||
if (isset($_POST['user']) && isset($_POST['table'])) {
|
||||
$userId = $_POST['user'];
|
||||
$page = 'reports';
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Query per cercare le impostazioni salvate
|
||||
$query = "SELECT * FROM user_table_settings WHERE iduser = ? AND page = ?";
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->bind_param("is", $userId, $page);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
// Se esistono, restituisci le impostazioni esistenti
|
||||
$row = $result->fetch_assoc();
|
||||
$settings = [
|
||||
'columns' => json_decode($row['column_visibility'], true),
|
||||
'ColReorder' => json_decode($row['column_order'], true),
|
||||
'time' => time()
|
||||
];
|
||||
|
||||
echo json_encode($settings);
|
||||
} else {
|
||||
// Se non esistono, inserisci un record di default
|
||||
$defaultColumnVisibility = json_encode([true, true, true, true, true, true]); // Adatta le colonne al numero di colonne della tua tabella
|
||||
$defaultColumnOrder = json_encode([0, 1, 2, 3, 4, 5]); // Ordine predefinito delle colonne
|
||||
|
||||
$insertQuery = "INSERT INTO user_table_settings (iduser, page, column_visibility, column_order, created_at, updated_at) VALUES (?, ?, ?, ?, NOW(), NOW())";
|
||||
$insertStmt = $conn->prepare($insertQuery);
|
||||
$insertStmt->bind_param("isss", $userId, $page, $defaultColumnVisibility, $defaultColumnOrder);
|
||||
|
||||
if ($insertStmt->execute()) {
|
||||
// Restituisci le impostazioni predefinite appena create
|
||||
$settings = [
|
||||
'columns' => json_decode($defaultColumnVisibility, true),
|
||||
'ColReorder' => json_decode($defaultColumnOrder, true),
|
||||
'time' => time()
|
||||
];
|
||||
|
||||
echo json_encode($settings);
|
||||
} else {
|
||||
// Gestisci eventuali errori nell'inserimento
|
||||
echo json_encode(['error' => 'Failed to insert default settings']);
|
||||
}
|
||||
|
||||
$insertStmt->close();
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
} else {
|
||||
echo json_encode(['error' => 'Invalid request']);
|
||||
}
|
||||
@@ -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>
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// Connessione al database
|
||||
include('../include/headscript.php');
|
||||
$tableName = 'reports'; // Nome tabella per reports.php
|
||||
|
||||
// Verifica che i parametri necessari siano stati inviati
|
||||
if (isset($_POST['user']) && isset($_POST['table']) && isset($_POST['settings'])) {
|
||||
$userId = $_POST['user'];
|
||||
$page = $tableName;
|
||||
$settings = json_decode($_POST['settings'], true);
|
||||
|
||||
$columnVisibility = json_encode(array_column($settings['columns'], 'visible'));
|
||||
$columnOrder = json_encode($settings['ColReorder']);
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
// Verifica della connessione
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Query per verificare se il record esiste già
|
||||
$query = "SELECT * FROM user_table_settings WHERE iduser = ? AND page = ?";
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->bind_param("is", $userId, $page);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
// Aggiorna le impostazioni esistenti
|
||||
$updateQuery = "UPDATE user_table_settings SET column_visibility = ?, column_order = ?, updated_at = NOW() WHERE iduser = ? AND page = ?";
|
||||
$updateStmt = $conn->prepare($updateQuery);
|
||||
$updateStmt->bind_param("ssis", $columnVisibility, $columnOrder, $userId, $page);
|
||||
$updateStmt->execute();
|
||||
$updateStmt->close();
|
||||
echo json_encode(['status' => 'Settings updated']);
|
||||
} else {
|
||||
// Inserisci nuove impostazioni
|
||||
$insertQuery = "INSERT INTO user_table_settings (iduser, page, column_visibility, column_order, created_at, updated_at) VALUES (?, ?, ?, ?, NOW(), NOW())";
|
||||
$insertStmt = $conn->prepare($insertQuery);
|
||||
$insertStmt->bind_param("isss", $userId, $page, $columnVisibility, $columnOrder);
|
||||
$insertStmt->execute();
|
||||
$insertStmt->close();
|
||||
echo json_encode(['status' => 'Settings saved']);
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
} else {
|
||||
// Se i parametri non sono validi, restituisci errore
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'Invalid request']);
|
||||
}
|
||||
Reference in New Issue
Block a user