diff --git a/public/userarea/ajax_drag_programmazione.php b/public/userarea/ajax_drag_programmazione.php new file mode 100644 index 0000000..842ca80 --- /dev/null +++ b/public/userarea/ajax_drag_programmazione.php @@ -0,0 +1,136 @@ +getConnection(); + +$STATUS_PROGRAMMATO = 6; +$STATUS_DA_PROGRAMMARE = 1; + +$jsonFile = __DIR__ . "/data/production_priority.json"; + +/* ------------------------------- + JSON HELPERS +---------------------------------*/ +function loadPriority() +{ + global $jsonFile; + if (!file_exists($jsonFile)) return []; + return json_decode(file_get_contents($jsonFile), true) ?: []; +} + +function savePriority($arr) +{ + global $jsonFile; + file_put_contents($jsonFile, json_encode($arr, JSON_PRETTY_PRINT)); +} + +/* ------------------------------- + LOAD: PROGRAMMATI +---------------------------------*/ +if ($_GET['mode'] === 'planned') { + + $priority = loadPriority(); + $map = []; + foreach ($priority as $p) $map[$p['id']] = $p['priority']; + + $sql = "SELECT p.*, m.nome AS matrice, ms.nome AS mescola, + l.name AS linea, c.nome AS cliente + FROM productiondata p + LEFT JOIN matrice m ON p.idmatrice = m.id + LEFT JOIN mescole ms ON p.idmescola = ms.id + LEFT JOIN production_lines l ON p.id_linea = l.id + LEFT JOIN clients c ON p.id_cliente = c.id + WHERE p.id_status = :s"; + $stmt = $pdo->prepare($sql); + $stmt->execute(['s' => $STATUS_PROGRAMMATO]); + $rows = $stmt->fetchAll(); + + // Ordina per priority + usort($rows, function ($a, $b) use ($map) { + return ($map[$a['id']] ?? 9999) <=> ($map[$b['id']] ?? 9999); + }); + + ob_start(); + foreach ($rows as $r): + $prio = $map[$r['id']] ?? '-'; +?> + + + + + + + + + ob_get_clean()]); + exit; +} + +/* ------------------------------- + LOAD: DA PROGRAMMARE +---------------------------------*/ +if ($_GET['mode'] === 'to_plan') { + + $sql = "SELECT p.*, m.nome AS matrice, ms.nome AS mescola, + l.name AS linea, c.nome AS cliente + FROM productiondata p + LEFT JOIN matrice m ON p.idmatrice = m.id + LEFT JOIN mescole ms ON p.idmescola = ms.id + LEFT JOIN production_lines l ON p.id_linea = l.id + LEFT JOIN clients c ON p.id_cliente = c.id + WHERE p.id_status = :s + ORDER BY p.Data ASC"; + + $stmt = $pdo->prepare($sql); + $stmt->execute(['s' => $STATUS_DA_PROGRAMMARE]); + + ob_start(); + foreach ($stmt as $r): ?> + + + + + + + + ob_get_clean()]); + exit; +} + +/* ------------------------------- + UPDATE STATUS + PRIORITY +---------------------------------*/ +if ($_POST['mode'] === 'save') { + + $planned = json_decode($_POST['planned'], true); + $toPlan = json_decode($_POST['toPlan'], true); + + $pdo->beginTransaction(); + + // Aggiorna programmati + foreach ($planned as $i => $row) { + $id = $row['id']; + $stmt = $pdo->prepare("UPDATE productiondata SET id_status = :s WHERE id = :id"); + $stmt->execute(['s' => $STATUS_PROGRAMMATO, 'id' => $id]); + $priorityArr[] = ['id' => $id, 'priority' => $i + 1]; + } + + // Aggiorna da programmare + foreach ($toPlan as $row) { + $id = $row['id']; + $stmt = $pdo->prepare("UPDATE productiondata SET id_status = :s WHERE id = :id"); + $stmt->execute(['s' => $STATUS_DA_PROGRAMMARE, 'id' => $id]); + } + + $pdo->commit(); + + savePriority($priorityArr); + + echo json_encode(['success' => true]); + exit; +} diff --git a/public/userarea/ajax_update_priority.php b/public/userarea/ajax_update_priority.php new file mode 100644 index 0000000..f89efa4 --- /dev/null +++ b/public/userarea/ajax_update_priority.php @@ -0,0 +1,23 @@ +getConnection(); + +$programmati = json_decode($_POST["programmati"], true); +$daProgrammare = json_decode($_POST["daProgrammare"], true); + +$pdo->beginTransaction(); + +foreach ($programmati as $p) { + $stmt = $pdo->prepare("UPDATE productiondata SET id_status=6, priority=? WHERE id=?"); + $stmt->execute([$p["priority"], $p["id"]]); +} + +foreach ($daProgrammare as $id) { + $stmt = $pdo->prepare("UPDATE productiondata SET id_status=1, priority=NULL WHERE id=?"); + $stmt->execute([$id]); +} + +$pdo->commit(); + +echo json_encode(["success" => true]); diff --git a/public/userarea/components/photo_buttons.php b/public/userarea/components/photo_buttons.php new file mode 100644 index 0000000..1264a2e --- /dev/null +++ b/public/userarea/components/photo_buttons.php @@ -0,0 +1,27 @@ +
+ + + + + + + + + + +
\ No newline at end of file diff --git a/public/userarea/components/photo_modal.php b/public/userarea/components/photo_modal.php new file mode 100644 index 0000000..9cf5401 --- /dev/null +++ b/public/userarea/components/photo_modal.php @@ -0,0 +1,54 @@ + \ No newline at end of file diff --git a/public/userarea/edit_linea.php b/public/userarea/edit_linea.php index 90264b3..cae8e68 100644 --- a/public/userarea/edit_linea.php +++ b/public/userarea/edit_linea.php @@ -115,6 +115,11 @@ +
+ + +
diff --git a/public/userarea/get_photos.php b/public/userarea/get_photos.php new file mode 100644 index 0000000..22e1e99 --- /dev/null +++ b/public/userarea/get_photos.php @@ -0,0 +1,38 @@ +getConnection(); + + $production_id = isset($_GET['production_id']) ? (int)$_GET['production_id'] : 0; + $photo_type = $_GET['photo_type'] ?? ''; + + if ($production_id <= 0 || $photo_type === '') { + throw new Exception("Parametri non validi"); + } + + $stmt = $pdo->prepare(" + SELECT id, filename, photo_type, created_at, elaborato + FROM production_photos + WHERE production_id = :prod AND photo_type = :ptype + ORDER BY created_at DESC, id DESC + "); + $stmt->execute([ + ':prod' => $production_id, + ':ptype' => $photo_type + ]); + + $photos = $stmt->fetchAll(PDO::FETCH_ASSOC); + + echo json_encode([ + 'success' => true, + 'photos' => $photos + ]); +} catch (Exception $e) { + echo json_encode([ + 'success' => false, + 'message' => $e->getMessage() + ]); +} diff --git a/public/userarea/linee.php b/public/userarea/linee.php index d47a4fd..d4b7c3f 100644 --- a/public/userarea/linee.php +++ b/public/userarea/linee.php @@ -144,6 +144,7 @@ Nome Modello Marca + Colore Stato Azioni @@ -163,13 +164,19 @@ : "Inattiva"; echo " - {$row['id']} - {$row['line_number']} - " . htmlspecialchars($row['name']) . " - " . htmlspecialchars($row['model']) . " - " . htmlspecialchars($row['brand']) . " - {$badge} - + {$row['id']} + {$row['line_number']} + " . htmlspecialchars($row['name']) . " + " . htmlspecialchars($row['model']) . " + " . htmlspecialchars($row['brand']) . " + + +
+ + + {$badge} + + @@ -215,6 +222,12 @@
+
+ + +
+
diff --git a/public/userarea/photos/7-1-1763722707.png b/public/userarea/photos/7-1-1763722707.png new file mode 100644 index 0000000..b356a48 Binary files /dev/null and b/public/userarea/photos/7-1-1763722707.png differ diff --git a/public/userarea/photos/7-2-1763722707.png b/public/userarea/photos/7-2-1763722707.png new file mode 100644 index 0000000..b356a48 Binary files /dev/null and b/public/userarea/photos/7-2-1763722707.png differ diff --git a/public/userarea/photos/7-3-1763722718.png b/public/userarea/photos/7-3-1763722718.png new file mode 100644 index 0000000..762e7ff Binary files /dev/null and b/public/userarea/photos/7-3-1763722718.png differ diff --git a/public/userarea/photos/7-4-1763722718.png b/public/userarea/photos/7-4-1763722718.png new file mode 100644 index 0000000..762e7ff Binary files /dev/null and b/public/userarea/photos/7-4-1763722718.png differ diff --git a/public/userarea/photos/7-5-1763723161.png b/public/userarea/photos/7-5-1763723161.png new file mode 100644 index 0000000..fd0f090 Binary files /dev/null and b/public/userarea/photos/7-5-1763723161.png differ diff --git a/public/userarea/production_line_view.php b/public/userarea/production_line_view.php index 84c06df..802de43 100644 --- a/public/userarea/production_line_view.php +++ b/public/userarea/production_line_view.php @@ -4,7 +4,7 @@ $db = DBHandlerSelect::getInstance(); $pdo = $db->getConnection(); // --- LISTE LINEE --- -$linee = $pdo->query("SELECT id, name FROM production_lines ORDER BY line_number")->fetchAll(); +$linee = $pdo->query("SELECT id, name, color FROM production_lines ORDER BY line_number")->fetchAll(); // --- STATUS DINAMICI --- $statusProgrammato = $pdo->query("SELECT id, nome, badge_color, line_color FROM production_status WHERE id = 6 LIMIT 1")->fetch(); @@ -174,14 +174,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['save_final_data'])) exit; } +// --- AJAX: carica record giorno successivo --- +if (!empty($_GET['ajax_next'])) { -// --- AJAX: carica record --- -if (!empty($_GET['ajax'])) { $date = $_GET['date'] ?? date('Y-m-d'); $lineRaw = $_GET['line'] ?? ''; $lineArray = $lineRaw !== '' ? explode(',', $lineRaw) : []; - $sql = "SELECT p.*, m.nome AS matrice, @@ -210,94 +209,73 @@ if (!empty($_GET['ajax'])) { ':pausa' => $statusPausaId ]; - try { - $stmt = $pdo->prepare($sql); - $stmt->execute($params); - $records = $stmt->fetchAll(); - } catch (PDOException $e) { - echo '
Errore database.
'; - exit; + $stmt = $pdo->prepare($sql); + $stmt->execute($params); + + $recordsNext = $stmt->fetchAll(); + + if (empty($recordsNext)) { + exit; // ritorna vuoto } + foreach ($recordsNext as $r) { + include __DIR__ . "/render_production_card.php"; + } + + exit; +} + +// --- AJAX PRINCIPALE: carica i record della data selezionata --- +if (!empty($_GET['ajax'])) { + + $date = $_GET['date'] ?? date('Y-m-d'); + $lineRaw = $_GET['line'] ?? ''; + $lineArray = $lineRaw !== '' ? explode(',', $lineRaw) : []; + + $sql = "SELECT + p.*, + m.nome AS matrice, + ms.nome AS mescola, + l.name AS linea, + c.nome AS cliente, + s.nome AS status_nome, + s.badge_color, + s.line_color, + p.tempo_totale_produzione + FROM productiondata p + LEFT JOIN matrice m ON p.idmatrice = m.id + LEFT JOIN mescole ms ON p.idmescola = ms.id + LEFT JOIN production_lines l ON p.id_linea = l.id + LEFT JOIN clients c ON p.id_cliente = c.id + LEFT JOIN production_status s ON p.id_status = s.id + WHERE p.data_produzione = :date + AND p.id_status IN (:programmato, :produzione, :pausa)" + . (!empty($lineArray) ? " AND p.id_linea IN (" . implode(',', array_map('intval', $lineArray)) . ")" : "") + . " ORDER BY l.line_number, p.Data"; + + $params = [ + ':date' => $date, + ':programmato' => $statusProgrammatoId, + ':produzione' => $statusProduzioneId, + ':pausa' => $statusPausaId + ]; + + $stmt = $pdo->prepare($sql); + $stmt->execute($params); + $records = $stmt->fetchAll(); + if (empty($records)) { - echo '
- -
Nessuna produzione programmata, in corso o in pausa
-
'; exit; } foreach ($records as $r) { - $isInProduction = $r['id_status'] == $statusProduzioneId; - $isPaused = $r['id_status'] == $statusPausaId; - $dataZibo = ($r['data_zibo'] && $r['data_zibo'] !== '0000-00-00') ? date('d/m/Y', strtotime($r['data_zibo'])) : '-'; - $dataCliente = ($r['data_cliente'] && $r['data_cliente'] !== '0000-00-00') ? date('d/m/Y', strtotime($r['data_cliente'])) : '-'; - - $totalSeconds = (int)($r['tempo_totale_produzione'] ?? 0); - $startTime = ($isInProduction || $isPaused) && !empty($r['data_avvio']) && $r['data_avvio'] !== '0000-00-00 00:00:00' - ? strtotime($r['data_avvio'] . ' UTC') - : strtotime($r['Data'] . ' UTC'); - - $badgeColor = $r['badge_color'] ?? '#6c757d'; - $lineColor = $r['line_color'] ?? '#e9ecef'; - $statusNome = $r['status_nome']; -?> -
- - -
-
-
Linea
-
Matrice
-
Mescola
-
Cliente
-
Zibo
-
Data Cl.
-
Metri
-
Ore
-
-
- - - - -
-
- - -
- -
- 00:00:00 -
- - - - -
- - - - - - - -
- - - -
-
- @@ -617,6 +595,22 @@ if (!empty($_GET['ajax'])) { animation: slideUp 0.25s ease-out; } + /* MODALE GRANDE PER PREVIEW FOTO */ + .preview-large { + width: 95% !important; + max-width: 1200px !important; + max-height: 90vh !important; + padding: 0 !important; + background: black !important; + position: relative; + border-radius: 12px !important; + display: flex; + justify-content: center; + align-items: center; + } + + + /* animazione dolce */ @keyframes slideUp { from { @@ -667,17 +661,28 @@ if (!empty($_GET['ajax'])) { color: white; } + .line-btn { + flex: 0 0 150px; + padding: 0.8rem 0; + font-size: 1.4rem; + font-weight: 700; + border-radius: 0.8rem; + border: none; + cursor: pointer; + transition: 0.2s; + color: white; + } + .line-btn.active { - background: #dc2626; - /* rosso */ + background: var(--line-color); } .line-btn.inactive { - background: #cbd5e1; - /* grigio */ - color: #475569; + background: #cbd5e1 !important; + color: #475569 !important; } + /* Modale più grande e ottimizzata */ .modal-content.final-wide { width: 95%; @@ -729,6 +734,11 @@ if (!empty($_GET['ajax'])) { border: 1px solid #cbd5e1; margin-bottom: 1rem; } + + #imagePreviewModal .modal-content { + max-width: 1200px !important; + width: 95% !important; + } @@ -758,9 +768,11 @@ if (!empty($_GET['ajax'])) { + @@ -809,6 +821,10 @@ if (!empty($_GET['ajax'])) { + + + +