added pages

This commit is contained in:
2025-10-27 10:10:09 +01:00
parent 92ec026afe
commit a4b1fb9b1f
16 changed files with 1185 additions and 95 deletions
+235 -66
View File
@@ -9,7 +9,7 @@
<?php include('cssinclude.php'); ?>
<title>Gestione Matrici - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
<!-- jQuery e Bootstrap -->
<!-- jQuery, Bootstrap, SweetAlert -->
<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>
@@ -19,6 +19,11 @@
<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>
<!-- Select2 -->
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.full.min.js"></script>
<style>
body {
font-size: 1.05rem;
@@ -31,9 +36,9 @@
}
.back-dashboard {
background-color: #cfe3ff !important;
background-color: #b9ebc7 !important;
color: #1f2d3d !important;
border: 1px solid #bcd4f4 !important;
border: 1px solid #a1d7b4 !important;
border-radius: 10px;
font-weight: 600;
font-size: 1rem;
@@ -43,7 +48,7 @@
}
.back-dashboard:hover {
background-color: #b9d3ff !important;
background-color: #a1dfb1 !important;
transform: translateY(-2px);
}
@@ -64,23 +69,46 @@
.table thead {
background-color: #b9ebc7;
color: #1f2d3d;
text-align: center;
}
.table tbody td {
vertical-align: middle;
}
.modal-content {
border-radius: 16px;
}
.action-btn {
border: none;
background: none;
cursor: pointer;
font-size: 1.2rem;
margin: 0 4px;
}
.action-btn.edit {
color: #0d6efd;
}
.action-btn.delete {
color: #dc3545;
}
.action-btn.linee {
color: #198754;
}
.action-btn.mescole {
color: #ff9800;
}
.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>
@@ -107,11 +135,12 @@
<!-- TABELLA -->
<div class="table-responsive">
<table id="tabellaMatrici" class="table table-striped align-middle text-center" style="width:100%;">
<table id="tabellaMatrici" class="table table-striped align-middle text-center">
<thead>
<tr>
<th style="width:80px;">ID</th>
<th>ID</th>
<th>Nome Matrice</th>
<th>Azioni</th>
</tr>
</thead>
<tbody>
@@ -120,13 +149,19 @@
$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>";
echo "<tr><td colspan='3' 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>";
<td>{$row['id']}</td>
<td>" . htmlspecialchars($row['nome']) . "</td>
<td>
<button class='action-btn edit' data-id='{$row['id']}' data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'><i class='fa-solid fa-pen-to-square'></i></button>
<button class='action-btn delete' data-id='{$row['id']}'><i class='fa-solid fa-trash'></i></button>
<button class='action-btn linee' data-id='{$row['id']}' data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'><i class='fa-solid fa-sitemap'></i></button>
<button class='action-btn mescole' data-id='{$row['id']}' data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'><i class='fa-solid fa-flask'></i></button>
</td>
</tr>";
}
}
?>
@@ -141,16 +176,17 @@
<?php include('include/footer.php'); ?>
</div>
<!-- MODALE AGGIUNTA MATRICE -->
<!-- MODALE AGGIUNTA / MODIFICA -->
<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>
<h5 class="modal-title" id="addMatriceLabel">Aggiungi / Modifica Matrice</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form id="addMatriceForm">
<input type="hidden" id="idMatriceEdit">
<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>
@@ -163,71 +199,204 @@
</div>
</div>
</div>
<!-- MODALE ASSOCIA LINEE -->
<div class="modal fade" id="associaLineeModal" tabindex="-1" 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">Associa Linee</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form id="associaLineeForm">
<input type="hidden" id="idMatriceLinee">
<div class="mb-3">
<label class="form-label fw-semibold">Linee di Produzione</label>
<select id="lineeSelect" name="linee[]" class="form-select" multiple required style="width:100%;"></select>
</div>
<div class="text-center">
<button type="submit" class="btn btn-add">💾 Salva Associazioni</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- MODALE ASSOCIA MESCOLE -->
<div class="modal fade" id="associaMescoleModal" tabindex="-1" 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">Associa Mescole</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form id="associaMescoleForm">
<input type="hidden" id="idMatriceMescole">
<div class="mb-3">
<label class="form-label fw-semibold">Mescole</label>
<select id="mescoleSelect" name="mescole[]" class="form-select" multiple required style="width:100%;"></select>
</div>
<div class="text-center">
<button type="submit" class="btn btn-add">💾 Salva Associazioni</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php include('jsinclude.php'); ?>
<script>
// Attiva DataTables
$(document).ready(function() {
$('#tabellaMatrici').DataTable({
const table = $('#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();
// === ADD / EDIT MATRICE ===
$(document).on('click', '.edit', function() {
$('#idMatriceEdit').val($(this).data('id'));
$('#nomeMatrice').val($(this).data('nome'));
$('#addMatriceModal').modal('show');
});
if (nome === "") {
Swal.fire({
icon: "warning",
title: "Attenzione",
text: "Inserisci il nome della matrice.",
confirmButtonColor: "#3085d6"
});
return;
}
$('#addMatriceForm').on('submit', function(e) {
e.preventDefault();
const id = $('#idMatriceEdit').val();
const nome = $('#nomeMatrice').val().trim();
if (nome === "") return;
fetch("save_matrice.php", {
method: "POST",
fetch('save_matrice.php', {
method: 'POST',
headers: {
"Content-Type": "application/x-www-form-urlencoded"
'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(() => {
body: 'id=' + id + '&nome=' + encodeURIComponent(nome)
}).then(r => r.json()).then(data => {
Swal.fire({
icon: "error",
title: "Errore di connessione",
text: "Impossibile contattare il server.",
confirmButtonColor: "#d33"
});
icon: data.success ? 'success' : 'error',
title: data.success ? 'Salvata!' : 'Errore',
text: data.message || (data.success ? 'Matrice salvata correttamente.' : 'Errore durante il salvataggio.')
}).then(() => location.reload());
});
});
// === DELETE MATRICE ===
$(document).on('click', '.delete', function() {
const id = $(this).data('id');
Swal.fire({
icon: 'warning',
title: 'Eliminare questa matrice?',
text: 'L\'operazione non è reversibile.',
showCancelButton: true,
confirmButtonText: 'Sì, elimina',
cancelButtonText: 'Annulla',
confirmButtonColor: '#d33'
}).then(res => {
if (res.isConfirmed) {
fetch('delete_matrice.php?id=' + id)
.then(r => r.json())
.then(data => {
Swal.fire({
icon: data.success ? 'success' : 'error',
title: data.success ? 'Eliminata!' : 'Errore',
text: data.message || ''
}).then(() => location.reload());
});
}
});
});
// === ASSOCIA LINEE ===
$(document).on('click', '.linee', function() {
const id = $(this).data('id');
const nome = $(this).data('nome');
$('#idMatriceLinee').val(id);
$('.modal-title').text('Associa Linee a ' + nome);
fetch('get_linee_matrice.php?id=' + id)
.then(r => r.json())
.then(data => {
const sel = $('#lineeSelect');
sel.empty();
data.tutte.forEach(l => {
const selected = data.associate.includes(l.id.toString()) ? 'selected' : '';
sel.append(`<option value="${l.id}" ${selected}>${l.name} (${l.brand || ''})</option>`);
});
sel.select2({
theme: 'bootstrap-5',
width: '100%'
});
$('#associaLineeModal').modal('show');
});
});
$('#associaLineeForm').on('submit', e => {
e.preventDefault();
const id = $('#idMatriceLinee').val();
const linee = $('#lineeSelect').val();
fetch('save_matrice_linee.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id, linee })
}).then(r => r.json()).then(d => {
Swal.fire({
icon: d.success ? 'success' : 'error',
title: d.success ? 'Salvato!' : 'Errore',
text: d.message || ''
}).then(() => location.reload());
});
});
// === ASSOCIA MESCOLE ===
$(document).on('click', '.mescole', function() {
const id = $(this).data('id');
const nome = $(this).data('nome');
$('#idMatriceMescole').val(id);
$('.modal-title').text('Associa Mescole a ' + nome);
fetch('get_mescole_matrice.php?id=' + id)
.then(r => r.json())
.then(data => {
const sel = $('#mescoleSelect');
sel.empty();
data.tutte.forEach(m => {
const selected = data.associate.includes(m.id.toString()) ? 'selected' : '';
sel.append(`<option value="${m.id}" ${selected}>${m.nome}</option>`);
});
sel.select2({
theme: 'bootstrap-5',
width: '100%'
});
$('#associaMescoleModal').modal('show');
});
});
$('#associaMescoleForm').on('submit', e => {
e.preventDefault();
const id = $('#idMatriceMescole').val();
const mescole = $('#mescoleSelect').val();
fetch('save_matrice_mescole.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id, mescole })
}).then(r => r.json()).then(d => {
Swal.fire({
icon: d.success ? 'success' : 'error',
title: d.success ? 'Salvato!' : 'Errore',
text: d.message || ''
}).then(() => location.reload());
});
});
});
</script>
</body>
</html>
</html>