333 lines
13 KiB
PHP
333 lines
13 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>Gestione Cause di Pausa - <?= 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-problem {
|
||
background: #dc3545;
|
||
color: white;
|
||
padding: 6px 12px;
|
||
border-radius: 6px;
|
||
}
|
||
|
||
.badge-normal {
|
||
background: #0d6efd;
|
||
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">
|
||
<?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 Cause di Pausa</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 Cause</h6>
|
||
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addReasonModal">
|
||
➕ Aggiungi Causa
|
||
</button>
|
||
</div>
|
||
|
||
<div class="table-responsive">
|
||
<table id="tabReasons" class="table table-striped align-middle">
|
||
<thead>
|
||
<tr>
|
||
<th>ID</th>
|
||
<th>Nome</th>
|
||
<th>Descrizione</th>
|
||
<th>Tipo</th>
|
||
<th>Azioni</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php
|
||
$db = DBHandlerSelect::getInstance();
|
||
$pdo = $db->getConnection();
|
||
|
||
$stmt = $pdo->query("SELECT * FROM pause_reasons ORDER BY id ASC");
|
||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)):
|
||
?>
|
||
<tr>
|
||
<td><?= $row['id'] ?></td>
|
||
<td><?= htmlspecialchars($row['name']) ?></td>
|
||
<td><?= htmlspecialchars($row['description']) ?></td>
|
||
|
||
<td>
|
||
<?php if ($row['is_problem']): ?>
|
||
<span class="badge-problem">Problema tecnico</span>
|
||
<?php else: ?>
|
||
<span class="badge-normal">Pausa</span>
|
||
<?php endif; ?>
|
||
</td>
|
||
|
||
<td>
|
||
<button class="btn-action edit"
|
||
data-id="<?= $row['id'] ?>"
|
||
data-name="<?= htmlspecialchars($row['name'], ENT_QUOTES) ?>"
|
||
data-desc="<?= htmlspecialchars($row['description'], ENT_QUOTES) ?>"
|
||
data-problem="<?= $row['is_problem'] ?>">
|
||
<i class="fas fa-edit"></i>
|
||
</button>
|
||
|
||
<button class="btn-action delete" 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="addReasonModal" 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 Causa Pausa</h5>
|
||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||
</div>
|
||
|
||
<form id="addReasonForm">
|
||
<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">Descrizione (opzionale)</label>
|
||
<textarea name="description" class="form-control mb-3"></textarea>
|
||
|
||
<label class="fw-semibold">Tipo</label><br>
|
||
<select name="is_problem" class="form-control">
|
||
<option value="0">Pausa normale</option>
|
||
<option value="1">Problema tecnico</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="editReasonModal" 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 Causa</h5>
|
||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||
</div>
|
||
|
||
<form id="editReasonForm">
|
||
<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">Descrizione</label>
|
||
<textarea id="edit_description" name="description" class="form-control mb-3"></textarea>
|
||
|
||
<label class="fw-semibold">Tipo</label>
|
||
<select id="edit_is_problem" name="is_problem" class="form-control">
|
||
<option value="0">Pausa normale</option>
|
||
<option value="1">Problema tecnico</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() {
|
||
|
||
$('#tabReasons').DataTable({
|
||
order: [
|
||
[0, 'asc']
|
||
],
|
||
pageLength: 50,
|
||
language: {
|
||
url: 'https://cdn.datatables.net/plug-ins/1.13.6/i18n/it-IT.json'
|
||
}
|
||
});
|
||
|
||
// ➕ AGGIUNTA
|
||
$("#addReasonForm").on("submit", function(e) {
|
||
e.preventDefault();
|
||
|
||
fetch("save_pause_reason.php", {
|
||
method: "POST",
|
||
body: new FormData(this)
|
||
})
|
||
.then(r => r.json())
|
||
.then(d => {
|
||
if (d.success) {
|
||
Swal.fire("Salvato!", "Causa aggiunta.", "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_name").val($(this).data("name"));
|
||
$("#edit_description").val($(this).data("desc"));
|
||
$("#edit_is_problem").val($(this).data("problem"));
|
||
|
||
$("#editReasonModal").modal("show");
|
||
});
|
||
|
||
// 💾 SALVA MODIFICA
|
||
$("#editReasonForm").on("submit", function(e) {
|
||
e.preventDefault();
|
||
|
||
fetch("edit_pause_reason.php", {
|
||
method: "POST",
|
||
body: new FormData(this)
|
||
})
|
||
.then(r => r.json())
|
||
.then(d => {
|
||
if (d.success) {
|
||
Swal.fire("Aggiornato!", "Causa modificata.", "success")
|
||
.then(() => location.reload());
|
||
} else Swal.fire("Errore", d.message, "error");
|
||
});
|
||
});
|
||
|
||
// 🗑️ ELIMINA
|
||
$(document).on("click", ".delete", function() {
|
||
const id = $(this).data("id");
|
||
|
||
Swal.fire({
|
||
title: "Eliminare la causa?",
|
||
text: "Questa azione non può essere annullata.",
|
||
icon: "warning",
|
||
showCancelButton: true,
|
||
confirmButtonText: "Sì, elimina",
|
||
cancelButtonText: "Annulla"
|
||
}).then(result => {
|
||
if (result.isConfirmed) {
|
||
fetch("delete_pause_reason.php?id=" + id)
|
||
.then(r => r.json())
|
||
.then(d => {
|
||
if (d.success) {
|
||
Swal.fire("Eliminato!", "Causa rimossa.", "success")
|
||
.then(() => location.reload());
|
||
} else Swal.fire("Errore", d.message, "error");
|
||
});
|
||
}
|
||
});
|
||
});
|
||
|
||
});
|
||
</script>
|
||
|
||
</body>
|
||
|
||
</html>
|