added column selection and reorder in products

This commit is contained in:
2024-10-01 09:31:33 +02:00
parent 6e97456cf4
commit 9f63e362f2
6 changed files with 1218 additions and 309 deletions
@@ -0,0 +1,48 @@
<?php
// Connessione al database
include('../include/headscript.php');
$tableName = 'products'; // Per la pagina products.php
// Verifica che i parametri necessari siano stati inviati
if (isset($_POST['user']) && isset($_POST['table'])) {
$userId = $_POST['user'];
$tablen = $tableName;
$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
$query = "SELECT * FROM user_table_settings WHERE iduser = ? AND page = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("is", $userId, $tablen);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
// Restituisci i dati esistenti
$row = $result->fetch_assoc();
echo json_encode([
'column_visibility' => $row['column_visibility'],
'column_order' => $row['column_order']
]);
} else {
// Crea un record di default se non esiste
$defaultVisibility = json_encode([/* Impostazioni di visibilità predefinite */]);
$defaultOrder = json_encode([/* Ordine delle colonne predefinito */]);
$insertQuery = "INSERT INTO user_table_settings (iduser, page, column_visibility, column_order, created_at) VALUES (?, ?, ?, ?, NOW())";
$insertStmt = $conn->prepare($insertQuery);
$insertStmt->bind_param("isss", $userId, $tablen, $defaultVisibility, $defaultOrder);
$insertStmt->execute();
// Restituisci le impostazioni predefinite
echo json_encode([
'column_visibility' => $defaultVisibility,
'column_order' => $defaultOrder
]);
}
}
+188 -46
View File
@@ -1,5 +1,22 @@
<?php include('../include/headscript.php'); ?>
<?php include("../class/company.php"); ?>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include('../include/headscript.php'); ?>
<?php include("../class/company.php");
$page = 'products.php';
$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();
?>
<?php
$conn = new mysqli($servername, $username, $password, $database);
@@ -21,11 +38,22 @@ $result = $conn->query($query);
<!-- 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">
<link rel="stylesheet" type="text/css" 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>
<script type="text/javascript" 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">
@@ -59,6 +87,41 @@ $result = $conn->query($query);
.text-dark {
color: black !important;
}
.custom-colvis-btn .dt-button {
background-color: #f8f9fa !important;
/* Colore di sfondo chiaro per i pulsanti */
color: #343a40 !important;
/* Testo scuro per il contrasto */
border: 1px solid #ced4da !important;
/* Bordo leggero */
}
.custom-colvis-btn .dt-button.active {
background-color: #007bff !important;
/* Colore di sfondo attivo (blu) */
color: white !important;
/* Testo bianco per il contrasto */
}
.custom-colvis-btn .dt-button:hover {
background-color: #0056b3 !important;
/* Colore al passaggio del mouse (blu più scuro) */
color: white !important;
}
/* Forza il contrasto per i pulsanti del selettore */
.dt-button-collection button.active {
background-color: #007bff !important;
/* Colore per il bottone selezionato */
color: #007bff !important;
}
.dt-button-collection button {
background-color: #f8f9fa !important;
/* Colore per i bottoni non attivi */
color: #000 !important;
}
</style>
<body class="fixed-left">
@@ -93,6 +156,19 @@ $result = $conn->query($query);
<th>Color</th>
<th>Season</th>
<th>Market</th>
<th>SKU</th>
<th>Order</th>
<th>Buyer</th>
<th>Fiber Content Result</th>
<th>Supplier</th>
<th>Department</th>
<th>Production Date</th>
<th>Date In Lab</th>
<th>Date Out Lab</th>
<th>Lab Service</th>
<th>Age Range</th>
<th>Division</th>
<th>Phase</th>
<th>Action</th>
</tr>
</thead>
@@ -105,6 +181,19 @@ $result = $conn->query($query);
<td><?php echo $row['products_color']; ?></td>
<td><?php echo $row['products_season']; ?></td>
<td><?php echo $row['products_market']; ?></td>
<td><?php echo $row['products_sku']; ?></td>
<td><?php echo $row['products_order']; ?></td>
<td><?php echo $row['product_buyer']; ?></td>
<td><?php echo $row['products_fibercontentresult']; ?></td>
<td><?php echo $row['namesupplier']; ?></td>
<td><?php echo $row['iddepartment']; ?></td>
<td><?php echo $row['dateprod']; ?></td>
<td><?php echo $row['dateinlab']; ?></td>
<td><?php echo $row['dateoutlab']; ?></td>
<td><?php echo $row['labservice']; ?></td>
<td><?php echo $row['agerange']; ?></td>
<td><?php echo $row['products_division']; ?></td>
<td><?php echo $row['products_phase']; ?></td>
<td>
<button class="btn btn-info btn-sm show-reports">Reports</button>
</td>
@@ -118,65 +207,115 @@ $result = $conn->query($query);
</div>
</div>
</div><!-- container -->
</div><!-- Page content Wrapper -->
</div><!-- content -->
<?php include('../include/footer.php'); ?>
</div>
</div>
<script>
$(document).ready(function() {
// Inizializza DataTables con filtri per le colonne
// Inizializza DataTables con ColReorder, filtri e ColVis
var table = $('#productsTable').DataTable({
responsive: true,
"pageLength": 50,
"order": [
pageLength: 50,
order: [
[1, 'asc']
], // Ordina per descrizione
colReorder: true, // Abilita il riordinamento delle colonne
dom: 'Bfrtip', // Integra i bottoni
buttons: [{
extend: 'colvis', // ColVis per mostrare/nascondere colonne
collectionLayout: 'fixed four-column', // Layout del dropdown
text: 'Select Columns', // Testo del bottone dropdown
postfixButtons: ['colvisRestore'], // Pulsante per ripristinare la configurazione iniziale
columns: ':not(:last-child)' // Non nascondere l'ultima colonna (Actions)
}],
initComplete: function() {
// Aggiungi i filtri per ogni colonna
// Aggiungi i filtri per ogni colonna (eccetto la colonna delle azioni)
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();
}
});
if (column.index() !== 6) { // Escludi la colonna "Action"
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();
}
});
}
});
},
// Recupera le impostazioni salvate dal server
stateSave: true,
stateSaveCallback: function(settings, data) {
// Salva le impostazioni sul server tramite AJAX
$.ajax({
url: 'save_user_table_settings.php', // PHP che salva i settaggi
method: 'POST',
data: {
user: "<?php echo $iduserlogin; ?>", // ID utente
table: 'products', // Nome della tabella
settings: JSON.stringify(data) // Impostazioni della tabella
},
success: function(response) {
console.log('Settings saved:', response);
},
error: function(xhr, status, error) {
console.error('Error saving settings:', xhr.responseText);
}
});
},
stateLoadCallback: function(settings) {
var o;
// Carica le impostazioni salvate dal server tramite AJAX
$.ajax({
url: 'get_user_table_settings.php', // PHP che recupera i settaggi
method: 'POST',
data: {
user: "<?php echo $iduserlogin; ?>", // ID utente
table: 'products' // Nome della tabella
},
async: false,
success: function(response) {
o = JSON.parse(response);
},
error: function(xhr, status, error) {
console.error('Error loading settings:', xhr.responseText);
}
});
return o;
}
});
// Gestione del click su "Reports" per visualizzare la tabella report e analisi
// Gestione del click su "Reports" per visualizzare la tabella child con i report e le analisi
$('#productsTable').on('click', '.show-reports', function() {
var tr = $(this).closest('tr');
var productId = tr.data('productid');
var row = $('#productsTable').DataTable().row(tr);
var button = $(this);
console.log('Loading reports and analysis for productId:', productId); // 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
// Se la riga child è già visibile, nascondila
if (row.child.isShown()) {
button.prop('disabled', false);
row.child.hide();
tr.removeClass('shown');
button.html('Reports');
button.prop('disabled', false);
return;
}
// Carica i report e le analisi insieme tramite AJAX
// Carica i report e le analisi tramite AJAX
$.ajax({
url: 'get_reports_and_analysis.php', // Nuovo script PHP per ottenere sia i report che le analisi
url: 'get_reports_and_analysis.php',
type: 'POST',
data: {
productId: productId
},
success: function(data) {
console.log('Reports and Analysis data loaded:', data); // Debug
row.child(formatReportsAndAnalysis(data)).show();
tr.addClass('shown');
},
@@ -200,35 +339,33 @@ $result = $conn->query($query);
html += '<thead><tr><th>Report Number</th><th>Report Date</th><th>Rating</th><th>Analysis (Name)</th><th>Final Rating</th><th>Action</th></tr></thead>';
html += '<tbody>';
// Per ogni report, aggiungi il report e le analisi associate
$.each(reports, function(index, report) {
// Riga del report principale
html += '<tr>';
html += '<td>' + report.reportsNumberLab + '</td>';
html += '<td>' + report.reportDateIn + '</td>';
html += '<td>' + report.reportsRating + '</td>';
html += '<td colspan="2"></td>'; // Righe vuote per mantenere l'allineamento
html += '<td><button class="btn btn-primary btn-sm report-details" data-reportid="' + report.idreports + '">Details</button></td>'; // Aggiungi il bottone Details
html += '<td><button class="btn btn-primary btn-sm report-details" data-reportid="' + report.idreports + '">Details</button></td>';
// Se ci sono analisi associate al report, le aggiungi sotto lo stesso report
// Se ci sono analisi associate, aggiungi le righe per ciascuna analisi
if (report.analysis.length > 0) {
$.each(report.analysis, function(i, 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>';
html += '<td></td>'; // Lascia vuoto per mantenere l'allineamento del report
html += '<td></td>'; // Lascia vuoto per mantenere l'allineamento del report
html += '<td></td>'; // Lascia vuoto per mantenere l'allineamento del report
html += '<td>' + (analysis.name ? analysis.name : 'N/A') + '</td>'; // Nome dell'analisi
html += '<td></td>';
html += '<td></td>';
html += '<td></td>';
html += '<td>' + (analysis.name ? analysis.name : 'N/A') + '</td>';
html += '<td class="' + ratingClass + '">' + (analysis.finalRating ? analysis.finalRating : 'N/A') + '</td>';
html += '<td></td>'; // Lascia vuoto per non aggiungere il bottone "Details" nella riga dell'analisi
html += '<td></td>';
html += '</tr>';
});
} else {
@@ -241,16 +378,21 @@ $result = $conn->query($query);
return html;
}
});
$(document).on('click', '.report-details', function() {
var reportId = $(this).data('reportid'); // Ottieni l'id del report
window.location.href = 'reportdetails.php?idreports=' + reportId; // Reindirizza alla pagina reportdetails.php con idreports
// Funzione per la visualizzazione dei dettagli del report
$(document).on('click', '.report-details', function() {
var reportId = $(this).data('reportid');
window.location.href = 'reportdetails.php?idreports=' + reportId;
});
});
</script>
</body>
</html>
@@ -0,0 +1,40 @@
<?php
// Connessione al database
include('../include/headscript.php');
// Recupera i dati dalla richiesta POST
$iduser = isset($_POST['iduser']) ? $_POST['iduser'] : 0;
$page = isset($_POST['page']) ? $_POST['page'] : '';
$column_visibility = isset($_POST['column_visibility']) ? $_POST['column_visibility'] : '';
$column_order = isset($_POST['column_order']) ? $_POST['column_order'] : '';
if ($iduser && $page && $column_visibility && $column_order) {
// Verifica se esistono già impostazioni per l'utente e la pagina
$stmt = $conn->prepare("SELECT * FROM user_table_settings WHERE iduser = ? AND page_name = ?");
$stmt->bind_param("is", $iduser, $page);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
// Aggiorna le impostazioni esistenti
$stmt = $conn->prepare("UPDATE user_table_settings SET column_visibility = ?, column_order = ? WHERE iduser = ? AND page_name = ?");
$stmt->bind_param("ssis", $column_visibility, $column_order, $iduser, $page);
} else {
// Inserisci nuove impostazioni
$stmt = $conn->prepare("INSERT INTO user_table_settings (iduser, page_name, column_visibility, column_order) VALUES (?, ?, ?, ?)");
$stmt->bind_param("isss", $iduser, $page, $column_visibility, $column_order);
}
if ($stmt->execute()) {
echo json_encode(['success' => true]);
} else {
echo json_encode(['error' => 'Failed to save settings']);
}
} else {
// Se non ci sono dati sufficienti, invia un errore
http_response_code(400);
echo json_encode(['error' => 'Invalid request']);
}
$conn->close();
?>