zibo-dashboard/public/userarea/production_status.php
2025-11-22 20:34:51 +01:00

337 lines
13 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 Status Produzione - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
<!-- jQuery, Bootstrap, DataTables, 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>
<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);
}
.table thead {
background-color: #cfe3ff;
color: #1f2d3d;
text-align: center;
}
th,
td {
vertical-align: middle;
text-align: center;
}
.btn-action {
border: none;
background: transparent;
cursor: pointer;
font-size: 1.3rem;
}
.btn-action.edit {
color: #0d6efd;
}
.btn-action.delete {
color: #dc3545;
}
.btn-action:hover {
transform: scale(1.15);
}
.color-preview {
width: 45px;
height: 22px;
border-radius: 6px;
border: 1px solid #999;
margin: auto;
}
.back-dashboard {
background-color: #cfe3ff !important;
color: #1f2d3d !important;
border-radius: 10px;
font-weight: 600;
padding: 10px 18px;
}
</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 Status 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 Status</h6>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addStatusModal">
Aggiungi Status
</button>
</div>
<div class="table-responsive">
<table id="tabStatus" class="table table-striped align-middle">
<thead>
<tr>
<th>ID</th>
<th>Nome</th>
<th>Ordinamento</th>
<th>Colore Badge</th>
<th>Colore Linea</th>
<th>Azioni</th>
</tr>
</thead>
<tbody>
<?php
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
$stmt = $pdo->query("SELECT * FROM production_status ORDER BY ordinamento ASC");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)):
?>
<tr>
<td><?= $row['id'] ?></td>
<td><?= htmlspecialchars($row['nome']) ?></td>
<td><?= $row['ordinamento'] ?></td>
<td>
<div class="color-preview" style="background: <?= $row['badge_color'] ?>"></div>
<small><?= $row['badge_color'] ?></small>
</td>
<td>
<div class="color-preview" style="background: <?= $row['line_color'] ?>"></div>
<small><?= $row['line_color'] ?></small>
</td>
<td>
<button class="btn-action edit" title="Modifica"
data-id="<?= $row['id'] ?>"
data-nome="<?= htmlspecialchars($row['nome'], ENT_QUOTES) ?>"
data-ord="<?= $row['ordinamento'] ?>"
data-badge="<?= $row['badge_color'] ?>"
data-line="<?= $row['line_color'] ?>">
<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>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?php include('include/footer.php'); ?>
</div>
<!-- MODALE AGGIUNTA -->
<div class="modal fade" id="addStatusModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header" style="background:#cfe3ff">
<h5 class="modal-title">Aggiungi Nuovo Status</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form id="addStatusForm">
<div class="modal-body">
<label class="fw-semibold">Nome Status</label>
<input type="text" name="nome" class="form-control mb-3" required>
<label class="fw-semibold">Ordinamento</label>
<input type="number" name="ordinamento" class="form-control mb-3" required>
<label class="fw-semibold">Colore Badge</label>
<input type="color" name="badge_color" class="form-control form-control-color mb-3" value="#6c757d">
<label class="fw-semibold">Colore Linea</label>
<input type="color" name="line_color" class="form-control form-control-color mb-3" value="#e9ecef">
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">💾 Salva</button>
</div>
</form>
</div>
</div>
</div>
<!-- MODALE MODIFICA -->
<div class="modal fade" id="editStatusModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header" style="background:#cfe3ff">
<h5 class="modal-title">Modifica Status</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form id="editStatusForm">
<div class="modal-body">
<input type="hidden" name="id" id="edit_id">
<label class="fw-semibold">Nome Status</label>
<input type="text" name="nome" id="edit_nome" class="form-control mb-3" required>
<label class="fw-semibold">Ordinamento</label>
<input type="number" name="ordinamento" id="edit_ordinamento" class="form-control mb-3" required>
<label class="fw-semibold">Colore Badge</label>
<input type="color" name="badge_color" id="edit_badge" class="form-control form-control-color mb-3">
<label class="fw-semibold">Colore Linea</label>
<input type="color" name="line_color" id="edit_line" class="form-control form-control-color mb-3">
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">💾 Aggiorna</button>
</div>
</form>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('#tabStatus').DataTable({
order: [
[2, 'asc']
],
pageLength: 50,
language: {
url: 'https://cdn.datatables.net/plug-ins/1.13.6/i18n/it-IT.json'
}
});
// SALVATAGGIO NUOVO STATUS
$("#addStatusForm").on("submit", function(e) {
e.preventDefault();
fetch("save_status.php", {
method: "POST",
body: new FormData(this)
})
.then(r => r.json())
.then(d => {
if (d.success) {
Swal.fire("Salvato!", "Nuovo status aggiunto", "success")
.then(() => location.reload());
} else Swal.fire("Errore", d.message, "error");
});
});
// ✏️ APRI MODALE MODIFICA
$(document).on("click", ".edit", function() {
$("#edit_id").val($(this).data("id"));
$("#edit_nome").val($(this).data("nome"));
$("#edit_ordinamento").val($(this).data("ord"));
$("#edit_badge").val($(this).data("badge"));
$("#edit_line").val($(this).data("line"));
$("#editStatusModal").modal("show");
});
// 💾 SALVA MODIFICA STATUS
$("#editStatusForm").on("submit", function(e) {
e.preventDefault();
fetch("edit_status.php", {
method: "POST",
body: new FormData(this)
})
.then(r => r.json())
.then(d => {
if (d.success) {
Swal.fire("Aggiornato!", "Lo status è stato modificato.", "success")
.then(() => location.reload());
} else Swal.fire("Errore", d.message, "error");
});
});
// 🗑️ ELIMINA STATUS
$(document).on("click", ".delete", function() {
const id = $(this).data("id");
Swal.fire({
title: "Eliminare lo status?",
text: "L'azione è irreversibile.",
icon: "warning",
showCancelButton: true,
confirmButtonText: "Sì, elimina",
cancelButtonText: "Annulla"
}).then(result => {
if (result.isConfirmed) {
fetch("delete_status.php?id=" + id)
.then(r => r.json())
.then(d => {
if (d.success) {
Swal.fire("Eliminato!", "Status rimosso.", "success")
.then(() => location.reload());
} else Swal.fire("Errore", d.message, "error");
});
}
});
});
});
</script>
</body>
</html>