update mescole and photo diagram
This commit is contained in:
+150
-95
@@ -75,19 +75,6 @@
|
||||
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;
|
||||
}
|
||||
|
||||
/* Centra il testo degli header della tabella */
|
||||
#tabellaMescole thead th {
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
@@ -123,6 +110,7 @@
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Nome Mescola</th>
|
||||
<th>Nome Uscita</th>
|
||||
<th>Linee Associate</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
@@ -132,37 +120,48 @@
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
$sql = "
|
||||
SELECT m.id, m.nome,
|
||||
GROUP_CONCAT(pl.name SEPARATOR ', ') AS linee
|
||||
FROM mescole m
|
||||
LEFT JOIN mescole_lines ml ON m.id = ml.idmescola
|
||||
LEFT JOIN production_lines pl ON ml.idlinea = pl.id
|
||||
GROUP BY m.id
|
||||
ORDER BY m.id DESC";
|
||||
SELECT m.id, m.nome, m.nomeuscita,
|
||||
GROUP_CONCAT(pl.name SEPARATOR ', ') AS linee
|
||||
FROM mescole m
|
||||
LEFT JOIN mescole_lines ml ON m.id = ml.idmescola
|
||||
LEFT JOIN production_lines pl ON ml.idlinea = pl.id
|
||||
GROUP BY m.id
|
||||
ORDER BY m.id DESC";
|
||||
|
||||
$stmt = $pdo->query($sql);
|
||||
if ($stmt->rowCount() === 0) {
|
||||
echo "<tr><td colspan='4' class='text-muted'>Nessuna mescola presente</td></tr>";
|
||||
echo "<tr><td colspan='5' class='text-muted'>Nessuna mescola presente</td></tr>";
|
||||
} else {
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$linee = $row['linee'] ? htmlspecialchars($row['linee']) : '<span class="text-muted">Nessuna</span>';
|
||||
|
||||
echo "<tr>
|
||||
<td>{$row['id']}</td>
|
||||
<td>" . htmlspecialchars($row['nome']) . "</td>
|
||||
<td>{$linee}</td>
|
||||
<td>
|
||||
<button class='btn btn-sm btn-outline-primary associa-linee'
|
||||
data-id='{$row['id']}'
|
||||
data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'>
|
||||
⚙️ Associa Linee
|
||||
</button>
|
||||
</td>
|
||||
</tr>";
|
||||
<td>{$row['id']}</td>
|
||||
<td>" . htmlspecialchars($row['nome']) . "</td>
|
||||
<td>" . htmlspecialchars($row['nomeuscita']) . "</td>
|
||||
<td>{$linee}</td>
|
||||
<td>
|
||||
<button class='btn btn-sm btn-outline-primary associa-linee'
|
||||
data-id='{$row['id']}'
|
||||
data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'>
|
||||
⚙️ Associa Linee
|
||||
</button>
|
||||
|
||||
<button class='btn btn-sm btn-outline-secondary edit-mescola'
|
||||
data-id='{$row['id']}'
|
||||
data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'
|
||||
data-nomeuscita='" . htmlspecialchars($row['nomeuscita'], ENT_QUOTES) . "'>
|
||||
✏️ Modifica
|
||||
</button>
|
||||
</td>
|
||||
</tr>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -172,48 +171,92 @@
|
||||
</div>
|
||||
|
||||
<!-- MODALE AGGIUNTA MESCOLA -->
|
||||
<div class="modal fade" id="addMescolaModal" tabindex="-1" aria-labelledby="addMescolaLabel" aria-hidden="true">
|
||||
<div class="modal fade" id="addMescolaModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header" style="background-color:#cfe3ff;">
|
||||
<h5 class="modal-title" id="addMescolaLabel">Aggiungi Nuova Mescola</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Chiudi"></button>
|
||||
<h5 class="modal-title">Aggiungi Nuova Mescola</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<form id="addMescolaForm">
|
||||
<div class="mb-3">
|
||||
<label for="nomeMescola" class="form-label fw-semibold">Nome Mescola</label>
|
||||
<input type="text" class="form-control" id="nomeMescola" name="nomeMescola" required>
|
||||
<label class="form-label fw-semibold">Nome Mescola</label>
|
||||
<input type="text" class="form-control" id="nomeMescola" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold">Nome Uscita</label>
|
||||
<input type="text" class="form-control" id="nomeUscita" required>
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
<button type="submit" class="btn btn-add">💾 Salva</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODALE EDIT -->
|
||||
<div class="modal fade" id="editMescolaModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header" style="background-color:#cfe3ff;">
|
||||
<h5 class="modal-title">Modifica Mescola</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<form id="editMescolaForm">
|
||||
<input type="hidden" id="editIdMescola">
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold">Nome Mescola</label>
|
||||
<input type="text" class="form-control" id="editNomeMescola" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold">Nome Uscita</label>
|
||||
<input type="text" class="form-control" id="editNomeUscita" required>
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
<button type="submit" class="btn btn-add">💾 Salva Modifiche</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODALE ASSOCIA LINEE -->
|
||||
<div class="modal fade" id="associaLineeModal" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal fade" id="associaLineeModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header" style="background-color:#cfe3ff;">
|
||||
<h5 class="modal-title">Associa Linee alla Mescola</h5>
|
||||
<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="idMescolaLinee">
|
||||
<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>
|
||||
<label class="form-label fw-semibold">Linee</label>
|
||||
<select id="lineeSelect" class="form-select" multiple style="width:100%;"></select>
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
<button type="submit" class="btn btn-add">💾 Salva Associazioni</button>
|
||||
<button type="submit" class="btn btn-add">💾 Salva</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -221,7 +264,7 @@
|
||||
<?php include('jsinclude.php'); ?>
|
||||
|
||||
<script>
|
||||
// Inizializza DataTables
|
||||
/* ----------------- DATATABLE ----------------- */
|
||||
$(document).ready(function() {
|
||||
$('#tabellaMescole').DataTable({
|
||||
order: [
|
||||
@@ -234,62 +277,86 @@
|
||||
});
|
||||
});
|
||||
|
||||
// Inserimento mescola
|
||||
/* -------- AGGIUNTA MESCOLA -------- */
|
||||
$("#addMescolaForm").on("submit", function(e) {
|
||||
e.preventDefault();
|
||||
const nome = $("#nomeMescola").val().trim();
|
||||
|
||||
if (nome === "") {
|
||||
Swal.fire({
|
||||
icon: "warning",
|
||||
title: "Attenzione",
|
||||
text: "Inserisci il nome della mescola.",
|
||||
confirmButtonColor: "#3085d6"
|
||||
});
|
||||
return;
|
||||
}
|
||||
let nome = $("#nomeMescola").val().trim();
|
||||
let nomeuscita = $("#nomeUscita").val().trim();
|
||||
|
||||
fetch("save_mescola.php", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
body: "nome=" + encodeURIComponent(nome)
|
||||
body: `nome=${encodeURIComponent(nome)}&nomeuscita=${encodeURIComponent(nomeuscita)}`
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
Swal.fire({
|
||||
icon: "success",
|
||||
title: "Salvata!",
|
||||
text: "La nuova mescola è stata aggiunta correttamente.",
|
||||
confirmButtonColor: "#3085d6"
|
||||
}).then(() => location.reload());
|
||||
icon: "success",
|
||||
title: "Salvato!",
|
||||
confirmButtonColor: "#3085d6"
|
||||
})
|
||||
.then(() => location.reload());
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: data.message || "Errore durante il salvataggio.",
|
||||
confirmButtonColor: "#d33"
|
||||
text: data.message
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore di connessione",
|
||||
text: "Impossibile contattare il server.",
|
||||
confirmButtonColor: "#d33"
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Apertura modale Associa Linee
|
||||
/* -------- APERTURA MODALE EDIT -------- */
|
||||
$(document).on("click", ".edit-mescola", function() {
|
||||
$("#editIdMescola").val($(this).data("id"));
|
||||
$("#editNomeMescola").val($(this).data("nome"));
|
||||
$("#editNomeUscita").val($(this).data("nomeuscita"));
|
||||
$("#editMescolaModal").modal("show");
|
||||
});
|
||||
|
||||
/* -------- SALVATAGGIO EDIT -------- */
|
||||
$("#editMescolaForm").on("submit", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
let id = $("#editIdMescola").val();
|
||||
let nome = $("#editNomeMescola").val().trim();
|
||||
let nomeuscita = $("#editNomeUscita").val().trim();
|
||||
|
||||
fetch("update_mescola.php", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
body: `id=${id}&nome=${encodeURIComponent(nome)}&nomeuscita=${encodeURIComponent(nomeuscita)}`
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
Swal.fire({
|
||||
icon: "success",
|
||||
title: "Aggiornato!",
|
||||
confirmButtonColor: "#3085d6"
|
||||
})
|
||||
.then(() => location.reload());
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: data.message
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/* -------- MODALE ASSOCIA LINEE -------- */
|
||||
$(document).on("click", ".associa-linee", function() {
|
||||
|
||||
const idMescola = $(this).data("id");
|
||||
const nomeMescola = $(this).data("nome");
|
||||
$("#idMescolaLinee").val(idMescola);
|
||||
$(".modal-title").text("Associa Linee a " + nomeMescola);
|
||||
|
||||
fetch("get_linee_mescola.php?id=" + idMescola)
|
||||
.then(r => r.json())
|
||||
@@ -299,26 +366,24 @@
|
||||
|
||||
data.tutte_linee.forEach(l => {
|
||||
const selected = data.associate.includes(l.id.toString()) ? "selected" : "";
|
||||
select.append(`<option value="${l.id}" ${selected}>${l.name} (${l.brand || ''})</option>`);
|
||||
select.append(`<option value="${l.id}" ${selected}>${l.name}</option>`);
|
||||
});
|
||||
|
||||
select.select2({
|
||||
theme: "bootstrap-5",
|
||||
width: "100%",
|
||||
placeholder: "Seleziona o rimuovi linee di produzione",
|
||||
allowClear: true,
|
||||
closeOnSelect: false
|
||||
width: "100%"
|
||||
});
|
||||
|
||||
$("#associaLineeModal").modal("show");
|
||||
});
|
||||
});
|
||||
|
||||
// Salvataggio associazioni (aggiungi/rimuovi)
|
||||
/* -------- SALVATAGGIO LINEE -------- */
|
||||
$("#associaLineeForm").on("submit", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const idMescola = $("#idMescolaLinee").val();
|
||||
const linee = $("#lineeSelect").val() || []; // se deselezionate tutte, array vuoto
|
||||
const linee = $("#lineeSelect").val() || [];
|
||||
|
||||
fetch("save_mescola_linee.php", {
|
||||
method: "POST",
|
||||
@@ -334,27 +399,17 @@
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
Swal.fire({
|
||||
icon: "success",
|
||||
title: "Aggiornato!",
|
||||
text: "Associazioni aggiornate correttamente.",
|
||||
confirmButtonColor: "#3085d6"
|
||||
}).then(() => location.reload());
|
||||
icon: "success",
|
||||
title: "Aggiornato!"
|
||||
})
|
||||
.then(() => location.reload());
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: data.message || "Errore durante l'aggiornamento.",
|
||||
confirmButtonColor: "#d33"
|
||||
text: data.message
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore di connessione",
|
||||
text: "Impossibile contattare il server.",
|
||||
confirmButtonColor: "#d33"
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user