added pages
This commit is contained in:
parent
92ec026afe
commit
a4b1fb9b1f
28
public/userarea/delete_linea.php
Normal file
28
public/userarea/delete_linea.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
require_once(__DIR__ . '/class/db-functions.php');
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
||||
echo json_encode(['success' => false, 'message' => 'ID non valido.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = (int)$_GET['id'];
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$stmt = $pdo->prepare("DELETE FROM production_lines WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
echo json_encode(['success' => true]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => 'Linea non trovata o già eliminata.']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => 'Errore: ' . $e->getMessage()]);
|
||||
}
|
||||
26
public/userarea/delete_matrice.php
Normal file
26
public/userarea/delete_matrice.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
include('../class/db-functions.php');
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
if (!isset($_GET['id'])) {
|
||||
echo json_encode(['success' => false, 'message' => 'ID non fornito.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = intval($_GET['id']);
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Cancella eventuali associazioni
|
||||
$pdo->prepare("DELETE FROM matrice_lines WHERE idmatrice = ?")->execute([$id]);
|
||||
$pdo->prepare("DELETE FROM matrice_mescole WHERE idmatrice = ?")->execute([$id]);
|
||||
|
||||
// Cancella la matrice
|
||||
$pdo->prepare("DELETE FROM matrice WHERE id = ?")->execute([$id]);
|
||||
|
||||
echo json_encode(['success' => true, 'message' => 'Matrice eliminata con successo.']);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => 'Errore: ' . $e->getMessage()]);
|
||||
}
|
||||
166
public/userarea/edit_linea.php
Normal file
166
public/userarea/edit_linea.php
Normal file
@ -0,0 +1,166 @@
|
||||
<?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>
|
||||
28
public/userarea/get_linee_matrice.php
Normal file
28
public/userarea/get_linee_matrice.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
include('../class/db-functions.php');
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
if (!isset($_GET['id'])) {
|
||||
echo json_encode(['success' => false, 'message' => 'ID matrice non fornito.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$idMatrice = intval($_GET['id']);
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Tutte le linee
|
||||
$stmt = $pdo->query("SELECT id, name, brand FROM production_lines ORDER BY name ASC");
|
||||
$tutte = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Linee già associate
|
||||
$stmt = $pdo->prepare("SELECT idlinea FROM matrice_lines WHERE idmatrice = ?");
|
||||
$stmt->execute([$idMatrice]);
|
||||
$associate = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
echo json_encode(['success' => true, 'tutte' => $tutte, 'associate' => $associate]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => 'Errore: ' . $e->getMessage()]);
|
||||
}
|
||||
37
public/userarea/get_linee_mescola.php
Normal file
37
public/userarea/get_linee_mescola.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
require_once(__DIR__ . '/class/db-functions.php');
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
if (!isset($_GET['id'])) {
|
||||
throw new Exception("Parametro ID mancante.");
|
||||
}
|
||||
|
||||
$idMescola = (int) $_GET['id'];
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Recupera TUTTE le linee
|
||||
$stmt = $pdo->query("SELECT id, name, brand FROM production_lines ORDER BY line_number ASC");
|
||||
$tutte_linee = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Recupera linee associate a questa mescola
|
||||
$stmt = $pdo->prepare("SELECT idlinea FROM mescole_lines WHERE idmescola = ?");
|
||||
$stmt->execute([$idMescola]);
|
||||
$associate = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
// Conversione in stringhe (per compatibilità con JS)
|
||||
$associate = array_map('strval', $associate);
|
||||
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"tutte_linee" => $tutte_linee,
|
||||
"associate" => $associate
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"message" => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
27
public/userarea/get_mescole_matrice.php
Normal file
27
public/userarea/get_mescole_matrice.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
include('../class/db-functions.php');
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
if (!isset($_GET['id'])) {
|
||||
echo json_encode(['success' => false, 'message' => 'ID matrice non fornito.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$idMatrice = intval($_GET['id']);
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Tutte le mescole
|
||||
$stmt = $pdo->query("SELECT id, nome FROM mescole ORDER BY nome ASC");
|
||||
$tutte = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Mescole già associate
|
||||
$stmt = $pdo->prepare("SELECT idmescola FROM matrice_mescole WHERE idmatrice = ?");
|
||||
$stmt->execute([$idMatrice]);
|
||||
$associate = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
echo json_encode(['success' => true, 'tutte' => $tutte, 'associate' => $associate]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => 'Errore: ' . $e->getMessage()]);
|
||||
}
|
||||
327
public/userarea/linee.php
Normal file
327
public/userarea/linee.php
Normal file
@ -0,0 +1,327 @@
|
||||
<?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>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>{$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="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>
|
||||
@ -9,7 +9,7 @@
|
||||
<?php include('cssinclude.php'); ?>
|
||||
<title>Gestione Matrici - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
||||
|
||||
<!-- jQuery e Bootstrap -->
|
||||
<!-- jQuery, Bootstrap, 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>
|
||||
@ -19,6 +19,11 @@
|
||||
<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>
|
||||
|
||||
<!-- Select2 -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
|
||||
<link href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css" rel="stylesheet" />
|
||||
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.full.min.js"></script>
|
||||
|
||||
<style>
|
||||
body {
|
||||
font-size: 1.05rem;
|
||||
@ -31,9 +36,9 @@
|
||||
}
|
||||
|
||||
.back-dashboard {
|
||||
background-color: #cfe3ff !important;
|
||||
background-color: #b9ebc7 !important;
|
||||
color: #1f2d3d !important;
|
||||
border: 1px solid #bcd4f4 !important;
|
||||
border: 1px solid #a1d7b4 !important;
|
||||
border-radius: 10px;
|
||||
font-weight: 600;
|
||||
font-size: 1rem;
|
||||
@ -43,7 +48,7 @@
|
||||
}
|
||||
|
||||
.back-dashboard:hover {
|
||||
background-color: #b9d3ff !important;
|
||||
background-color: #a1dfb1 !important;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
@ -64,23 +69,46 @@
|
||||
.table thead {
|
||||
background-color: #b9ebc7;
|
||||
color: #1f2d3d;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.table tbody td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
border: none;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
font-size: 1.2rem;
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
.action-btn.edit {
|
||||
color: #0d6efd;
|
||||
}
|
||||
|
||||
.action-btn.delete {
|
||||
color: #dc3545;
|
||||
}
|
||||
|
||||
.action-btn.linee {
|
||||
color: #198754;
|
||||
}
|
||||
|
||||
.action-btn.mescole {
|
||||
color: #ff9800;
|
||||
}
|
||||
|
||||
.dataTables_filter input {
|
||||
border-radius: 8px;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid #ced4da;
|
||||
}
|
||||
|
||||
.dataTables_wrapper .dataTables_length select {
|
||||
border-radius: 8px;
|
||||
padding: 5px;
|
||||
border: 1px solid #ced4da;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@ -107,11 +135,12 @@
|
||||
|
||||
<!-- TABELLA -->
|
||||
<div class="table-responsive">
|
||||
<table id="tabellaMatrici" class="table table-striped align-middle text-center" style="width:100%;">
|
||||
<table id="tabellaMatrici" class="table table-striped align-middle text-center">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:80px;">ID</th>
|
||||
<th>ID</th>
|
||||
<th>Nome Matrice</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -120,13 +149,19 @@
|
||||
$pdo = $db->getConnection();
|
||||
$stmt = $pdo->query("SELECT * FROM matrice ORDER BY id DESC");
|
||||
if ($stmt->rowCount() === 0) {
|
||||
echo "<tr><td colspan='2' class='text-muted'>Nessuna matrice presente</td></tr>";
|
||||
echo "<tr><td colspan='3' class='text-muted'>Nessuna matrice presente</td></tr>";
|
||||
} else {
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
echo "<tr>
|
||||
<td>" . htmlspecialchars($row['id']) . "</td>
|
||||
<td>" . htmlspecialchars($row['nome']) . "</td>
|
||||
</tr>";
|
||||
<td>{$row['id']}</td>
|
||||
<td>" . htmlspecialchars($row['nome']) . "</td>
|
||||
<td>
|
||||
<button class='action-btn edit' data-id='{$row['id']}' data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'><i class='fa-solid fa-pen-to-square'></i></button>
|
||||
<button class='action-btn delete' data-id='{$row['id']}'><i class='fa-solid fa-trash'></i></button>
|
||||
<button class='action-btn linee' data-id='{$row['id']}' data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'><i class='fa-solid fa-sitemap'></i></button>
|
||||
<button class='action-btn mescole' data-id='{$row['id']}' data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'><i class='fa-solid fa-flask'></i></button>
|
||||
</td>
|
||||
</tr>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -141,16 +176,17 @@
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
|
||||
<!-- MODALE AGGIUNTA MATRICE -->
|
||||
<!-- MODALE AGGIUNTA / MODIFICA -->
|
||||
<div class="modal fade" id="addMatriceModal" tabindex="-1" aria-labelledby="addMatriceLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header" style="background-color:#b9ebc7;">
|
||||
<h5 class="modal-title" id="addMatriceLabel">Aggiungi Nuova Matrice</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Chiudi"></button>
|
||||
<h5 class="modal-title" id="addMatriceLabel">Aggiungi / Modifica Matrice</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="addMatriceForm">
|
||||
<input type="hidden" id="idMatriceEdit">
|
||||
<div class="mb-3">
|
||||
<label for="nomeMatrice" class="form-label fw-semibold">Nome Matrice</label>
|
||||
<input type="text" class="form-control" id="nomeMatrice" name="nomeMatrice" required>
|
||||
@ -163,71 +199,204 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODALE ASSOCIA LINEE -->
|
||||
<div class="modal fade" id="associaLineeModal" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header" style="background-color:#b9ebc7;">
|
||||
<h5 class="modal-title">Associa Linee</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="associaLineeForm">
|
||||
<input type="hidden" id="idMatriceLinee">
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold">Linee di Produzione</label>
|
||||
<select id="lineeSelect" name="linee[]" class="form-select" multiple required style="width:100%;"></select>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<button type="submit" class="btn btn-add">💾 Salva Associazioni</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODALE ASSOCIA MESCOLE -->
|
||||
<div class="modal fade" id="associaMescoleModal" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header" style="background-color:#b9ebc7;">
|
||||
<h5 class="modal-title">Associa Mescole</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="associaMescoleForm">
|
||||
<input type="hidden" id="idMatriceMescole">
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold">Mescole</label>
|
||||
<select id="mescoleSelect" name="mescole[]" class="form-select" multiple required style="width:100%;"></select>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<button type="submit" class="btn btn-add">💾 Salva Associazioni</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include('jsinclude.php'); ?>
|
||||
<script>
|
||||
// Attiva DataTables
|
||||
$(document).ready(function() {
|
||||
$('#tabellaMatrici').DataTable({
|
||||
const table = $('#tabellaMatrici').DataTable({
|
||||
order: [
|
||||
[0, 'desc']
|
||||
],
|
||||
pageLength: 25,
|
||||
language: {
|
||||
url: 'https://cdn.datatables.net/plug-ins/1.13.6/i18n/it-IT.json'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Gestione inserimento con AJAX
|
||||
document.getElementById("addMatriceForm").addEventListener("submit", function(e) {
|
||||
e.preventDefault();
|
||||
const nome = document.getElementById("nomeMatrice").value.trim();
|
||||
// === ADD / EDIT MATRICE ===
|
||||
$(document).on('click', '.edit', function() {
|
||||
$('#idMatriceEdit').val($(this).data('id'));
|
||||
$('#nomeMatrice').val($(this).data('nome'));
|
||||
$('#addMatriceModal').modal('show');
|
||||
});
|
||||
|
||||
if (nome === "") {
|
||||
Swal.fire({
|
||||
icon: "warning",
|
||||
title: "Attenzione",
|
||||
text: "Inserisci il nome della matrice.",
|
||||
confirmButtonColor: "#3085d6"
|
||||
});
|
||||
return;
|
||||
}
|
||||
$('#addMatriceForm').on('submit', function(e) {
|
||||
e.preventDefault();
|
||||
const id = $('#idMatriceEdit').val();
|
||||
const nome = $('#nomeMatrice').val().trim();
|
||||
if (nome === "") return;
|
||||
|
||||
fetch("save_matrice.php", {
|
||||
method: "POST",
|
||||
fetch('save_matrice.php', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
body: "nome=" + encodeURIComponent(nome)
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
Swal.fire({
|
||||
icon: "success",
|
||||
title: "Salvata!",
|
||||
text: "La nuova matrice è stata aggiunta correttamente.",
|
||||
confirmButtonColor: "#3085d6"
|
||||
}).then(() => location.reload());
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: data.message || "Si è verificato un errore durante il salvataggio.",
|
||||
confirmButtonColor: "#d33"
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
body: 'id=' + id + '&nome=' + encodeURIComponent(nome)
|
||||
}).then(r => r.json()).then(data => {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore di connessione",
|
||||
text: "Impossibile contattare il server.",
|
||||
confirmButtonColor: "#d33"
|
||||
});
|
||||
icon: data.success ? 'success' : 'error',
|
||||
title: data.success ? 'Salvata!' : 'Errore',
|
||||
text: data.message || (data.success ? 'Matrice salvata correttamente.' : 'Errore durante il salvataggio.')
|
||||
}).then(() => location.reload());
|
||||
});
|
||||
});
|
||||
|
||||
// === DELETE MATRICE ===
|
||||
$(document).on('click', '.delete', function() {
|
||||
const id = $(this).data('id');
|
||||
Swal.fire({
|
||||
icon: 'warning',
|
||||
title: 'Eliminare questa matrice?',
|
||||
text: 'L\'operazione non è reversibile.',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Sì, elimina',
|
||||
cancelButtonText: 'Annulla',
|
||||
confirmButtonColor: '#d33'
|
||||
}).then(res => {
|
||||
if (res.isConfirmed) {
|
||||
fetch('delete_matrice.php?id=' + id)
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
Swal.fire({
|
||||
icon: data.success ? 'success' : 'error',
|
||||
title: data.success ? 'Eliminata!' : 'Errore',
|
||||
text: data.message || ''
|
||||
}).then(() => location.reload());
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// === ASSOCIA LINEE ===
|
||||
$(document).on('click', '.linee', function() {
|
||||
const id = $(this).data('id');
|
||||
const nome = $(this).data('nome');
|
||||
$('#idMatriceLinee').val(id);
|
||||
$('.modal-title').text('Associa Linee a ' + nome);
|
||||
|
||||
fetch('get_linee_matrice.php?id=' + id)
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
const sel = $('#lineeSelect');
|
||||
sel.empty();
|
||||
data.tutte.forEach(l => {
|
||||
const selected = data.associate.includes(l.id.toString()) ? 'selected' : '';
|
||||
sel.append(`<option value="${l.id}" ${selected}>${l.name} (${l.brand || ''})</option>`);
|
||||
});
|
||||
sel.select2({
|
||||
theme: 'bootstrap-5',
|
||||
width: '100%'
|
||||
});
|
||||
$('#associaLineeModal').modal('show');
|
||||
});
|
||||
});
|
||||
|
||||
$('#associaLineeForm').on('submit', e => {
|
||||
e.preventDefault();
|
||||
const id = $('#idMatriceLinee').val();
|
||||
const linee = $('#lineeSelect').val();
|
||||
fetch('save_matrice_linee.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ id, linee })
|
||||
}).then(r => r.json()).then(d => {
|
||||
Swal.fire({
|
||||
icon: d.success ? 'success' : 'error',
|
||||
title: d.success ? 'Salvato!' : 'Errore',
|
||||
text: d.message || ''
|
||||
}).then(() => location.reload());
|
||||
});
|
||||
});
|
||||
|
||||
// === ASSOCIA MESCOLE ===
|
||||
$(document).on('click', '.mescole', function() {
|
||||
const id = $(this).data('id');
|
||||
const nome = $(this).data('nome');
|
||||
$('#idMatriceMescole').val(id);
|
||||
$('.modal-title').text('Associa Mescole a ' + nome);
|
||||
|
||||
fetch('get_mescole_matrice.php?id=' + id)
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
const sel = $('#mescoleSelect');
|
||||
sel.empty();
|
||||
data.tutte.forEach(m => {
|
||||
const selected = data.associate.includes(m.id.toString()) ? 'selected' : '';
|
||||
sel.append(`<option value="${m.id}" ${selected}>${m.nome}</option>`);
|
||||
});
|
||||
sel.select2({
|
||||
theme: 'bootstrap-5',
|
||||
width: '100%'
|
||||
});
|
||||
$('#associaMescoleModal').modal('show');
|
||||
});
|
||||
});
|
||||
|
||||
$('#associaMescoleForm').on('submit', e => {
|
||||
e.preventDefault();
|
||||
const id = $('#idMatriceMescole').val();
|
||||
const mescole = $('#mescoleSelect').val();
|
||||
fetch('save_matrice_mescole.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ id, mescole })
|
||||
}).then(r => r.json()).then(d => {
|
||||
Swal.fire({
|
||||
icon: d.success ? 'success' : 'error',
|
||||
title: d.success ? 'Salvato!' : 'Errore',
|
||||
text: d.message || ''
|
||||
}).then(() => location.reload());
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@ -19,6 +19,11 @@
|
||||
<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>
|
||||
|
||||
<!-- Select2 -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
|
||||
<link href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css" rel="stylesheet" />
|
||||
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.full.min.js"></script>
|
||||
|
||||
<style>
|
||||
body {
|
||||
font-size: 1.05rem;
|
||||
@ -81,6 +86,12 @@
|
||||
padding: 5px;
|
||||
border: 1px solid #ced4da;
|
||||
}
|
||||
|
||||
/* Centra il testo degli header della tabella */
|
||||
#tabellaMescole thead th {
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@ -110,22 +121,41 @@
|
||||
<table id="tabellaMescole" class="table table-striped align-middle text-center" style="width:100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:80px;">ID</th>
|
||||
<th>ID</th>
|
||||
<th>Nome Mescola</th>
|
||||
<th>Linee Associate</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
$stmt = $pdo->query("SELECT * FROM mescole ORDER BY id DESC");
|
||||
$sql = "
|
||||
SELECT m.id, m.nome,
|
||||
GROUP_CONCAT(pl.name SEPARATOR ', ') AS linee
|
||||
FROM mescole m
|
||||
LEFT JOIN mescole_lines ml ON m.id = ml.idmescola
|
||||
LEFT JOIN production_lines pl ON ml.idlinea = pl.id
|
||||
GROUP BY m.id
|
||||
ORDER BY m.id DESC";
|
||||
$stmt = $pdo->query($sql);
|
||||
if ($stmt->rowCount() === 0) {
|
||||
echo "<tr><td colspan='2' class='text-muted'>Nessuna mescola presente</td></tr>";
|
||||
echo "<tr><td colspan='4' class='text-muted'>Nessuna mescola presente</td></tr>";
|
||||
} else {
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$linee = $row['linee'] ? htmlspecialchars($row['linee']) : '<span class="text-muted">Nessuna</span>';
|
||||
echo "<tr>
|
||||
<td>" . htmlspecialchars($row['id']) . "</td>
|
||||
<td>{$row['id']}</td>
|
||||
<td>" . htmlspecialchars($row['nome']) . "</td>
|
||||
<td>{$linee}</td>
|
||||
<td>
|
||||
<button class='btn btn-sm btn-outline-primary associa-linee'
|
||||
data-id='{$row['id']}'
|
||||
data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'>
|
||||
⚙️ Associa Linee
|
||||
</button>
|
||||
</td>
|
||||
</tr>";
|
||||
}
|
||||
}
|
||||
@ -163,9 +193,35 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODALE ASSOCIA LINEE -->
|
||||
<div class="modal fade" id="associaLineeModal" tabindex="-1" 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">Associa Linee alla Mescola</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="associaLineeForm">
|
||||
<input type="hidden" id="idMescolaLinee">
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold">Linee di Produzione</label>
|
||||
<select id="lineeSelect" name="linee[]" class="form-select" multiple required style="width:100%;"></select>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<button type="submit" class="btn btn-add">💾 Salva Associazioni</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include('jsinclude.php'); ?>
|
||||
|
||||
<script>
|
||||
// Attiva DataTables
|
||||
// Inizializza DataTables
|
||||
$(document).ready(function() {
|
||||
$('#tabellaMescole').DataTable({
|
||||
order: [
|
||||
@ -178,10 +234,10 @@
|
||||
});
|
||||
});
|
||||
|
||||
// Gestione inserimento con AJAX
|
||||
document.getElementById("addMescolaForm").addEventListener("submit", function(e) {
|
||||
// Inserimento mescola
|
||||
$("#addMescolaForm").on("submit", function(e) {
|
||||
e.preventDefault();
|
||||
const nome = document.getElementById("nomeMescola").value.trim();
|
||||
const nome = $("#nomeMescola").val().trim();
|
||||
|
||||
if (nome === "") {
|
||||
Swal.fire({
|
||||
@ -213,7 +269,81 @@
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: data.message || "Si è verificato un errore durante il salvataggio.",
|
||||
text: data.message || "Errore durante il salvataggio.",
|
||||
confirmButtonColor: "#d33"
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore di connessione",
|
||||
text: "Impossibile contattare il server.",
|
||||
confirmButtonColor: "#d33"
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Apertura modale Associa Linee
|
||||
$(document).on("click", ".associa-linee", function() {
|
||||
const idMescola = $(this).data("id");
|
||||
const nomeMescola = $(this).data("nome");
|
||||
$("#idMescolaLinee").val(idMescola);
|
||||
$(".modal-title").text("Associa Linee a " + nomeMescola);
|
||||
|
||||
fetch("get_linee_mescola.php?id=" + idMescola)
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
const select = $("#lineeSelect");
|
||||
select.empty();
|
||||
|
||||
data.tutte_linee.forEach(l => {
|
||||
const selected = data.associate.includes(l.id.toString()) ? "selected" : "";
|
||||
select.append(`<option value="${l.id}" ${selected}>${l.name} (${l.brand || ''})</option>`);
|
||||
});
|
||||
|
||||
select.select2({
|
||||
theme: "bootstrap-5",
|
||||
width: "100%",
|
||||
placeholder: "Seleziona o rimuovi linee di produzione",
|
||||
allowClear: true,
|
||||
closeOnSelect: false
|
||||
});
|
||||
|
||||
$("#associaLineeModal").modal("show");
|
||||
});
|
||||
});
|
||||
|
||||
// Salvataggio associazioni (aggiungi/rimuovi)
|
||||
$("#associaLineeForm").on("submit", function(e) {
|
||||
e.preventDefault();
|
||||
const idMescola = $("#idMescolaLinee").val();
|
||||
const linee = $("#lineeSelect").val() || []; // se deselezionate tutte, array vuoto
|
||||
|
||||
fetch("save_mescola_linee.php", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
idMescola,
|
||||
linee
|
||||
})
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
Swal.fire({
|
||||
icon: "success",
|
||||
title: "Aggiornato!",
|
||||
text: "Associazioni aggiornate correttamente.",
|
||||
confirmButtonColor: "#3085d6"
|
||||
}).then(() => location.reload());
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: data.message || "Errore durante l'aggiornamento.",
|
||||
confirmButtonColor: "#d33"
|
||||
});
|
||||
}
|
||||
@ -228,6 +358,7 @@
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -98,10 +98,10 @@
|
||||
|
||||
.dashboard-grid-bottom {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(200px, 1fr));
|
||||
grid-template-columns: repeat(3, minmax(200px, 1fr));
|
||||
gap: 25px 35px;
|
||||
width: 100%;
|
||||
max-width: 600px;
|
||||
max-width: 900px;
|
||||
justify-items: center;
|
||||
}
|
||||
|
||||
@ -156,17 +156,17 @@
|
||||
background: linear-gradient(135deg, #ff8585ff, #ff9d9dff);
|
||||
}
|
||||
|
||||
.btn-linee {
|
||||
background: linear-gradient(135deg, #b9e3ffff, #d7f1ffff);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.stats-row {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.dashboard-grid {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.dashboard-grid,
|
||||
.dashboard-grid-bottom {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 20px;
|
||||
@ -248,7 +248,7 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- ===== SECONDA RIGA BOTTONI (2 per riga) ===== -->
|
||||
<!-- ===== SECONDA RIGA BOTTONI (3 per riga) ===== -->
|
||||
<div class="dashboard-grid-bottom">
|
||||
<button class="dash-btn btn-mescole" onclick="location.href='mescole.php'">
|
||||
<div class="dash-icon">⚗️</div>
|
||||
@ -259,6 +259,11 @@
|
||||
<div class="dash-icon">🧩</div>
|
||||
<div>Matrici</div>
|
||||
</button>
|
||||
|
||||
<button class="dash-btn btn-linee" onclick="location.href='linee.php'">
|
||||
<div class="dash-icon">🏭</div>
|
||||
<div>Linee di Produzione</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
27
public/userarea/save_linea.php
Normal file
27
public/userarea/save_linea.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require_once __DIR__ . '/class/db-functions.php';
|
||||
|
||||
try {
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$lineNumber = $_POST['lineNumber'] ?? null;
|
||||
$name = $_POST['lineName'] ?? '';
|
||||
$model = $_POST['model'] ?? '';
|
||||
$brand = $_POST['brand'] ?? '';
|
||||
$status = $_POST['status'] ?? 'active';
|
||||
|
||||
if (!$lineNumber || !$name) {
|
||||
echo json_encode(['success' => false, 'message' => 'Numero linea e nome sono obbligatori.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO production_lines (line_number, name, model, brand, status)
|
||||
VALUES (?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$lineNumber, $name, $model, $brand, $status]);
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
@ -1,22 +1,31 @@
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
include('../class/db-functions.php');
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
if (!isset($_POST['nome']) || trim($_POST['nome']) === '') {
|
||||
throw new Exception("Nome matrice mancante.");
|
||||
}
|
||||
|
||||
$nome = trim($_POST['nome']);
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Inserisci nuova matrice
|
||||
$stmt = $pdo->prepare("INSERT INTO matrice (nome) VALUES (:nome)");
|
||||
$stmt->bindParam(':nome', $nome, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
$id = $_POST['id'] ?? null;
|
||||
$nome = trim($_POST['nome'] ?? '');
|
||||
|
||||
echo json_encode(["success" => true]);
|
||||
if ($nome === '') {
|
||||
echo json_encode(['success' => false, 'message' => 'Il nome della matrice è obbligatorio.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
// Aggiornamento
|
||||
$stmt = $pdo->prepare("UPDATE matrice SET nome = ? WHERE id = ?");
|
||||
$stmt->execute([$nome, $id]);
|
||||
echo json_encode(['success' => true, 'message' => 'Matrice aggiornata con successo.']);
|
||||
} else {
|
||||
// Inserimento
|
||||
$stmt = $pdo->prepare("INSERT INTO matrice (nome) VALUES (?)");
|
||||
$stmt->execute([$nome]);
|
||||
echo json_encode(['success' => true, 'message' => 'Matrice creata con successo.']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(["success" => false, "message" => $e->getMessage()]);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore: ' . $e->getMessage()]);
|
||||
}
|
||||
|
||||
27
public/userarea/save_matrice_linee.php
Normal file
27
public/userarea/save_matrice_linee.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
include('../class/db-functions.php');
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$idMatrice = intval($data['id']);
|
||||
$linee = $data['linee'] ?? [];
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Elimina tutte le precedenti associazioni
|
||||
$pdo->prepare("DELETE FROM matrice_lines WHERE idmatrice = ?")->execute([$idMatrice]);
|
||||
|
||||
// Inserisce le nuove associazioni
|
||||
if (!empty($linee)) {
|
||||
$stmt = $pdo->prepare("INSERT INTO matrice_lines (idmatrice, idlinea) VALUES (?, ?)");
|
||||
foreach ($linee as $idLinea) {
|
||||
$stmt->execute([$idMatrice, $idLinea]);
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode(['success' => true, 'message' => 'Associazioni linee aggiornate.']);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => 'Errore: ' . $e->getMessage()]);
|
||||
}
|
||||
27
public/userarea/save_matrice_mescole.php
Normal file
27
public/userarea/save_matrice_mescole.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
include('../class/db-functions.php');
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$idMatrice = intval($data['id']);
|
||||
$mescole = $data['mescole'] ?? [];
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Rimuove tutte le precedenti associazioni
|
||||
$pdo->prepare("DELETE FROM matrice_mescole WHERE idmatrice = ?")->execute([$idMatrice]);
|
||||
|
||||
// Inserisce le nuove
|
||||
if (!empty($mescole)) {
|
||||
$stmt = $pdo->prepare("INSERT INTO matrice_mescole (idmatrice, idmescola) VALUES (?, ?)");
|
||||
foreach ($mescole as $idMescola) {
|
||||
$stmt->execute([$idMatrice, $idMescola]);
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode(['success' => true, 'message' => 'Associazioni mescole aggiornate.']);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => 'Errore: ' . $e->getMessage()]);
|
||||
}
|
||||
27
public/userarea/save_mescola_linee.php
Normal file
27
public/userarea/save_mescola_linee.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
require_once(__DIR__ . '/class/db-functions.php');
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
$idMescola = (int)$data['idMescola'];
|
||||
$linee = $data['linee'] ?? [];
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Elimina tutte le associazioni esistenti
|
||||
$pdo->prepare("DELETE FROM mescole_lines WHERE idmescola = ?")->execute([$idMescola]);
|
||||
|
||||
// Reinserisci solo le selezionate
|
||||
if (!empty($linee)) {
|
||||
$stmt = $pdo->prepare("INSERT INTO mescole_lines (idmescola, idlinea) VALUES (?, ?)");
|
||||
foreach ($linee as $idLinea) {
|
||||
$stmt->execute([$idMescola, $idLinea]);
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
29
public/userarea/toggle_linea_status.php
Normal file
29
public/userarea/toggle_linea_status.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
require_once(__DIR__ . '/class/db-functions.php');
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
if (!isset($_GET['id']) || !isset($_GET['status'])) {
|
||||
echo json_encode(['success' => false, 'message' => 'Parametri mancanti.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = (int)$_GET['id'];
|
||||
$status = $_GET['status'] === 'active' ? 'active' : 'inactive';
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$stmt = $pdo->prepare("UPDATE production_lines SET status = ? WHERE id = ?");
|
||||
$stmt->execute([$status, $id]);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
echo json_encode(['success' => true]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => 'Nessuna modifica effettuata.']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => 'Errore: ' . $e->getMessage()]);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user