update entra id

This commit is contained in:
2025-05-13 15:03:09 +02:00
parent 6752d3515f
commit 2a96d24de7
44 changed files with 3835 additions and 1856 deletions
+5
View File
@@ -0,0 +1,5 @@
<link href="../assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="../assets/css/icons.css" rel="stylesheet" type="text/css">
<link href="../assets/css/style.css" rel="stylesheet" type="text/css">
<link href="https://cdn.jsdelivr.net/npm/boxicons@2.0.7/css/boxicons.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.css">
+85 -106
View File
@@ -3,27 +3,44 @@ ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include('../include/headscript.php'); ?>
<?php include("../class/company.php");
include('../include/headscript.php');
include("../class/company.php");
require_once '../class/db-functions.php'; // Includo DBHandlerSelect
$page = 'products.php';
$conn = new mysqli($servername, $username, $password, $database);
// Inizializzo la connessione con DBHandlerSelect
$dbHandler = new DBHandlerSelect();
$pdo = $dbHandler->getConnection();
// Validazione iduserlogin
if (!isset($iduserlogin) || !is_numeric($iduserlogin)) {
die("Errore: ID utente non valido.");
}
// 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();
?>
try {
$query = "SELECT column_visibility, column_order FROM user_table_settings WHERE iduser = :iduser AND page = :page";
$stmt = $pdo->prepare($query);
$stmt->execute(['iduser' => $iduserlogin, 'page' => $page]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$column_visibility = $row['column_visibility'] ?? null;
$column_order = $row['column_order'] ?? null;
} catch (PDOException $e) {
error_log("Errore query user_table_settings: " . $e->getMessage());
die("Errore nel caricamento delle impostazioni.");
}
<?php
$conn = new mysqli($servername, $username, $password, $database);
// Query per ottenere tutti i prodotti
$query = "SELECT * FROM products";
$result = $conn->query($query);
// Query per ottenere i prodotti con colonne specifiche
try {
// Rimossa la condizione WHERE iduser per compatibilità (potrebbe non esserci il campo iduser nella tabella products)
$query = "SELECT idproducts, products_refnumber, products_description, products_style, products_color, products_season, products_market, products_sku, products_order, product_buyer, products_fibercontentresult, namesupplier, iddepartment, dateprod, dateinlab, dateoutlab, labservice, agerange, products_division, products_phase FROM products";
$stmt = $pdo->prepare($query);
$stmt->execute();
} catch (PDOException $e) {
error_log("Errore query products: " . $e->getMessage());
die("Errore nel caricamento dei prodotti: " . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8'));
}
?>
<!DOCTYPE html>
@@ -45,7 +62,6 @@ $result = $conn->query($query);
<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 -->
@@ -54,15 +70,8 @@ $result = $conn->query($query);
<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>
<!-- Altri riferimenti al CSS e JS -->
<link href="../assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="../assets/css/icons.css" rel="stylesheet" type="text/css">
<link href="../assets/css/style.css" rel="stylesheet" type="text/css">
<link href="https://cdn.jsdelivr.net/npm/boxicons@2.0.7/css/boxicons.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.css">
<?php include('cssinclude.php'); ?>
</head>
<style>
@@ -111,22 +120,18 @@ $result = $conn->query($query);
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">
<div id="wrapper">
<?php include('../include/navigationbar.php'); ?>
<div class="content-page">
@@ -134,7 +139,6 @@ $result = $conn->query($query);
<?php include('../include/topbar.php'); ?>
<div class="page-content-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div class="page-title-box">
@@ -142,7 +146,6 @@ $result = $conn->query($query);
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<div class="card">
@@ -174,27 +177,27 @@ $result = $conn->query($query);
</tr>
</thead>
<tbody>
<?php while ($row = $result->fetch_assoc()) { ?>
<tr data-productid="<?php echo $row['idproducts']; ?>">
<td><?php echo $row['products_refnumber']; ?></td>
<td><?php echo $row['products_description']; ?></td>
<td><?php echo $row['products_style']; ?></td>
<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>
<?php while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { ?>
<tr data-productid="<?php echo htmlspecialchars($row['idproducts'], ENT_QUOTES, 'UTF-8'); ?>">
<td><?php echo htmlspecialchars($row['products_refnumber'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['products_description'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['products_style'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['products_color'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['products_season'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['products_market'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['products_sku'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['products_order'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['product_buyer'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['products_fibercontentresult'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['namesupplier'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['iddepartment'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['dateprod'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['dateinlab'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['dateoutlab'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['labservice'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['agerange'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['products_division'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($row['products_phase'] ?? '', ENT_QUOTES, 'UTF-8'); ?></td>
<td>
<button class="btn btn-info btn-sm show-reports">Reports</button>
</td>
@@ -207,31 +210,27 @@ $result = $conn->query($query);
</div>
</div>
</div>
</div><!-- container -->
</div><!-- Page content Wrapper -->
</div><!-- content -->
</div>
</div>
</div>
<?php include('../include/footer.php'); ?>
</div>
</div>
<script>
$(document).ready(function() {
var hasUserInteracted = false; // Flag per tracciare l'interazione dell'utente
var hasUserInteracted = false;
// Carica le impostazioni salvate dal server prima di inizializzare DataTables
var stateLoaded = false;
var columnSettings = {}; // Variabile per memorizzare le impostazioni della tabella
var columnSettings = {};
// Recupera le impostazioni salvate dal server
$.ajax({
url: 'get_user_table_settings.php', // PHP che recupera i settaggi
url: 'get_user_table_settings.php',
method: 'POST',
data: {
user: "<?php echo $iduserlogin; ?>", // ID utente
table: 'products' // Nome della tabella
user: "<?php echo htmlspecialchars($iduserlogin, ENT_QUOTES, 'UTF-8'); ?>",
table: 'products'
},
async: false, // Carica in modo sincrono per garantire che le impostazioni siano pronte prima di DataTables
async: false,
success: function(response) {
columnSettings = JSON.parse(response);
console.log("Impostazioni recuperate:", columnSettings);
@@ -241,42 +240,36 @@ $result = $conn->query($query);
}
});
// Inizializza DataTables con ColReorder, filtri e ColVis
var table = $('#productsTable').DataTable({
responsive: true,
pageLength: 50,
order: [
[1, 'asc']
], // Ordina per descrizione
],
colReorder: {
order: columnSettings && columnSettings.ColReorder ? columnSettings.ColReorder : null // Usa le impostazioni di ColReorder se presenti
order: columnSettings && columnSettings.ColReorder ? columnSettings.ColReorder : null
},
dom: 'Bfrtip', // Integra i bottoni
dom: 'Bfrtip',
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)
extend: 'colvis',
collectionLayout: 'fixed four-column',
text: 'Select Columns',
postfixButtons: ['colvisRestore'],
columns: ':not(:last-child)'
}],
initComplete: function() {
console.log("DataTables initComplete");
// Se sono state caricate impostazioni di visibilità delle colonne, applicale
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); // Non ridisegnare ogni volta
column.visible(columnSettings.columns[index].visible, false);
});
}
this.api().columns.adjust().draw(false); // Ridisegna la tabella alla fine
// Aggiungi i filtri per ogni colonna (eccetto la colonna delle azioni)
this.api().columns.adjust().draw(false);
this.api().columns().every(function() {
var column = this;
if (column.index() !== 6) { // Escludi la colonna "Action"
if (column.index() !== 19) {
var input = $('<input class="form-control form-control-sm" type="text" placeholder="Search"/>')
.appendTo($(column.header()))
.on('keyup change clear', function() {
@@ -290,16 +283,14 @@ $result = $conn->query($query);
stateSave: true,
stateSaveCallback: function(settings, data) {
console.log("Salvataggio stato tabella");
// Salva le impostazioni sul server solo se l'utente ha interagito
if (hasUserInteracted) {
$.ajax({
url: 'save_user_table_settings.php', // PHP che salva i settaggi
url: 'save_user_table_settings.php',
method: 'POST',
data: {
user: "<?php echo $iduserlogin; ?>", // ID utente
table: 'products', // Nome della tabella
settings: JSON.stringify(data) // Impostazioni della tabella
user: "<?php echo htmlspecialchars($iduserlogin, ENT_QUOTES, 'UTF-8'); ?>",
table: 'products',
settings: JSON.stringify(data)
},
success: function(response) {
console.log('Impostazioni salvate:', response);
@@ -312,7 +303,6 @@ $result = $conn->query($query);
}
});
// Imposta il flag `hasUserInteracted` quando l'utente modifica qualcosa (colonne o riordina)
table.on('column-reorder', function() {
hasUserInteracted = true;
console.log("Colonne riordinate");
@@ -323,7 +313,6 @@ $result = $conn->query($query);
console.log("Visibilità colonna cambiata");
});
// 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');
@@ -333,7 +322,6 @@ $result = $conn->query($query);
button.prop('disabled', true);
button.html('<i class="fa fa-spinner fa-spin"></i> Loading...');
// Se la riga child è già visibile, nascondila
if (row.child.isShown()) {
row.child.hide();
tr.removeClass('shown');
@@ -342,7 +330,6 @@ $result = $conn->query($query);
return;
}
// Carica i report e le analisi tramite AJAX
$.ajax({
url: 'get_reports_and_analysis.php',
type: 'POST',
@@ -357,15 +344,14 @@ $result = $conn->query($query);
button.prop('disabled', false);
button.html('Reports');
},
error: function() {
Swal.fire('Error!', 'There was an error loading the reports and analysis.', 'error');
error: function(xhr) {
Swal.fire('Errore!', xhr.status === 404 ? 'Risorsa non trovata.' : 'Errore nel caricamento dei report.', 'error');
button.prop('disabled', false);
button.html('Reports');
}
});
});
// Funzione per formattare i report e le analisi nella stessa tabella
function formatReportsAndAnalysis(data) {
var parsedData = JSON.parse(data);
var reports = parsedData.reports;
@@ -374,10 +360,8 @@ $result = $conn->query($query);
html += '<tbody>';
$.each(reports, function(index, report) {
// Definisci la classe di stile per il rating del report
var ratingClass = '';
var ratingValue = report.reportsRating.toLowerCase(); // Converte il valore in minuscolo
var ratingValue = report.reportsRating.toLowerCase();
if (ratingValue === 'fail') {
ratingClass = 'bg-danger text-white';
} else if (ratingValue === 'pass') {
@@ -389,12 +373,11 @@ $result = $conn->query($query);
html += '<tr>';
html += '<td>' + report.reportsNumberLab + '</td>';
html += '<td>' + report.reportDateIn + '</td>';
html += '<td class="' + ratingClass + '">' + report.reportsRating + '</td>'; // Applica la classe alla cella
html += '<td colspan="2"></td>'; // Righe vuote per mantenere l'allineamento
html += '<td class="' + ratingClass + '">' + report.reportsRating + '</td>';
html += '<td colspan="2"></td>';
html += '<td><button class="btn btn-primary btn-sm report-details" data-reportid="' + report.idreports + '">Details</button></td>';
html += '</tr>';
// Se ci sono analisi associate, aggiungi le righe per ciascuna analisi
if (report.analysis.length > 0) {
$.each(report.analysis, function(i, analysis) {
var ratingClass = '';
@@ -420,20 +403,16 @@ $result = $conn->query($query);
}
});
html += '</tbody></table>';
return html;
}
// 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>