zibo-dashboard/public/userarea/edit_linea.php
2025-10-27 10:10:09 +01:00

166 lines
6.7 KiB
PHP

<?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>Modifica Linea di Produzione</title>
<!-- jQuery + 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>
<style>
body {
background: #f8fafc;
font-size: 1.05rem;
}
.card {
border-radius: 16px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.btn-save {
background-color: #0d6efd;
color: #fff;
border-radius: 8px;
padding: 10px 20px;
font-weight: 500;
}
.btn-save:hover {
background-color: #0b5ed7;
transform: scale(1.02);
}
.back-dashboard {
background-color: #cfe3ff;
color: #1f2d3d;
border: 1px solid #bcd4f4;
border-radius: 10px;
font-weight: 600;
font-size: 1rem;
padding: 10px 18px;
transition: all 0.2s ease-in-out;
}
.back-dashboard:hover {
background-color: #b9d3ff;
transform: translateY(-2px);
}
</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-4 mx-auto" style="max-width: 600px;">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0 text-center w-100">Modifica Linea</h5>
<button type="button" class="btn back-dashboard position-absolute end-0 me-3" onclick="location.href='linee.php'">
↩️ Torna all'elenco
</button>
</div>
<div class="card-body">
<?php
require_once(__DIR__ . '/class/db-functions.php');
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
echo "<div class='alert alert-danger'>ID non valido.</div>";
exit;
}
$id = (int)$_GET['id'];
$stmt = $pdo->prepare("SELECT * FROM production_lines WHERE id = ?");
$stmt->execute([$id]);
$line = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$line) {
echo "<div class='alert alert-warning'>Linea non trovata.</div>";
exit;
}
?>
<form id="editLineaForm">
<input type="hidden" name="id" value="<?= htmlspecialchars($line['id']) ?>">
<div class="mb-3">
<label for="lineNumber" class="form-label fw-semibold">Numero Linea</label>
<input type="number" id="lineNumber" name="lineNumber" class="form-control" value="<?= htmlspecialchars($line['line_number']) ?>" required>
</div>
<div class="mb-3">
<label for="lineName" class="form-label fw-semibold">Nome Linea</label>
<input type="text" id="lineName" name="lineName" class="form-control" value="<?= htmlspecialchars($line['name']) ?>" required>
</div>
<div class="mb-3">
<label for="model" class="form-label fw-semibold">Modello</label>
<input type="text" id="model" name="model" class="form-control" value="<?= htmlspecialchars($line['model']) ?>">
</div>
<div class="mb-3">
<label for="brand" class="form-label fw-semibold">Marca</label>
<input type="text" id="brand" name="brand" class="form-control" value="<?= htmlspecialchars($line['brand']) ?>">
</div>
<div class="mb-3">
<label for="status" class="form-label fw-semibold">Stato</label>
<select id="status" name="status" class="form-select">
<option value="active" <?= $line['status'] === 'active' ? 'selected' : '' ?>>Attiva</option>
<option value="inactive" <?= $line['status'] === 'inactive' ? 'selected' : '' ?>>Inattiva</option>
</select>
</div>
<div class="text-center mt-4">
<button type="submit" class="btn btn-save">💾 Salva Modifiche</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php include('include/footer.php'); ?>
</div>
<script>
document.getElementById("editLineaForm").addEventListener("submit", e => {
e.preventDefault();
const formData = new FormData(e.target);
fetch("update_linea.php", {
method: "POST",
body: formData
})
.then(r => r.json())
.then(data => {
if (data.success) {
Swal.fire({
icon: "success",
title: "Aggiornata!",
text: "La linea è stata modificata correttamente.",
confirmButtonColor: "#3085d6"
}).then(() => location.href = "linee.php");
} else {
Swal.fire("Errore", data.message || "Errore durante l'aggiornamento.", "error");
}
})
.catch(() => Swal.fire("Errore", "Impossibile contattare il server.", "error"));
});
</script>
</body>
</html>