393 lines
16 KiB
PHP
393 lines
16 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/logo-zibo.svg" type="image/svg+xml" />
|
||
<?php include('cssinclude.php'); ?>
|
||
<title>Gestione Strumenti Aggiuntivi - <?= 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);
|
||
}
|
||
|
||
th,
|
||
td {
|
||
vertical-align: middle !important;
|
||
text-align: center !important;
|
||
}
|
||
|
||
.badge-active {
|
||
background: #198754;
|
||
color: white;
|
||
padding: 6px 12px;
|
||
border-radius: 6px;
|
||
}
|
||
|
||
.badge-inactive {
|
||
background: #6c757d;
|
||
color: white;
|
||
padding: 6px 12px;
|
||
border-radius: 6px;
|
||
}
|
||
|
||
.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.2);
|
||
}
|
||
|
||
.back-dashboard {
|
||
background-color: #cfe3ff !important;
|
||
color: #1f2d3d !important;
|
||
border-radius: 10px;
|
||
font-weight: 600;
|
||
padding: 10px 18px;
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
<body>
|
||
<div class="wrapper toggled">
|
||
<?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 Strumenti Aggiuntivi</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 Strumenti</h6>
|
||
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addToolModal">
|
||
➕ Aggiungi Strumento
|
||
</button>
|
||
</div>
|
||
|
||
<div class="table-responsive">
|
||
<table id="tabTools" class="table table-striped align-middle">
|
||
<thead>
|
||
<tr>
|
||
<th>Nome</th>
|
||
<th>N. Registrazione</th>
|
||
<th>N. Seriale</th>
|
||
<th>Tipo</th>
|
||
<th>Produttore</th>
|
||
<th>Descrizione</th>
|
||
<th>Stato</th>
|
||
<th>Azioni</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php
|
||
$db = DBHandlerSelect::getInstance();
|
||
$pdo = $db->getConnection();
|
||
|
||
$stmt = $pdo->query("SELECT * FROM production_tools ORDER BY id ASC");
|
||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)):
|
||
?>
|
||
<tr>
|
||
<td><?= htmlspecialchars($row['name']) ?></td>
|
||
<td><?= htmlspecialchars($row['registration_number'] ?? '') ?></td>
|
||
<td><?= htmlspecialchars($row['serial_number'] ?? '') ?></td>
|
||
<td><?= htmlspecialchars($row['tool_type'] ?? '') ?></td>
|
||
<td><?= htmlspecialchars($row['manufacturer'] ?? '') ?></td>
|
||
<td><?= nl2br(htmlspecialchars($row['description'] ?? '')) ?></td>
|
||
|
||
<td>
|
||
<?php if ((int)$row['is_active'] === 1): ?>
|
||
<span class="badge-active">Attivo</span>
|
||
<?php else: ?>
|
||
<span class="badge-inactive">Non attivo</span>
|
||
<?php endif; ?>
|
||
</td>
|
||
|
||
<td>
|
||
<button class="btn-action edit"
|
||
title="Modifica"
|
||
data-id="<?= $row['id'] ?>"
|
||
data-name="<?= htmlspecialchars($row['name'], ENT_QUOTES) ?>"
|
||
data-reg="<?= htmlspecialchars($row['registration_number'] ?? '', ENT_QUOTES) ?>"
|
||
data-serial="<?= htmlspecialchars($row['serial_number'] ?? '', ENT_QUOTES) ?>"
|
||
data-type="<?= htmlspecialchars($row['tool_type'] ?? '', ENT_QUOTES) ?>"
|
||
data-manufacturer="<?= htmlspecialchars($row['manufacturer'] ?? '', ENT_QUOTES) ?>"
|
||
data-desc="<?= htmlspecialchars($row['description'] ?? '', ENT_QUOTES) ?>"
|
||
data-active="<?= (int)$row['is_active'] ?>">
|
||
<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="addToolModal" tabindex="-1" aria-hidden="true">
|
||
<div class="modal-dialog modal-dialog-centered">
|
||
<div class="modal-content">
|
||
|
||
<div class="modal-header" style="background:#cfe3ff">
|
||
<h5 class="modal-title">Aggiungi Strumento</h5>
|
||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||
</div>
|
||
|
||
<form id="addToolForm">
|
||
<div class="modal-body">
|
||
|
||
<label class="fw-semibold">Nome</label>
|
||
<input type="text" name="name" class="form-control mb-3" required>
|
||
|
||
<label class="fw-semibold">N. Registrazione</label>
|
||
<input type="text" name="registration_number" class="form-control mb-3">
|
||
|
||
<label class="fw-semibold">N. Seriale</label>
|
||
<input type="text" name="serial_number" class="form-control mb-3">
|
||
|
||
<label class="fw-semibold">Tipo (es. Taglierina, Laser, Marcatura)</label>
|
||
<input type="text" name="tool_type" class="form-control mb-3">
|
||
|
||
<label class="fw-semibold">Produttore</label>
|
||
<input type="text" name="manufacturer" class="form-control mb-3">
|
||
|
||
<label class="fw-semibold">Descrizione (opzionale)</label>
|
||
<textarea name="description" class="form-control mb-3"></textarea>
|
||
|
||
<label class="fw-semibold">Stato</label>
|
||
<select name="is_active" class="form-control">
|
||
<option value="1">Attivo</option>
|
||
<option value="0">Non attivo</option>
|
||
</select>
|
||
|
||
</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="editToolModal" tabindex="-1" aria-hidden="true">
|
||
<div class="modal-dialog modal-dialog-centered">
|
||
<div class="modal-content">
|
||
|
||
<div class="modal-header" style="background:#cfe3ff">
|
||
<h5 class="modal-title">Modifica Strumento</h5>
|
||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||
</div>
|
||
|
||
<form id="editToolForm">
|
||
<div class="modal-body">
|
||
|
||
<input type="hidden" id="edit_id" name="id">
|
||
|
||
<label class="fw-semibold">Nome</label>
|
||
<input type="text" id="edit_name" name="name" class="form-control mb-3" required>
|
||
|
||
<label class="fw-semibold">N. Registrazione</label>
|
||
<input type="text" id="edit_registration_number" name="registration_number" class="form-control mb-3">
|
||
|
||
<label class="fw-semibold">N. Seriale</label>
|
||
<input type="text" id="edit_serial_number" name="serial_number" class="form-control mb-3">
|
||
|
||
<label class="fw-semibold">Tipo</label>
|
||
<input type="text" id="edit_tool_type" name="tool_type" class="form-control mb-3">
|
||
|
||
<label class="fw-semibold">Produttore</label>
|
||
<input type="text" id="edit_manufacturer" name="manufacturer" class="form-control mb-3">
|
||
|
||
<label class="fw-semibold">Descrizione</label>
|
||
<textarea id="edit_description" name="description" class="form-control mb-3"></textarea>
|
||
|
||
<label class="fw-semibold">Stato</label>
|
||
<select id="edit_is_active" name="is_active" class="form-control">
|
||
<option value="1">Attivo</option>
|
||
<option value="0">Non attivo</option>
|
||
</select>
|
||
|
||
</div>
|
||
|
||
|
||
<div class="modal-footer">
|
||
<button type="submit" class="btn btn-primary">💾 Aggiorna</button>
|
||
</div>
|
||
</form>
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
$(document).ready(function() {
|
||
|
||
$('#tabTools').DataTable({
|
||
order: [
|
||
[0, 'asc']
|
||
],
|
||
pageLength: 50,
|
||
language: {
|
||
url: 'https://cdn.datatables.net/plug-ins/1.13.6/i18n/it-IT.json'
|
||
}
|
||
});
|
||
|
||
// ➕ ADD TOOL
|
||
$("#addToolForm").on("submit", function(e) {
|
||
e.preventDefault();
|
||
|
||
fetch("save_tool.php", {
|
||
method: "POST",
|
||
body: new FormData(this)
|
||
})
|
||
.then(r => r.json())
|
||
.then(d => {
|
||
if (d.success) {
|
||
Swal.fire("Salvato!", "Strumento aggiunto.", "success")
|
||
.then(() => location.reload());
|
||
} else {
|
||
Swal.fire("Errore", d.message || "Errore durante il salvataggio.", "error");
|
||
}
|
||
})
|
||
.catch(() => {
|
||
Swal.fire("Errore", "Errore di comunicazione con il server.", "error");
|
||
});
|
||
});
|
||
|
||
// ✏️ OPEN EDIT MODAL
|
||
$(document).on("click", ".edit", function() {
|
||
|
||
$("#edit_id").val($(this).data("id"));
|
||
$("#edit_name").val($(this).data("name"));
|
||
$("#edit_registration_number").val($(this).data("reg"));
|
||
$("#edit_serial_number").val($(this).data("serial"));
|
||
$("#edit_tool_type").val($(this).data("type"));
|
||
$("#edit_manufacturer").val($(this).data("manufacturer"));
|
||
$("#edit_description").val($(this).data("desc"));
|
||
$("#edit_is_active").val($(this).data("active"));
|
||
|
||
$("#editToolModal").modal("show");
|
||
});
|
||
|
||
|
||
// 💾 SAVE EDIT
|
||
$("#editToolForm").on("submit", function(e) {
|
||
e.preventDefault();
|
||
|
||
fetch("edit_tool.php", {
|
||
method: "POST",
|
||
body: new FormData(this)
|
||
})
|
||
.then(r => r.json())
|
||
.then(d => {
|
||
if (d.success) {
|
||
Swal.fire("Aggiornato!", "Strumento modificato.", "success")
|
||
.then(() => location.reload());
|
||
} else {
|
||
Swal.fire("Errore", d.message || "Errore durante l'aggiornamento.", "error");
|
||
}
|
||
})
|
||
.catch(() => {
|
||
Swal.fire("Errore", "Errore di comunicazione con il server.", "error");
|
||
});
|
||
});
|
||
|
||
// 🗑️ DELETE TOOL
|
||
$(document).on("click", ".delete", function() {
|
||
const id = $(this).data("id");
|
||
|
||
Swal.fire({
|
||
title: "Eliminare lo strumento?",
|
||
text: "Questa azione non può essere annullata.",
|
||
icon: "warning",
|
||
showCancelButton: true,
|
||
confirmButtonText: "Sì, elimina",
|
||
cancelButtonText: "Annulla"
|
||
}).then(result => {
|
||
if (result.isConfirmed) {
|
||
fetch("delete_tool.php?id=" + encodeURIComponent(id))
|
||
.then(r => r.json())
|
||
.then(d => {
|
||
if (d.success) {
|
||
Swal.fire("Eliminato!", "Strumento rimosso.", "success")
|
||
.then(() => location.reload());
|
||
} else {
|
||
Swal.fire("Errore", d.message || "Errore durante l'eliminazione.", "error");
|
||
}
|
||
})
|
||
.catch(() => {
|
||
Swal.fire("Errore", "Errore di comunicazione con il server.", "error");
|
||
});
|
||
}
|
||
});
|
||
});
|
||
|
||
});
|
||
</script>
|
||
|
||
</body>
|
||
|
||
</html>
|