2025-11-22 13:35:12 +01:00

340 lines
14 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 Linee di Produzione - <?= 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);
}
th {
text-align: center !important;
}
.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: #0d6efd;
color: #fff;
border-radius: 8px;
padding: 10px 20px;
font-weight: 500;
transition: all 0.2s ease-in-out;
}
.btn-add:hover {
background-color: #0b5ed7;
transform: scale(1.02);
}
.btn-action {
border: none;
background: transparent;
cursor: pointer;
font-size: 1.2rem;
}
.btn-action.edit {
color: #007bff;
}
.btn-action.delete {
color: #dc3545;
}
.btn-action.toggle {
color: #128346;
}
.btn-action:hover {
transform: scale(1.15);
}
.table thead {
background-color: #cfe3ff;
color: #1f2d3d;
}
.badge-active {
background-color: #d1f5e1;
color: #128346;
padding: 6px 10px;
border-radius: 8px;
}
.badge-inactive {
background-color: #ffe0e0;
color: #a80000;
padding: 6px 10px;
border-radius: 8px;
}
.modal-content {
border-radius: 16px;
}
</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 text-center w-100">Gestione Linee di Produzione</h5>
<button type="button" class="btn back-dashboard position-absolute end-0 me-3" 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 Linee</h6>
<button class="btn btn-add" data-bs-toggle="modal" data-bs-target="#addLineaModal"> Aggiungi Linea</button>
</div>
<!-- TABELLA -->
<div class="table-responsive">
<table id="tabellaLinee" class="table table-striped align-middle text-center" style="width:100%;">
<thead>
<tr>
<th>ID</th>
<th>Numero</th>
<th>Nome</th>
<th>Modello</th>
<th>Marca</th>
<th>Colore</th>
<th>Stato</th>
<th>Azioni</th>
</tr>
</thead>
<tbody>
<?php
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
$stmt = $pdo->query("SELECT * FROM production_lines ORDER BY line_number ASC");
if ($stmt->rowCount() === 0) {
echo "<tr><td colspan='7' class='text-muted'>Nessuna linea di produzione presente</td></tr>";
} else {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$badge = $row['status'] === 'active'
? "<span class='badge-active'>Attiva</span>"
: "<span class='badge-inactive'>Inattiva</span>";
echo "<tr>
<td>{$row['id']}</td>
<td>{$row['line_number']}</td>
<td>" . htmlspecialchars($row['name']) . "</td>
<td>" . htmlspecialchars($row['model']) . "</td>
<td>" . htmlspecialchars($row['brand']) . "</td>
<td>
<div style='width:28px; height:28px; border-radius:6px; border:1px solid #999; background: {$row['color']}; margin:auto;'></div>
</td>
<td>{$badge}</td>
<td>
<button class='btn-action edit' title='Modifica' data-id='{$row['id']}'><i class='fas fa-edit'></i></button>
<button class='btn-action delete' title='Elimina' data-id='{$row['id']}'><i class='fas fa-trash'></i></button>
<button class='btn-action toggle' title='Cambia stato' data-id='{$row['id']}' data-status='{$row['status']}'><i class='fas fa-power-off'></i></button>
</td>
</tr>";
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?php include('include/footer.php'); ?>
</div>
<!-- MODALE AGGIUNTA LINEA -->
<div class="modal fade" id="addLineaModal" tabindex="-1" aria-labelledby="addLineaLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header" style="background-color:#cfe3ff;">
<h5 class="modal-title" id="addLineaLabel">Aggiungi Nuova Linea di Produzione</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Chiudi"></button>
</div>
<div class="modal-body">
<form id="addLineaForm">
<div class="mb-3">
<label for="lineNumber" class="form-label fw-semibold">Numero Linea</label>
<input type="number" class="form-control" id="lineNumber" name="lineNumber" required>
</div>
<div class="mb-3">
<label for="lineName" class="form-label fw-semibold">Nome Linea</label>
<input type="text" class="form-control" id="lineName" name="lineName" required>
</div>
<div class="mb-3">
<label for="model" class="form-label fw-semibold">Modello</label>
<input type="text" class="form-control" id="model" name="model">
</div>
<div class="mb-3">
<label for="brand" class="form-label fw-semibold">Marca</label>
<input type="text" class="form-control" id="brand" name="brand">
</div>
<div class="mb-3">
<label for="color" class="form-label fw-semibold">Colore Linea</label>
<input type="color" class="form-control form-control-color"
id="color" name="color" value="#dc2626" title="Scegli colore">
</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>
$(document).ready(function() {
const table = $('#tabellaLinee').DataTable({
order: [
[1, 'asc']
],
pageLength: 25,
language: {
url: 'https://cdn.datatables.net/plug-ins/1.13.6/i18n/it-IT.json'
}
});
// Aggiungi linea
$("#addLineaForm").on("submit", function(e) {
e.preventDefault();
const formData = new FormData(this);
fetch("save_linea.php", {
method: "POST",
body: formData
})
.then(r => r.json())
.then(data => {
if (data.success) {
Swal.fire("Salvata!", "La nuova linea è stata aggiunta.", "success")
.then(() => location.reload());
} else {
Swal.fire("Errore", data.message || "Errore durante il salvataggio.", "error");
}
})
.catch(() => Swal.fire("Errore", "Impossibile contattare il server.", "error"));
});
// ✏️ Modifica
$(document).on("click", ".edit", function() {
const id = $(this).data("id");
location.href = "edit_linea.php?id=" + id;
});
// 🗑️ Elimina
$(document).on("click", ".delete", function() {
const id = $(this).data("id");
Swal.fire({
title: "Sei sicuro?",
text: "Questa azione eliminerà definitivamente la linea.",
icon: "warning",
showCancelButton: true,
confirmButtonText: "Sì, elimina",
cancelButtonText: "Annulla",
confirmButtonColor: "#d33"
}).then(result => {
if (result.isConfirmed) {
fetch("delete_linea.php?id=" + id)
.then(r => r.json())
.then(data => {
if (data.success) {
Swal.fire("Eliminata!", "La linea è stata rimossa.", "success")
.then(() => location.reload());
} else {
Swal.fire("Errore", data.message || "Errore durante l'eliminazione.", "error");
}
});
}
});
});
// 🔘 Toggle stato
$(document).on("click", ".toggle", function() {
const id = $(this).data("id");
const currentStatus = $(this).data("status");
const newStatus = currentStatus === "active" ? "inactive" : "active";
Swal.fire({
title: "Cambiare stato?",
text: `Vuoi impostare questa linea come ${newStatus === "active" ? "ATTIVA" : "INATTIVA"}?`,
icon: "question",
showCancelButton: true,
confirmButtonText: "Conferma",
cancelButtonText: "Annulla",
confirmButtonColor: "#3085d6"
}).then(result => {
if (result.isConfirmed) {
fetch(`toggle_linea_status.php?id=${id}&status=${newStatus}`)
.then(r => r.json())
.then(data => {
if (data.success) {
Swal.fire("Aggiornata!", "Lo stato è stato modificato.", "success")
.then(() => location.reload());
} else {
Swal.fire("Errore", data.message || "Errore durante l'aggiornamento.", "error");
}
});
}
});
});
});
</script>
</body>
</html>