2025-10-24 21:45:33 +02:00

233 lines
8.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php include('include/headscript.php'); ?>
<!doctype html>
<html lang="it">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
<?php include('cssinclude.php'); ?>
<title>Gestione Matrici - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
<!-- jQuery e Bootstrap -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- DataTables -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css">
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>
<style>
body {
font-size: 1.05rem;
background: #f8fafc;
}
.card {
border-radius: 16px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.back-dashboard {
background-color: #cfe3ff !important;
color: #1f2d3d !important;
border: 1px solid #bcd4f4 !important;
border-radius: 10px;
font-weight: 600;
font-size: 1rem;
padding: 10px 18px;
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
transition: all 0.2s ease-in-out;
}
.back-dashboard:hover {
background-color: #b9d3ff !important;
transform: translateY(-2px);
}
.btn-add {
background-color: #198754;
color: #fff;
border-radius: 8px;
padding: 10px 20px;
font-weight: 500;
transition: all 0.2s ease-in-out;
}
.btn-add:hover {
background-color: #157347;
transform: scale(1.02);
}
.table thead {
background-color: #b9ebc7;
color: #1f2d3d;
}
.modal-content {
border-radius: 16px;
}
.dataTables_filter input {
border-radius: 8px;
padding: 6px 10px;
border: 1px solid #ced4da;
}
.dataTables_wrapper .dataTables_length select {
border-radius: 8px;
padding: 5px;
border: 1px solid #ced4da;
}
</style>
</head>
<body>
<div class="wrapper">
<?php include('include/navbar.php'); ?>
<?php include('include/topbar.php'); ?>
<div class="page-wrapper">
<div class="page-content">
<div class="card p-3">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0">Gestione Matrici</h5>
<button type="button" class="btn back-dashboard" onclick="location.href='production_dashboard.php'">
↩️ Torna alla Dashboard
</button>
</div>
<div class="card-body">
<div class="d-flex justify-content-between align-items-center mb-3">
<h6 class="fw-semibold mb-0">Elenco Completo</h6>
<button class="btn btn-add" data-bs-toggle="modal" data-bs-target="#addMatriceModal"> Aggiungi Matrice</button>
</div>
<!-- TABELLA -->
<div class="table-responsive">
<table id="tabellaMatrici" class="table table-striped align-middle text-center" style="width:100%;">
<thead>
<tr>
<th style="width:80px;">ID</th>
<th>Nome Matrice</th>
</tr>
</thead>
<tbody>
<?php
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
$stmt = $pdo->query("SELECT * FROM matrice ORDER BY id DESC");
if ($stmt->rowCount() === 0) {
echo "<tr><td colspan='2' class='text-muted'>Nessuna matrice presente</td></tr>";
} else {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<tr>
<td>" . htmlspecialchars($row['id']) . "</td>
<td>" . htmlspecialchars($row['nome']) . "</td>
</tr>";
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?php include('include/footer.php'); ?>
</div>
<!-- MODALE AGGIUNTA MATRICE -->
<div class="modal fade" id="addMatriceModal" tabindex="-1" aria-labelledby="addMatriceLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header" style="background-color:#b9ebc7;">
<h5 class="modal-title" id="addMatriceLabel">Aggiungi Nuova Matrice</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Chiudi"></button>
</div>
<div class="modal-body">
<form id="addMatriceForm">
<div class="mb-3">
<label for="nomeMatrice" class="form-label fw-semibold">Nome Matrice</label>
<input type="text" class="form-control" id="nomeMatrice" name="nomeMatrice" required>
</div>
<div class="text-center">
<button type="submit" class="btn btn-add">💾 Salva</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php include('jsinclude.php'); ?>
<script>
// Attiva DataTables
$(document).ready(function() {
$('#tabellaMatrici').DataTable({
order: [
[0, 'desc']
],
pageLength: 25,
language: {
url: 'https://cdn.datatables.net/plug-ins/1.13.6/i18n/it-IT.json'
}
});
});
// Gestione inserimento con AJAX
document.getElementById("addMatriceForm").addEventListener("submit", function(e) {
e.preventDefault();
const nome = document.getElementById("nomeMatrice").value.trim();
if (nome === "") {
Swal.fire({
icon: "warning",
title: "Attenzione",
text: "Inserisci il nome della matrice.",
confirmButtonColor: "#3085d6"
});
return;
}
fetch("save_matrice.php", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: "nome=" + encodeURIComponent(nome)
})
.then(r => r.json())
.then(data => {
if (data.success) {
Swal.fire({
icon: "success",
title: "Salvata!",
text: "La nuova matrice è stata aggiunta correttamente.",
confirmButtonColor: "#3085d6"
}).then(() => location.reload());
} else {
Swal.fire({
icon: "error",
title: "Errore",
text: data.message || "Si è verificato un errore durante il salvataggio.",
confirmButtonColor: "#d33"
});
}
})
.catch(() => {
Swal.fire({
icon: "error",
title: "Errore di connessione",
text: "Impossibile contattare il server.",
confirmButtonColor: "#d33"
});
});
});
</script>
</body>
</html>