diff --git a/public/userarea/delete_linea.php b/public/userarea/delete_linea.php new file mode 100644 index 0000000..51b8fbb --- /dev/null +++ b/public/userarea/delete_linea.php @@ -0,0 +1,28 @@ + 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()]); +} diff --git a/public/userarea/delete_matrice.php b/public/userarea/delete_matrice.php new file mode 100644 index 0000000..60607a2 --- /dev/null +++ b/public/userarea/delete_matrice.php @@ -0,0 +1,26 @@ + 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()]); +} diff --git a/public/userarea/edit_linea.php b/public/userarea/edit_linea.php new file mode 100644 index 0000000..90264b3 --- /dev/null +++ b/public/userarea/edit_linea.php @@ -0,0 +1,166 @@ + + + + + + + + + + Modifica Linea di Produzione + + + + + + + + + + +
+ + + +
+
+
+
+
Modifica Linea
+ +
+ +
+ getConnection(); + + if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { + echo "
ID non valido.
"; + 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 "
Linea non trovata.
"; + exit; + } + ?> + +
+ + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+
+
+
+
+ + +
+ + + + + \ No newline at end of file diff --git a/public/userarea/get_linee_matrice.php b/public/userarea/get_linee_matrice.php new file mode 100644 index 0000000..946aee8 --- /dev/null +++ b/public/userarea/get_linee_matrice.php @@ -0,0 +1,28 @@ + 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()]); +} diff --git a/public/userarea/get_linee_mescola.php b/public/userarea/get_linee_mescola.php new file mode 100644 index 0000000..b79fdd6 --- /dev/null +++ b/public/userarea/get_linee_mescola.php @@ -0,0 +1,37 @@ +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() + ]); +} diff --git a/public/userarea/get_mescole_matrice.php b/public/userarea/get_mescole_matrice.php new file mode 100644 index 0000000..b7f933b --- /dev/null +++ b/public/userarea/get_mescole_matrice.php @@ -0,0 +1,27 @@ + 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()]); +} diff --git a/public/userarea/linee.php b/public/userarea/linee.php new file mode 100644 index 0000000..d47a4fd --- /dev/null +++ b/public/userarea/linee.php @@ -0,0 +1,327 @@ + + + + + + + + + + Gestione Linee di Produzione - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?> + + + + + + + + + + + + + + + +
+ + + +
+
+
+
+
Gestione Linee di Produzione
+ +
+ +
+
+
Elenco Linee
+ +
+ + +
+ + + + + + + + + + + + + + getConnection(); + $stmt = $pdo->query("SELECT * FROM production_lines ORDER BY line_number ASC"); + + if ($stmt->rowCount() === 0) { + echo ""; + } else { + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $badge = $row['status'] === 'active' + ? "Attiva" + : "Inattiva"; + + echo " + + + + + + + + "; + } + } + ?> + +
IDNumeroNomeModelloMarcaStatoAzioni
Nessuna linea di produzione presente
{$row['id']}{$row['line_number']}" . htmlspecialchars($row['name']) . "" . htmlspecialchars($row['model']) . "" . htmlspecialchars($row['brand']) . "{$badge} + + + +
+
+
+
+
+
+ + +
+ + + + + + + + + \ No newline at end of file diff --git a/public/userarea/matrici.php b/public/userarea/matrici.php index 743454b..235339e 100644 --- a/public/userarea/matrici.php +++ b/public/userarea/matrici.php @@ -9,7 +9,7 @@ Gestione Matrici - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?> - + @@ -19,6 +19,11 @@ + + + + + @@ -107,11 +135,12 @@
- +
- + + @@ -120,13 +149,19 @@ $pdo = $db->getConnection(); $stmt = $pdo->query("SELECT * FROM matrice ORDER BY id DESC"); if ($stmt->rowCount() === 0) { - echo ""; + echo ""; } else { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo " - - - "; + + + + "; } } ?> @@ -141,16 +176,17 @@ - +
IDID Nome MatriceAzioni
Nessuna matrice presente
Nessuna matrice presente
" . htmlspecialchars($row['id']) . "" . htmlspecialchars($row['nome']) . "
{$row['id']}" . htmlspecialchars($row['nome']) . " + + + + +
- + + + 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 ""; + echo ""; } else { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $linee = $row['linee'] ? htmlspecialchars($row['linee']) : 'Nessuna'; echo " - + + + "; } } @@ -163,9 +193,35 @@ + + + + + + \ No newline at end of file diff --git a/public/userarea/production_dashboard.php b/public/userarea/production_dashboard.php index 44fe552..0712b03 100644 --- a/public/userarea/production_dashboard.php +++ b/public/userarea/production_dashboard.php @@ -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 @@ - +
+ +
diff --git a/public/userarea/save_linea.php b/public/userarea/save_linea.php new file mode 100644 index 0000000..5caa081 --- /dev/null +++ b/public/userarea/save_linea.php @@ -0,0 +1,27 @@ +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()]); +} diff --git a/public/userarea/save_matrice.php b/public/userarea/save_matrice.php index 4fe1ad6..1f08424 100644 --- a/public/userarea/save_matrice.php +++ b/public/userarea/save_matrice.php @@ -1,22 +1,31 @@ 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()]); } diff --git a/public/userarea/save_matrice_linee.php b/public/userarea/save_matrice_linee.php new file mode 100644 index 0000000..0a44a2a --- /dev/null +++ b/public/userarea/save_matrice_linee.php @@ -0,0 +1,27 @@ +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()]); +} diff --git a/public/userarea/save_matrice_mescole.php b/public/userarea/save_matrice_mescole.php new file mode 100644 index 0000000..b6fdfda --- /dev/null +++ b/public/userarea/save_matrice_mescole.php @@ -0,0 +1,27 @@ +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()]); +} diff --git a/public/userarea/save_mescola_linee.php b/public/userarea/save_mescola_linee.php new file mode 100644 index 0000000..bb8d8b0 --- /dev/null +++ b/public/userarea/save_mescola_linee.php @@ -0,0 +1,27 @@ +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()]); +} diff --git a/public/userarea/toggle_linea_status.php b/public/userarea/toggle_linea_status.php new file mode 100644 index 0000000..cca8d54 --- /dev/null +++ b/public/userarea/toggle_linea_status.php @@ -0,0 +1,29 @@ + 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()]); +}
IDID Nome MescolaLinee AssociateAzioni
Nessuna mescola presente
Nessuna mescola presente
" . htmlspecialchars($row['id']) . "{$row['id']} " . htmlspecialchars($row['nome']) . "{$linee} + +