added drag and photos

This commit is contained in:
Claudio 2025-11-22 13:35:12 +01:00
parent eeb1d0d5de
commit 8edccbdfef
21 changed files with 2006 additions and 121 deletions

View File

@ -0,0 +1,136 @@
<?php
require_once(__DIR__ . "/class/db-functions.php");
$db = DBHandlerSelect::getInstance();
$pdo = $db->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']] ?? '-';
?>
<tr data-id="<?= $r['id'] ?>">
<td><strong><?= $prio ?></strong></td>
<td><?= date('d/m/Y', strtotime($r['Data'])) ?></td>
<td><?= $r['matrice'] ?></td>
<td><?= $r['mescola'] ?></td>
<td><?= $r['linea'] ?></td>
<td><?= $r['cliente'] ?? '-' ?></td>
</tr>
<?php
endforeach;
echo json_encode(['html' => 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): ?>
<tr data-id="<?= $r['id'] ?>">
<td><?= date('d/m/Y', strtotime($r['Data'])) ?></td>
<td><?= $r['matrice'] ?></td>
<td><?= $r['mescola'] ?></td>
<td><?= $r['linea'] ?></td>
<td><?= $r['cliente'] ?? '-' ?></td>
</tr>
<?php endforeach;
echo json_encode(['html' => 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;
}

View File

@ -0,0 +1,23 @@
<?php
require_once("include/headscript.php");
$db = DBHandlerSelect::getInstance();
$pdo = $db->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]);

View File

@ -0,0 +1,27 @@
<div class="photo-actions" style="margin-top:12px; display:flex; gap:12px;">
<!-- Lotto mescola -->
<button class="photo-btn"
data-type="lotto_mescola"
data-production="<?= $r['id'] ?>"
title="Foto Lotti Mescola">
<i class="bi bi-box-seam" style="font-size:1.8rem; color:#334155;"></i>
</button>
<!-- Parametri macchina -->
<button class="photo-btn"
data-type="parametri_macchina"
data-production="<?= $r['id'] ?>"
title="Foto Parametri Macchina">
<i class="bi bi-speedometer" style="font-size:1.8rem; color:#334155;"></i>
</button>
<!-- Problemi -->
<button class="photo-btn"
data-type="problema"
data-production="<?= $r['id'] ?>"
title="Foto Problemi">
<i class="bi bi-exclamation-triangle" style="font-size:1.8rem; color:#b91c1c;"></i>
</button>
</div>

View File

@ -0,0 +1,54 @@
<div id="photoModal" class="modal">
<div class="modal-content final-wide" style="max-width:800px; position:relative;">
<!-- X per chiudere -->
<button id="photoModalCloseX"
style="position:absolute; top:10px; right:15px; font-size:1.7rem; background:none; border:none; cursor:pointer;">
&times;
</button>
<h3 id="photoModalTitle">Carica Foto</h3>
<p id="photoModalSubtitle"></p>
<div id="photoMessageSuccess"
style="display:none; margin-bottom:10px; padding:8px 12px; border-radius:8px; background:#dcfce7; color:#166534; font-weight:500; text-align:left;">
Foto caricata correttamente.
</div>
<div id="photoMessageError"
style="display:none; margin-bottom:10px; padding:8px 12px; border-radius:8px; background:#fee2e2; color:#b91c1c; font-weight:500; text-align:left;">
⚠️ Errore durante il caricamento.
</div>
<form id="photoForm" enctype="multipart/form-data">
<input type="hidden" name="production_id" id="photoProductionId">
<input type="hidden" name="photo_type" id="photoType">
<div class="mb-3">
<label><strong>Carica o scatta una foto:</strong></label>
<input type="file" name="photo" accept="image/*;capture=camera"
class="input-big" required>
</div>
<div class="modal-buttons" style="margin-top:1.5rem;">
<button type="button" id="photoCancel" class="modal-btn modal-cancel">Annulla</button>
<button type="submit" class="modal-btn modal-confirm">Carica</button>
</div>
</form>
<hr style="margin:1.5rem 0;">
<h4 style="font-size:1rem; margin-bottom:0.7rem;">Foto già registrate per questa tipologia</h4>
<div id="photoGallery" class="photo-gallery"
style="display:flex; flex-wrap:wrap; gap:10px; max-height:220px; overflow-y:auto; padding:4px 0;">
<!-- thumbnails caricati via JS -->
</div>
</div>
</div>

View File

@ -115,6 +115,11 @@
<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="color" class="form-label fw-semibold">Colore Linea</label>
<input type="color" id="color" name="color" class="form-control form-control-color"
value="<?= htmlspecialchars($line['color'] ?? '#dc2626') ?>">
</div>
<div class="mb-3">
<label for="status" class="form-label fw-semibold">Stato</label>

View File

@ -0,0 +1,38 @@
<?php
header('Content-Type: application/json');
require_once __DIR__ . '/class/db-functions.php';
try {
$db = DBHandlerSelect::getInstance();
$pdo = $db->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()
]);
}

View File

@ -144,6 +144,7 @@
<th>Nome</th>
<th>Modello</th>
<th>Marca</th>
<th>Colore</th>
<th>Stato</th>
<th>Azioni</th>
</tr>
@ -163,13 +164,19 @@
: "<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>
<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>
<div style='width:28px; height:28px; border-radius:6px; border:1px solid #999; background: {$row['color']}; margin:auto;'></div>
</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>
@ -215,6 +222,12 @@
<label for="brand" class="form-label fw-semibold">Marca</label>
<input type="text" class="form-control" id="brand" name="brand">
</div>
<div class="mb-3">
<label for="color" class="form-label fw-semibold">Colore Linea</label>
<input type="color" class="form-control form-control-color"
id="color" name="color" value="#dc2626" title="Scegli colore">
</div>
<div class="text-center">
<button type="submit" class="btn btn-add">💾 Salva</button>
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

View File

@ -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 '<div class="no-records">Errore database.</div>';
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 '<div class="no-records">
<i class="bi bi-inbox"></i>
<div>Nessuna produzione programmata, in corso o in pausa</div>
</div>';
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'];
?>
<div class="record-card <?= $isInProduction || $isPaused ? 'in-production expanded' : 'programmed' ?>"
data-id="<?= $r['id'] ?>"
data-total-seconds="<?= $totalSeconds ?>"
data-kgsp="<?= htmlspecialchars($r['kg_sp']) ?>"
data-metri="<?= htmlspecialchars($r['metri']) ?>"
style="--line-bg: <?= $lineColor ?>; --badge-bg: <?= $badgeColor ?>;">
<!-- RIGA VISIBILE -->
<div class="record-summary">
<div class="summary-grid">
<div><strong>Linea</strong> <span><?= htmlspecialchars($r['linea']) ?></span></div>
<div><strong>Matrice</strong> <span><?= htmlspecialchars($r['matrice']) ?></span></div>
<div><strong>Mescola</strong> <span><?= htmlspecialchars($r['mescola']) ?></span></div>
<div><strong>Cliente</strong> <span><?= htmlspecialchars($r['cliente'] ?? '-') ?></span></div>
<div><strong>Zibo</strong> <span><?= $dataZibo ?></span></div>
<div><strong>Data Cl.</strong> <span><?= $dataCliente ?></span></div>
<div><strong>Metri</strong> <span><?= number_format($r['metri'], 2) ?></span></div>
<div><strong>Ore</strong> <span><?= number_format($r['ore_previste'], 1) ?></span></div>
</div>
<div class="status-badge" style="background: var(--badge-bg);">
<?= strtoupper($statusNome) ?>
<?php if ($isInProduction || $isPaused): ?>
<i class="bi bi-chevron-down expand-arrow"></i>
<?php endif; ?>
</div>
</div>
<!-- RIGA ESPANSA -->
<div class="record-expanded">
<?php if ($isInProduction || $isPaused): ?>
<div class="timer-display" data-start="<?= $startTime ?>">
<span class="timer">00:00:00</span>
</div>
<!-- Teorici invisibili per modale finale -->
<span data-field="kg_sp" style="display:none;"><?= $r['kg_sp'] ?></span>
<span data-field="metri" style="display:none;"><?= $r['metri'] ?></span>
<div class="action-buttons">
<?php if ($isInProduction): ?>
<button class="action-btn pause-btn" data-id="<?= $r['id'] ?>">PAUSA</button>
<button class="action-btn stop-btn" data-id="<?= $r['id'] ?>">STOP</button>
<?php elseif ($isPaused): ?>
<button class="action-btn resume-btn" data-id="<?= $r['id'] ?>">RIPRENDI</button>
<button class="action-btn stop-btn" data-id="<?= $r['id'] ?>">STOP</button>
<?php endif; ?>
</div>
<?php else: ?>
<button class="action-btn start-btn" data-id="<?= $r['id'] ?>">AVVIA PRODUZIONE</button>
<?php endif; ?>
</div>
</div>
<?php
include __DIR__ . "/render_production_card.php";
}
exit;
}
?>
<!doctype html>
@ -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;
}
</style>
</head>
@ -758,9 +768,11 @@ if (!empty($_GET['ajax'])) {
<?php foreach ($linee as $l): ?>
<button
class="line-btn active"
data-line="<?= $l['id'] ?>">
data-line="<?= $l['id'] ?>"
style="--line-color: <?= htmlspecialchars($l['color']) ?>;">
<?= htmlspecialchars($l['name']) ?>
</button>
<?php endforeach; ?>
</div>
@ -809,6 +821,10 @@ if (!empty($_GET['ajax'])) {
</div>
</div>
<!-- Modal foto -->
<?php include __DIR__ . "/components/photo_modal.php"; ?>
<!-- Modal dati fine produzione -->
<div id="finalDataModal" class="modal">
<div class="modal-content final-wide">
@ -868,6 +884,128 @@ if (!empty($_GET['ajax'])) {
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).on("mousedown", function(e) {
// 🔥 Se clicco sulla X, non chiudere altri modali
if ($(e.target).attr("id") === "previewCloseX") {
return;
}
// --- Se il PREVIEW è aperto ---
if ($("#imagePreviewModal").hasClass("active")) {
// click fuori → chiudi SOLO il preview
if ($(e.target).closest("#imagePreviewModal .modal-content").length === 0) {
$("#imagePreviewModal").removeClass("active");
}
return; // 🔥 BLOCCA la chiusura del photoModal
}
// --- Se è aperto solo il PHOTO MODAL ---
if ($("#photoModal").hasClass("active")) {
if ($(e.target).closest("#photoModal .modal-content").length === 0) {
$("#photoModal").removeClass("active");
}
}
});
function showPhotoSuccess() {
$("#photoMessageError").hide();
$("#photoMessageSuccess").fadeIn(150);
setTimeout(() => {
$("#photoMessageSuccess").fadeOut(200);
}, 2000);
}
function showPhotoError(msg) {
$("#photoMessageSuccess").hide();
$("#photoMessageError").text("⚠️ " + msg).fadeIn(150);
}
function loadPhotoGallery(productionId, type) {
$("#photoGallery").html('<div style="color:#64748b;">Caricamento foto...</div>');
$.getJSON("get_photos.php", {
production_id: productionId,
photo_type: type
}, function(r) {
if (!r.success) {
$("#photoGallery").html(
'<div style="color:#b91c1c;">Errore nel caricamento delle foto.</div>'
);
return;
}
const photos = r.photos || [];
if (photos.length === 0) {
$("#photoGallery").html(
'<div style="color:#64748b;">Nessuna foto registrata per questa tipologia.</div>'
);
return;
}
let html = "";
photos.forEach(p => {
const aiLabel = p.ai_processed == 1 ? ' (AI✔)' : '';
html += `
<div style="width:90px; text-align:center; font-size:0.7rem;">
<div class="photo-thumb"
data-full="photos/${p.filename}"
style="width:90px; height:70px; border-radius:8px; overflow:hidden; border:1px solid #e2e8f0; margin-bottom:4px; cursor:pointer;">
<img src="photos/${p.filename}"
alt="photo"
style="width:100%; height:100%; object-fit:cover;">
</div>
<div style="color:#475569; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">
#${p.id}${aiLabel}
</div>
</div>
`;
});
$("#photoGallery").html(html);
}).fail(function() {
$("#photoGallery").html(
'<div style="color:#b91c1c;">Errore di connessione nel caricamento delle foto.</div>'
);
});
}
// APRI PREVIEW — evento CLICK (non mousedown)
$(document).on("click", ".photo-thumb", function(e) {
e.stopPropagation(); // evita che il click chiuda subito il modale
const fullImage = $(this).data("full");
$("#previewImage").attr("src", fullImage);
$("#imagePreviewModal").addClass("active");
});
// chiusura preview con X
$("#previewCloseX").on("click", function(e) {
e.preventDefault();
e.stopImmediatePropagation(); // 🔥 blocca davvero tutto
$("#imagePreviewModal").removeClass("active");
});
// chiusura modale principale (upload foto)
$("#photoModalCloseX").on("click", function() {
$("#photoModal").removeClass("active");
});
</script>
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<?php include('jsinclude.php'); ?>
<script>
@ -940,10 +1078,105 @@ if (!empty($_GET['ajax'])) {
date: isoDate,
line: line
}, function(html) {
$('#recordsContainer').html(html);
// Il primo HTML (oggi / data selezionata)
let htmlOggi = html;
// Ora carichiamo DOMANI
const dateObj = new Date(isoDate);
dateObj.setDate(dateObj.getDate() + 1);
const tomorrow = dateObj.toISOString().split('T')[0];
$.get('', {
ajax_next: 1,
date: tomorrow,
line: line
}, function(htmlNext) {
let titoloNext = `
<div style="margin:20px 0; font-size:1.4rem; font-weight:700; color:#1e40af;">
Programmazione giorno successivo (${formatItalianDate(tomorrow)})
</div>
`;
$('#recordsContainer').html(
htmlOggi +
(htmlNext.trim() !== '' ? titoloNext + htmlNext : '')
);
startAllTimers();
setupEventHandlers();
});
startAllTimers();
setupEventHandlers();
$(document).on("click", ".photo-btn", function(e) {
e.stopPropagation();
const type = $(this).data("type");
const production = $(this).data("production");
$("#photoType").val(type);
$("#photoProductionId").val(production);
let titles = {
lotto_mescola: "Foto Lotto Mescola",
parametri_macchina: "Foto Parametri Macchina",
problema: "Foto Problema di Produzione"
};
$("#photoModalTitle").text(titles[type] || "Carica Foto");
$("#photoModalSubtitle").text("Produzione ID: " + production);
// pulisci messaggi
$("#photoMessageSuccess").hide();
$("#photoMessageError").hide();
// carica galleria foto esistenti per questo record + tipologia
loadPhotoGallery(production, type);
$("#photoModal").addClass("active");
});
$("#photoCancel").on("click", () => {
$("#photoModal").removeClass("active");
});
// --- SUBMIT FORM FOTO ---
$("#photoForm").off("submit").on("submit", function(e) {
e.preventDefault();
let formData = new FormData(this);
$.ajax({
url: "upload_photo.php",
type: "POST",
data: formData,
processData: false,
contentType: false,
dataType: "json",
success: function(r) {
if (r.success) {
// conferma + refresh galleria
showPhotoSuccess();
loadPhotoGallery(
$("#photoProductionId").val(),
$("#photoType").val()
);
} else {
showPhotoError(r.message || "Errore durante il caricamento della foto.");
}
},
error: function() {
showPhotoError("Errore di comunicazione con il server.");
}
});
});
$('.record-card.in-production').each(function() {
const $card = $(this);
const $expanded = $card.find('.record-expanded');
@ -1009,6 +1242,20 @@ if (!empty($_GET['ajax'])) {
});
}
// --- CONVERT DATE ---
function formatItalianDate(isoDate) {
const months = [
"gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno",
"luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre"
];
const d = new Date(isoDate);
const day = d.getDate();
const month = months[d.getMonth()];
const year = d.getFullYear();
return `${day} ${month} ${year}`;
}
// --- MODALE UNIFICATA PER TUTTE LE AZIONI ---
function showReasonModal(action, id) {
$('#reasonModal').addClass('active');
@ -1234,6 +1481,42 @@ if (!empty($_GET['ajax'])) {
});
</script>
<!-- MODALE PER PREVIEW IMMAGINE -->
<div id="imagePreviewModal" class="modal">
<div class="modal-content preview-large">
<!-- X per chiudere -->
<button id="previewCloseX"
style="
position:absolute;
top:10px;
right:15px;
font-size:2rem;
color:white;
background:none;
border:none;
cursor:pointer;
z-index:9999; /* 🔥 aggiungi questo */
">
&times;
</button>
<img id="previewImage"
src=""
style="
max-width: 95%;
max-height: 85vh;
width: auto;
height: auto;
display: block;
margin: auto;
border-radius: 6px;
">
</div>
</div>
</body>
</html>

View File

@ -203,6 +203,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
font-size: 0.75rem !important;
padding: 0.15rem 0.3rem !important;
}
.line-filter-btn {
font-size: 0.9rem;
padding: 0.375rem 0.75rem;
}
.line-filter-btn.active {
background-color: #0d6efd !important;
color: white !important;
}
</style>
</head>
@ -213,9 +223,33 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
<div class="page-wrapper">
<div class="page-content">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<div class="card-header d-flex justify-content-between align-items-center flex-wrap gap-3">
<h5 class="mb-0">Programmazione Produzione</h5>
<div>
<div class="d-flex align-items-center gap-2 flex-wrap">
<!-- FILTRO STATUS (dropdown) -->
<div style="min-width:200px;">
<select id="filterStatus"
class="form-select form-select-sm"
style="width:200px;">
<option value="">Tutti gli status</option>
<?php foreach ($status_list as $s): ?>
<option value="<?= $s['id'] ?>">
<?= htmlspecialchars($s['nome']) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<!-- BOTTONI FILTRO LINEA -->
<div class="btn-group me-3" role="group">
<button type="button" class="btn btn-outline-primary line-filter-btn active" data-line="">Tutte</button>
<?php foreach ($linee as $l): ?>
<button type="button" class="btn btn-outline-primary line-filter-btn" data-line="<?= $l['id'] ?>">
<?= htmlspecialchars($l['name']) ?>
</button>
<?php endforeach; ?>
</div>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#modalNuovo">Aggiungi</button>
<button class="btn btn-secondary" onclick="location.href='production_dashboard.php'">Torna</button>
</div>
@ -472,6 +506,45 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
}
});
// FILTRO RAPIDO PER LINEA CON BOTTONI
$(document).on('click', '.line-filter-btn', function() {
$('.line-filter-btn').removeClass('active').addClass('btn-outline-primary');
$(this).addClass('active').removeClass('btn-outline-primary');
const lineaId = $(this).data('line') || '';
table.column(3).search(lineaId ? '^' + lineaId + '$' : '', true, false).draw();
});
// FILTRO STATUS (dropdown)
$('#filterStatus').on('change', function() {
const statusId = $(this).val() || '';
// colonna STATUS = indice 13
table.column(13).search(
statusId ? '^' + statusId + '$' : '',
true, // usa regex
false // no smart search
).draw();
});
// Aggiungi al bottone "Pulisci" anche la rimozione filtro linea
$(document).on('click', '.btn-clear-filters', function() {
table.columns().search('').draw();
$('.filters-row input[type="text"]').val('');
$('.filters-row select').val('').trigger('change');
// reset dropdown status
$('#filterStatus').val('').trigger('change');
$('.filters-row input[placeholder*="aaaa"]').each(function() {
const fp = $(this).data('flatpickr');
if (fp) fp.clear();
});
$('.dataTables_filter input').val('');
// Reset bottoni linea
$('.line-filter-btn').removeClass('active').addClass('btn-outline-primary');
$('.line-filter-btn[data-line=""]').addClass('active');
});
// --- FUNZIONE PULISCI TUTTI I FILTRO ---
$(document).on('click', '.btn-clear-filters', function() {
// Svuota tutti i filtri DataTables

View File

@ -0,0 +1,994 @@
<?php
include('include/headscript.php');
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
// --- LISTE SELECT ---
$matrici = $pdo->query("SELECT id, nome FROM matrice ORDER BY nome")->fetchAll();
$mescole = $pdo->query("SELECT id, nome FROM mescole ORDER BY nome")->fetchAll();
$linee = $pdo->query("SELECT id, line_number, name FROM production_lines ORDER BY line_number")->fetchAll();
$clienti = $pdo->query("SELECT id, nome FROM clients ORDER BY nome")->fetchAll();
$status_list = $pdo->query("SELECT id, nome, badge_color, line_color FROM production_status ORDER BY ordinamento, nome")->fetchAll();
function selectOptions($arr, $sel = null, $val = 'id', $txt = 'nome')
{
$opt = '';
foreach ($arr as $a) {
$selected = ($sel !== null && $a[$val] == $sel) ? 'selected' : '';
$opt .= "<option value='{$a[$val]}' $selected>" . htmlspecialchars($a[$txt]) . "</option>";
}
return $opt;
}
// --- SALVATAGGIO INLINE ---
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
$action = $_POST['action'];
$data = [
'Data' => $_POST['Data'],
'idmatrice' => $_POST['idmatrice'],
'idmescola' => $_POST['idmescola'],
'id_linea' => $_POST['id_linea'],
'id_cliente' => $_POST['id_cliente'] ?: null,
'data_zibo' => $_POST['data_zibo'] ?: null,
'data_cliente' => $_POST['data_cliente'] ?: null,
'metri' => $_POST['metri'] ?: 0,
'kg_sp' => $_POST['kg_sp'] ?: 0,
'kg_p' => $_POST['kg_p'] ?: 0,
'ore_previste' => $_POST['ore_previste'] ?: 0,
'note_extra' => $_POST['note_extra'] ?: null,
'data_produzione' => $_POST['data_produzione'],
'id_status' => $_POST['id_status'] ?? 1
];
try {
if ($action === 'insert') {
$sql = "INSERT INTO productiondata
(Data, idmatrice, idmescola, id_linea, id_cliente, data_zibo, data_cliente, metri, kg_sp, kg_p, ore_previste, note_extra, data_produzione, id_status)
VALUES
(:Data, :idmatrice, :idmescola, :id_linea, :id_cliente, :data_zibo, :data_cliente, :metri, :kg_sp, :kg_p, :ore_previste, :note_extra, :data_produzione, :id_status)";
$stmt = $pdo->prepare($sql);
$stmt->execute($data);
echo json_encode(['success' => true]);
} elseif ($action === 'update' && !empty($_POST['id'])) {
$data['id'] = $_POST['id'];
$sql = "UPDATE productiondata SET
Data=:Data, idmatrice=:idmatrice, idmescola=:idmescola, id_linea=:id_linea,
id_cliente=:id_cliente, data_zibo=:data_zibo, data_cliente=:data_cliente,
metri=:metri, kg_sp=:kg_sp, kg_p=:kg_p, ore_previste=:ore_previste,
note_extra=:note_extra, data_produzione=:data_produzione, id_status=:id_status
WHERE id = :id";
$stmt = $pdo->prepare($sql);
$stmt->execute($data);
echo json_encode(['success' => true]);
}
exit;
} catch (Exception $e) {
echo json_encode(['success' => false, 'msg' => $e->getMessage()]);
exit;
}
}
?>
<!doctype html>
<html lang="it">
<head>
<?php include('cssinclude.php'); ?>
<title>Programmazione Produzione - <?= $titlewebsite ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
<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">
<link href="https://cdn.datatables.net/1.13.7/css/dataTables.bootstrap5.min.css" rel="stylesheet">
<link href="https://cdn.datatables.net/responsive/2.5.0/css/responsive.bootstrap5.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<style>
.inline-edit {
display: none;
}
.btn-xs {
padding: 0.15rem 0.35rem;
font-size: 0.7rem;
line-height: 1.2;
border-radius: .4rem;
}
.btn-xs i {
font-size: 0.85rem;
}
.table td,
.table th {
vertical-align: middle;
}
.table th {
background: #f8f9fa;
font-weight: 600;
}
.modal-xl {
max-width: 95% !important;
}
.table-responsive {
min-height: 400px;
}
#tabProgrammazione {
width: 100% !important;
}
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
border-radius: 0.375rem;
border: 1px solid #ced4da;
}
.dataTables_wrapper .dataTables_filter {
float: right;
}
.dataTables_wrapper .dataTables_length {
float: left;
}
.dataTables_wrapper .dataTables_info {
float: left;
}
.dataTables_wrapper .dataTables_paginate {
float: right;
}
.btn-clear-filters {
margin-left: 0.5rem;
padding: 0.25rem 0.5rem;
font-size: 0.75rem;
}
.badge {
padding: .35em .65em;
font-size: .75rem;
border-radius: .4rem;
}
/* FILTRI SOPRA: TESTO PICCOLO */
.filters-row th {
padding: 0.4rem 0.3rem !important;
}
.filters-row input,
.filters-row select {
font-size: 0.75rem !important;
padding: 0.15rem 0.3rem !important;
height: auto !important;
}
.filters-row .select2-container {
font-size: 0.75rem !important;
}
.filters-row .select2-container--bootstrap-5 .select2-selection {
min-height: 28px !important;
padding: 0.1rem 0.3rem !important;
font-size: 0.75rem !important;
}
.select2-container--bootstrap-5 .select2-dropdown .select2-results__option {
font-size: 0.75rem !important;
padding: 0.2rem 0.5rem !important;
}
.select2-container--bootstrap-5 .select2-selection__placeholder {
font-size: 0.75rem !important;
}
/* ICONA NOTE */
.note-icon {
font-size: 1.1rem;
cursor: pointer;
transition: color 0.2s;
color: #6c757d;
}
.note-icon.has-note {
color: #dc3545 !important;
}
.note-icon:hover {
color: #0056b3;
}
#modalNoteView .modal-body {
white-space: pre-wrap;
max-height: 60vh;
overflow-y: auto;
font-size: 0.95rem;
}
/* Flatpickr nei filtri */
.flatpickr-input {
font-size: 0.75rem !important;
padding: 0.15rem 0.3rem !important;
}
.line-filter-btn {
font-size: 0.9rem;
padding: 0.375rem 0.75rem;
}
.line-filter-btn.active {
background-color: #0d6efd !important;
color: white !important;
}
.special-row,
.special-row td {
background-color: var(--rowcolor) !important;
}
/* FULLSCREEN BACKDROP */
#photoModal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.65);
z-index: 99999;
justify-content: center;
align-items: center;
}
/* CENTRATURA CONTENUTO */
#photoModal .modal-content {
background: white;
border-radius: 10px;
padding: 20px;
max-height: 90vh;
overflow-y: auto;
animation: fadeIn 0.25s ease-out;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: scale(0.95);
}
to {
opacity: 1;
transform: scale(1);
}
}
/* MINIATURA FOTO */
.photo-gallery img {
width: 110px;
height: 110px;
object-fit: cover;
border-radius: 8px;
cursor: pointer;
transition: transform 0.2s;
}
.photo-gallery img:hover {
transform: scale(1.05);
}
</style>
</head>
<body>
<div class="wrapper">
<?php include('include/navbar.php');
include('include/topbar.php'); ?>
<div class="page-wrapper">
<div class="page-content">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center flex-wrap gap-3">
<h5 class="mb-0">Programmazione Produzione</h5>
<div class="d-flex align-items-center gap-2 flex-wrap">
<!-- BOTTONI FILTRO LINEA -->
<div class="btn-group me-3" role="group">
<button type="button" class="btn btn-outline-primary line-filter-btn active" data-line="">Tutte</button>
<?php foreach ($linee as $l): ?>
<button type="button" class="btn btn-outline-primary line-filter-btn" data-line="<?= $l['id'] ?>">
<?= htmlspecialchars($l['name']) ?>
</button>
<?php endforeach; ?>
</div>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#modalNuovo">Aggiungi</button>
<button class="btn btn-secondary" onclick="location.href='production_dashboard.php'">Torna</button>
</div>
</div>
<?php
// CARICO TUTTE LE RIGHE UNA SOLA VOLTA
$sql = "SELECT
p.*,
m.nome AS matrice,
ms.nome AS mescola,
l.name AS linea,
c.nome AS cliente,
s.nome AS status_nome,
COALESCE(s.badge_color, '#6c757d') AS badge_color,
COALESCE(s.line_color, '#ffffff') AS line_color
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
ORDER BY p.priority ASC, p.data_produzione ASC, p.Data ASC";
$rows = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
?>
<div class="card-body pt-0">
<div class="table-responsive">
<?php
$rows_special = array_filter($rows, function ($r) {
return in_array($r['id_status'], [2, 7, 8]);
});
?>
<!-- tabella speciao -->
<?php if (!empty($rows_special)): ?>
<h5 class="mt-3 mb-2">In Produzione / Pausa / Problema</h5>
<table id="tabSpecial" class="table table-hover align-middle" style="width:100%">
<thead>
<tr>
<th>Matrice</th>
<th>Mescola</th>
<th>Linea</th>
<th>Cliente</th>
<th>Data Zibo</th>
<th>Data Cliente</th>
<th>Timer</th>
<th>Status</th>
<th>Foto</th>
</tr>
</thead>
<tbody>
<?php foreach ($rows_special as $r): ?>
<?php $sec = intval($r['tempo_totale_produzione'] ?? 0); ?>
<tr class="special-row"
data-id="<?= $r['id'] ?>"
data-seconds="<?= $sec ?>"
style="--rowcolor: <?= $r['line_color'] ?>;">
<td><?= htmlspecialchars($r['matrice']) ?></td>
<td><?= htmlspecialchars($r['mescola']) ?></td>
<td data-line-id="<?= $r['id_linea'] ?>"><?= htmlspecialchars($r['linea']) ?></td>
<td><?= htmlspecialchars($r['cliente']) ?></td>
<td><?= htmlspecialchars($r['data_zibo']) ?></td>
<td><?= htmlspecialchars($r['data_cliente']) ?></td>
<!-- TIMER -->
<td class="timer" id="timer-<?= $r['id'] ?>">
<?= gmdate("H:i:s", $sec) ?>
</td>
<!-- BADGE -->
<td>
<span class="badge" style="background: <?= $r['badge_color'] ?>;">
<?= htmlspecialchars($r['status_nome']) ?>
</span>
</td>
<!-- FOTO ICONS -->
<td class="text-center" style="white-space: nowrap;">
<i class="bi bi-camera-fill photo-btn me-2"
data-type="lotto_mescola"
data-production="<?= $r['id'] ?>"
style="font-size:1.3rem; cursor:pointer;"></i>
<i class="bi bi-gear-fill photo-btn me-2"
data-type="parametri_macchina"
data-production="<?= $r['id'] ?>"
style="font-size:1.3rem; cursor:pointer;"></i>
<i class="bi bi-exclamation-triangle-fill photo-btn"
data-type="problema"
data-production="<?= $r['id'] ?>"
style="font-size:1.3rem; cursor:pointer; color:#b91c1c;"></i>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<hr class="my-4">
<?php endif; ?>
<!-- ========================= -->
<!-- TABELLA PROGRAMMATI -->
<!-- ========================= -->
<h5 class="mt-3 mb-2">Programmati</h5>
<table id="tabProgrammati" class="table table-hover align-middle" style="width:100%">
<thead>
<tr>
<th>Priority</th>
<th>Matrice</th>
<th>Mescola</th>
<th>Linea</th>
<th>Cliente</th>
<th>Data Zibo</th>
<th>Data Cliente</th>
<th>mt</th>
<th>kg sp</th>
<th>kg p</th>
<th>Ore</th>
<th>Note</th>
<th>Prod.</th>
<th>Status</th>
<th style="width: 80px;">Azioni</th>
</tr>
</thead>
<tbody id="programmatiBlock">
<?php foreach ($rows as $r): ?>
<?php if ($r['id_status'] != 6) continue; ?>
<tr data-id="<?= $r['id'] ?>" data-status="6" data-priority="<?= $r['priority'] ?? '' ?>"
style="background-color: <?= $r['line_color'] ?> !important;">
<?php include 'row_production.php'; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<!-- ========================= -->
<!-- TABELLA DA PROGRAMMARE -->
<!-- ========================= -->
<h5 class="mt-5 mb-2">Da Programmare</h5>
<table id="tabDaProgrammare" class="table table-hover align-middle" style="width:100%">
<thead>
<tr>
<th>Data</th>
<th>Matrice</th>
<th>Mescola</th>
<th>Linea</th>
<th>Cliente</th>
<th>Data Zibo</th>
<th>Data Cliente</th>
<th>mt</th>
<th>kg sp</th>
<th>kg p</th>
<th>Ore</th>
<th>Note</th>
<th>Prod.</th>
<th>Status</th>
<th style="width: 80px;">Azioni</th>
</tr>
</thead>
<tbody id="daProgrammareBlock">
<?php foreach ($rows as $r): ?>
<?php if ($r['id_status'] != 1) continue; ?>
<tr data-id="<?= $r['id'] ?>" data-status="1"
style="background-color: <?= $r['line_color'] ?> !important;">
<?php include 'row_production.php'; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?php include('include/footer.php'); ?>
</div>
<!-- MODALE VISUALIZZAZIONE NOTE -->
<div class="modal fade" id="modalNoteView" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Note Extra</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="noteContent">
<!-- Contenuto caricato via JS -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Chiudi</button>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.full.min.js"></script>
<script src="https://cdn.datatables.net/1.13.7/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.7/js/dataTables.bootstrap5.min.js"></script>
<script src="https://cdn.datatables.net/responsive/2.5.0/js/dataTables.responsive.min.js"></script>
<script src="https://cdn.datatables.net/responsive/2.5.0/js/responsive.bootstrap5.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<?php include('jsinclude.php'); ?>
<script>
$(function() {
const table1 = $('#tabProgrammati').DataTable({
responsive: true,
language: {
url: 'https://cdn.datatables.net/plug-ins/1.13.7/i18n/it-IT.json'
},
pageLength: 25
});
const table2 = $('#tabDaProgrammare').DataTable({
responsive: true,
language: {
url: 'https://cdn.datatables.net/plug-ins/1.13.7/i18n/it-IT.json'
},
pageLength: 25
});
// FILTRO RAPIDO PER LINEA CON BOTTONI
$(document).on('click', '.line-filter-btn', function() {
$(".line-filter-btn").removeClass("active").addClass("btn-outline-primary");
$(this).addClass("active").removeClass("btn-outline-primary");
const lineId = $(this).data("line");
$("#tabProgrammati tbody tr").each(function() {
const rowLine = $(this).find("td[data-line-id]").data("line-id");
if (!lineId || lineId == rowLine) {
$(this).show();
} else {
$(this).hide();
}
});
});
// Aggiungi al bottone "Pulisci" anche la rimozione filtro linea
$(document).on('click', '.btn-clear-filters', function() {
table.columns().search('').draw();
$('.filters-row input[type="text"]').val('');
$('.filters-row select').val('').trigger('change');
// reset dropdown status
$('.filters-row input[placeholder*="aaaa"]').each(function() {
const fp = $(this).data('flatpickr');
if (fp) fp.clear();
});
$('.dataTables_filter input').val('');
// Reset bottoni linea
$('.line-filter-btn').removeClass('active').addClass('btn-outline-primary');
$('.line-filter-btn[data-line=""]').addClass('active');
});
// --- FUNZIONE PULISCI TUTTI I FILTRO ---
$(document).on('click', '.btn-clear-filters', function() {
// Svuota tutti i filtri DataTables
table.columns().search('').draw();
// Svuota campi testo
$('.filters-row input[type="text"]').val('');
// Svuota select
$('.filters-row select').val('').trigger('change');
// Svuota Flatpickr (date inputs)
$('.filters-row input[placeholder*="aaaa"]').each(function() {
const fpInstance = $(this).data('flatpickr');
if (fpInstance) {
fpInstance.clear();
fpInstance.setDate('');
} else {
$(this).val('');
}
});
// Svuota search principale
$('.dataTables_filter input').val('');
});
// --- APERTURA MODALE NOTE ---
$(document).on('click', '.note-icon', function() {
const note = $(this).data('note') || '';
$('#noteContent').text(note || '(Nessuna nota)');
});
// --- INLINE EDIT ---
let original = {};
$('#tabProgrammazione').on('click', '.edit-row', function() {
const tr = $(this).closest('tr');
original = tr.find('.view').map((i, e) => $(e).html()).get();
tr.find('.view').hide();
tr.find('.inline-edit').show();
tr.find('.edit-row').addClass('d-none');
tr.find('.save-row, .cancel-row').removeClass('d-none');
tr.find('.inline-edit.select2').each(function() {
if (!$(this).hasClass('select2-hidden-accessible')) {
$(this).select2({
theme: 'bootstrap-5',
width: '100%'
});
}
});
});
$('#tabProgrammazione').on('click', '.cancel-row', function() {
const tr = $(this).closest('tr');
tr.find('.view').show().each((i, e) => $(e).html(original[i]));
tr.find('.inline-edit').hide();
tr.find('.edit-row').removeClass('d-none');
tr.find('.save-row, .cancel-row').addClass('d-none');
tr.find('.inline-edit.select2').select2('destroy');
});
$('#tabProgrammazione').on('click', '.save-row', function() {
const tr = $(this).closest('tr');
const data = tr.find('.inline-edit').serializeArray();
data.push({
name: 'action',
value: 'update'
}, {
name: 'id',
value: tr.data('id')
});
$.post('', data, r => r.success ? location.reload() : alert(r.msg || 'Errore'), 'json');
});
// --- ELIMINAZIONE ---
let deleteRow;
$('#tabProgrammazione').on('click', '.delete-row', function(e) {
e.preventDefault();
deleteRow = $(this).closest('tr');
$('#deleteId').val(deleteRow.data('id'));
const md = bootstrap.Modal.getOrCreateInstance(document.getElementById('modalDelete'));
md.show();
});
$('#confirmDelete').on('click', function() {
const id = $('#deleteId').val();
$.post('delete_productiondata.php', {
id
}, function(r) {
if (r.success) {
bootstrap.Modal.getInstance(document.getElementById('modalDelete')).hide();
deleteRow.fadeOut(300, () => deleteRow.remove());
} else alert(r.msg);
}, 'json');
});
// --- MODALE AGGIUNGI ---
$('#modalNuovo').on('shown.bs.modal', function() {
$(this).find('.select2').each(function() {
if (!$(this).hasClass('select2-hidden-accessible')) {
$(this).select2({
theme: 'bootstrap-5',
width: '100%'
});
}
});
});
$('#formNuovo').on('submit', function(e) {
e.preventDefault();
const data = $(this).serializeArray();
data.push({
name: 'action',
value: 'insert'
});
$.post('', data, r => r.success ? location.reload() : alert('Errore: ' + (r.msg || 'Fallito')), 'json');
});
$('#modalNuovo').on('hidden.bs.modal', function() {
$(this).find('form')[0].reset();
$(this).find('.select2').select2('destroy');
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
});
});
</script>
<script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
let sortProgrammati = Sortable.create(document.getElementById("programmatiBlock"), {
group: "prod",
animation: 150,
onEnd: updatePriority
});
let sortDaProgrammare = Sortable.create(document.getElementById("daProgrammareBlock"), {
group: "prod",
animation: 150,
onEnd: updatePriority
});
// disabilito sortable sulla tabella special (è sola lettura)
const specialTbody = document.querySelector("#tabSpecial tbody");
if (specialTbody) {
Sortable.create(specialTbody, {
disabled: true
});
}
function updatePriority() {
let programmati = [];
let daProgrammare = [];
$("#programmatiBlock tr").each(function(index) {
programmati.push({
id: $(this).data("id"),
priority: index + 1
});
});
$("#daProgrammareBlock tr").each(function() {
daProgrammare.push($(this).data("id"));
});
$.post("ajax_update_priority.php", {
programmati: JSON.stringify(programmati),
daProgrammare: JSON.stringify(daProgrammare)
}, function(response) {
if (response.success) {
location.reload();
} else {
alert("Errore aggiornamento priorità");
}
}, "json");
}
});
</script>
<!-- MODALE AGGIUNGI -->
<div class="modal fade" id="modalNuovo" tabindex="-1" aria-labelledby="modalNuovoLabel" aria-hidden="true">
<div class="modal-dialog modal-xl" style="max-width: 95vw;">
<div class="modal-content">
<form id="formNuovo">
<div class="modal-header">
<h5 class="modal-title" id="modalNuovoLabel">Aggiungi Programmazione</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="row g-3">
<div class="col-md-6">
<label class="form-label">Data</label>
<input type="date" class="form-control" name="Data" required>
</div>
<div class="col-md-6">
<label class="form-label">Data Produzione</label>
<input type="date" class="form-control" name="data_produzione" required>
</div>
<div class="col-md-6">
<label class="form-label">Matrice</label>
<select class="form-select select2" name="idmatrice" required>
<option value="">Seleziona...</option>
<?php foreach ($matrici as $m): ?>
<option value="<?= $m['id'] ?>"><?= htmlspecialchars($m['nome']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6">
<label class="form-label">Mescola</label>
<select class="form-select select2" name="idmescola" required>
<option value="">Seleziona...</option>
<?php foreach ($mescole as $m): ?>
<option value="<?= $m['id'] ?>"><?= htmlspecialchars($m['nome']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6">
<label class="form-label">Linea</label>
<select class="form-select select2" name="id_linea" required>
<option value="">Seleziona...</option>
<?php foreach ($linee as $l): ?>
<option value="<?= $l['id'] ?>"><?= htmlspecialchars($l['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6">
<label class="form-label">Cliente</label>
<select class="form-select select2" name="id_cliente">
<option value="">Nessuno</option>
<?php foreach ($clienti as $c): ?>
<option value="<?= $c['id'] ?>"><?= htmlspecialchars($c['nome']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6">
<label class="form-label">Data Zibo</label>
<input type="date" class="form-control" name="data_zibo">
</div>
<div class="col-md-6">
<label class="form-label">Data Cliente</label>
<input type="date" class="form-control" name="data_cliente">
</div>
<div class="col-md-3">
<label class="form-label">Metri</label>
<input type="number" step="0.01" class="form-control" name="metri" value="0">
</div>
<div class="col-md-3">
<label class="form-label">Kg SP</label>
<input type="number" step="0.01" class="form-control" name="kg_sp" value="0">
</div>
<div class="col-md-3">
<label class="form-label">Kg P</label>
<input type="number" step="0.01" class="form-control" name="kg_p" value="0">
</div>
<div class="col-md-3">
<label class="form-label">Ore Previste</label>
<input type="number" step="0.01" class="form-control" name="ore_previste" value="0">
</div>
<div class="col-12">
<label class="form-label">Note Extra</label>
<textarea class="form-control" name="note_extra" rows="2"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Annulla</button>
<button type="submit" class="btn btn-primary">Salva</button>
</div>
</form>
</div>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
function updateTimers() {
document.querySelectorAll(".special-row").forEach(row => {
let id = row.dataset.id;
let sec = parseInt(row.dataset.seconds) + 1;
row.dataset.seconds = sec;
let h = String(Math.floor(sec / 3600)).padStart(2, '0');
let m = String(Math.floor((sec % 3600) / 60)).padStart(2, '0');
let s = String(sec % 60).padStart(2, '0');
document.getElementById("timer-" + id).innerText = `${h}:${m}:${s}`;
});
}
setInterval(updateTimers, 1000);
});
$(document).on("click", ".photo-btn", function() {
const type = $(this).data("type");
const id = $(this).data("production");
$("#photoType").val(type);
$("#photoProductionId").val(id);
$("#photoModalTitle").text("Carica Foto " + type);
$("#photoMessageSuccess").hide();
$("#photoMessageError").hide();
// Svuota gallery
$("#photoGallery").html("<p>Caricamento foto...</p>");
// Carico foto esistenti (nuova versione JSON)
$.getJSON("get_photos.php", {
production_id: id,
photo_type: type
}, function(r) {
if (!r.success) {
$("#photoGallery").html("<p style='color:red;'>Errore nel caricamento</p>");
return;
}
if (r.photos.length === 0) {
$("#photoGallery").html("<p>Nessuna foto presente</p>");
return;
}
let html = "";
r.photos.forEach(p => {
html += `
<img src="photos/${p.filename}"
data-full="photos/${p.filename}"
class="photo-thumb"
style="width:110px; height:110px; object-fit:cover; margin:5px; cursor:pointer;">
`;
});
$("#photoGallery").html(html);
});
// MOSTRA IL MODALE
$("#photoModal").css("display", "flex");
});
$("#photoModalCloseX, #photoCancel").on("click", function() {
$("#photoModal").hide();
});
$("#photoModal").on("click", function(e) {
if (e.target.id === "photoModal") {
$("#photoModal").hide();
}
});
// Clic su miniatura → apri preview
$(document).on("click", ".photo-thumb", function() {
const src = $(this).data("full");
$("#previewImage").attr("src", src);
$("#imagePreviewModal").css("display", "flex");
});
// Chiudi con X
$("#previewCloseX").on("click", function() {
$("#imagePreviewModal").hide();
});
// Chiudi cliccando fuori
$("#imagePreviewModal").on("click", function(e) {
if (e.target.id === "imagePreviewModal") {
$("#imagePreviewModal").hide();
}
});
</script>
<!-- MODALE PREVIEW FOTO -->
<div id="imagePreviewModal" class="modal"
style="display:none; position:fixed; top:0; left:0; width:100%; height:100%;
background:rgba(0,0,0,0.75); z-index:100000; justify-content:center; align-items:center;">
<div class="modal-content"
style="position:relative; max-width:90%; background:black; border-radius:10px; padding:10px;">
<!-- X CHIUSURA -->
<button id="previewCloseX"
style="position:absolute; top:10px; right:15px; font-size:2rem; color:white;
background:none; border:none; cursor:pointer;">&times;</button>
<img id="previewImage" src=""
style="max-width:100%; max-height:85vh; display:block; margin:auto;">
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,105 @@
<?php
/**
* Questo file riceve la variabile $r dal file principale
* e stampa una singola card di produzione.
*
* Variabili già presenti in scope:
* - $statusProduzioneId
* - $statusPausaId
*/
$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);
/**
* Calcolo startTime:
* - Se in produzione: usa data_avvio
* - Se in pausa: NON incrementa timer, JS se ne accorge
* - Se programmato: usa Data (data pianificazione)
*/
$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'];
?>
<div class="record-card <?= $isInProduction || $isPaused ? 'in-production expanded' : 'programmed' ?>"
data-id="<?= $r['id'] ?>"
data-total-seconds="<?= $totalSeconds ?>"
data-kgsp="<?= htmlspecialchars($r['kg_sp']) ?>"
data-metri="<?= htmlspecialchars($r['metri']) ?>"
style="--line-bg: <?= $lineColor ?>; --badge-bg: <?= $badgeColor ?>;">
<!-- RIGA VISIBILE -->
<div class="record-summary">
<div class="summary-grid">
<div><strong>Linea</strong> <span><?= htmlspecialchars($r['linea']) ?></span></div>
<div><strong>Matrice</strong> <span><?= htmlspecialchars($r['matrice']) ?></span></div>
<div><strong>Mescola</strong> <span><?= htmlspecialchars($r['mescola']) ?></span></div>
<div><strong>Cliente</strong> <span><?= htmlspecialchars($r['cliente'] ?? '-') ?></span></div>
<div><strong>Zibo</strong> <span><?= $dataZibo ?></span></div>
<div><strong>Data Cl.</strong> <span><?= $dataCliente ?></span></div>
<div><strong>Metri</strong> <span><?= number_format($r['metri'], 2) ?></span></div>
<div><strong>Ore</strong> <span><?= number_format($r['ore_previste'], 1) ?></span></div>
</div>
<div class="status-badge" style="background: var(--badge-bg);">
<?= strtoupper($statusNome) ?>
<?php if ($isInProduction || $isPaused): ?>
<i class="bi bi-chevron-down expand-arrow"></i>
<?php endif; ?>
</div>
</div>
<!-- RIGA ESPANSA -->
<div class="record-expanded">
<?php if ($isInProduction || $isPaused): ?>
<div class="timer-display" data-start="<?= $startTime ?>">
<span class="timer">00:00:00</span>
</div>
<!-- Teorici nascosti (per modale finale) -->
<span data-field="kg_sp" style="display:none;"><?= $r['kg_sp'] ?></span>
<span data-field="metri" style="display:none;"><?= $r['metri'] ?></span>
<div class="action-buttons">
<?php if ($isInProduction): ?>
<button class="action-btn pause-btn" data-id="<?= $r['id'] ?>">PAUSA</button>
<button class="action-btn stop-btn" data-id="<?= $r['id'] ?>">STOP</button>
<?php elseif ($isPaused): ?>
<button class="action-btn resume-btn" data-id="<?= $r['id'] ?>">RIPRENDI</button>
<button class="action-btn stop-btn" data-id="<?= $r['id'] ?>">STOP</button>
<?php endif; ?>
</div>
<?php if (in_array($r['id_status'], [2, 7])): // 2 produzione, 7 pausa
?>
<?php include __DIR__ . "/components/photo_buttons.php"; ?>
<?php endif; ?>
<?php else: ?>
<button class="action-btn start-btn" data-id="<?= $r['id'] ?>">AVVIA PRODUZIONE</button>
<?php endif; ?>
</div>
</div>

View File

@ -0,0 +1,57 @@
<td><span class='view'><?= $r['priority'] ?></span>
<input class='inline-edit form-control form-control-sm' name='priority' type='text' value='<?= $r['priority'] ?>'>
</td>
<td><span class='view'><?= $r['matrice'] ?></span>
<select class='inline-edit form-select form-select-sm select2' name='idmatrice'><?= selectOptions($matrici, $r['idmatrice']) ?></select>
</td>
<td><span class='view'><?= $r['mescola'] ?></span>
<select class='inline-edit form-select form-select-sm select2' name='idmescola'><?= selectOptions($mescole, $r['idmescola']) ?></select>
</td>
<td data-line-id="<?= $r['id_linea'] ?>">
<span class='view'><?= $r['linea'] ?></span>
<select class='inline-edit form-select form-select-sm select2' name='id_linea'><?= selectOptions($linee, $r['id_linea'], 'id', 'name') ?></select>
</td>
<td><span class='view'><?= $r['cliente'] ?? '-' ?></span>
<select class='inline-edit form-select form-select-sm select2' name='id_cliente'>
<option value=''>-</option><?= selectOptions($clienti, $r['id_cliente']) ?>
</select>
</td>
<td><span class='view'><?= $r['data_zibo'] ? date('d/m/Y', strtotime($r['data_zibo'])) : '-' ?></span>
<input class='inline-edit form-control form-control-sm' name='data_zibo' type='date' value='<?= $r['data_zibo'] ?>'>
</td>
<td><span class='view'><?= $r['data_cliente'] ? date('d/m/Y', strtotime($r['data_cliente'])) : '-' ?></span>
<input class='inline-edit form-control form-control-sm' name='data_cliente' type='date' value='<?= $r['data_cliente'] ?>'>
</td>
<td><span class='view'><?= $r['metri'] ?></span>
<input class='inline-edit form-control form-control-sm' name='metri' type='number' step='0.01' value='<?= $r['metri'] ?>'>
</td>
<td><span class='view'><?= $r['kg_sp'] ?></span>
<input class='inline-edit form-control form-control-sm' name='kg_sp' type='number' step='0.01' value='<?= $r['kg_sp'] ?>'>
</td>
<td><span class='view'><?= $r['kg_p'] ?></span>
<input class='inline-edit form-control form-control-sm' name='kg_p' type='number' step='0.01' value='<?= $r['kg_p'] ?>'>
</td>
<td><span class='view'><?= $r['ore_previste'] ?></span>
<input class='inline-edit form-control form-control-sm' name='ore_previste' type='number' step='0.01' value='<?= $r['ore_previste'] ?>'>
</td>
<td>
<span class='view'>
<i class='bi bi-file-text note-icon <?= !empty($r['note_extra']) ? "has-note" : "" ?>'
data-note='<?= htmlspecialchars($r['note_extra'] ?? '') ?>'
data-bs-toggle='modal' data-bs-target='#modalNoteView'></i>
</span>
<textarea class='inline-edit form-control form-control-sm' name='note_extra' rows='2'><?= htmlspecialchars($r['note_extra'] ?? '') ?></textarea>
</td>
<td><span class='view'><?= date('d/m/Y', strtotime($r['data_produzione'])) ?></span>
<input class='inline-edit form-control form-control-sm' name='data_produzione' type='date' value='<?= $r['data_produzione'] ?>'>
</td>
<td>
<span class='badge view' style='background-color: <?= $r['badge_color'] ?>; color: #fff;'><?= ucfirst($r['status_nome']) ?></span>
<select class='inline-edit form-select form-select-sm select2' name='id_status'><?= selectOptions($status_list, $r['id_status'], 'id', 'nome') ?></select>
</td>
<td>
<button class='btn btn-xs btn-outline-primary edit-row'><i class='bi bi-pencil'></i></button>
<button class='btn btn-xs btn-success save-row d-none'><i class='bi bi-check-lg'></i></button>
<button class='btn btn-xs btn-secondary cancel-row d-none'><i class='bi bi-x-lg'></i></button>
<button class='btn btn-xs btn-outline-danger delete-row'><i class='bi bi-trash-fill'></i></button>
</td>

View File

@ -0,0 +1,20 @@
<td><?= htmlspecialchars($r['Data']) ?></td>
<td><?= htmlspecialchars($r['matrice']) ?></td>
<td><?= htmlspecialchars($r['mescola']) ?></td>
<td data-line-id="<?= $r['id_linea'] ?>">
<?= htmlspecialchars($r['linea']) ?>
</td>
<td><?= htmlspecialchars($r['cliente']) ?></td>
<td><?= htmlspecialchars($r['data_zibo']) ?></td>
<td><?= htmlspecialchars($r['data_cliente']) ?></td>
<td><?= htmlspecialchars($r['metri']) ?></td>
<td><?= htmlspecialchars($r['kg_sp']) ?></td>
<td><?= htmlspecialchars($r['kg_p']) ?></td>
<td><?= htmlspecialchars($r['ore_previste']) ?></td>
<td><?= nl2br(htmlspecialchars($r['note_extra'])) ?></td>
<td><?= htmlspecialchars($r['data_produzione']) ?></td>
<td>
<span class="badge" style="background: <?= $r['badge_color'] ?>;">
<?= htmlspecialchars($r['status_nome']) ?>
</span>
</td>

View File

@ -7,19 +7,22 @@ try {
$pdo = $db->getConnection();
$lineNumber = $_POST['lineNumber'] ?? null;
$name = $_POST['lineName'] ?? '';
$model = $_POST['model'] ?? '';
$brand = $_POST['brand'] ?? '';
$status = $_POST['status'] ?? 'active';
$name = $_POST['lineName'] ?? '';
$model = $_POST['model'] ?? '';
$brand = $_POST['brand'] ?? '';
$status = $_POST['status'] ?? 'active';
$color = $_POST['color'] ?? '#dc2626';
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]);
$stmt = $pdo->prepare("
INSERT INTO production_lines (line_number, name, model, brand, status, color)
VALUES (?, ?, ?, ?, ?, ?)
");
$stmt->execute([$lineNumber, $name, $model, $brand, $status, $color]);
echo json_encode(['success' => true]);
} catch (Exception $e) {

View File

@ -1,38 +1,39 @@
<?php
header('Content-Type: application/json');
require_once(__DIR__ . '/class/db-functions.php');
try {
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
// Validazione base
if (empty($_POST['id']) || !is_numeric($_POST['id'])) {
echo json_encode(['success' => false, 'message' => 'ID non valido.']);
exit;
}
$id = (int)$_POST['id'];
$lineNumber = trim($_POST['lineNumber'] ?? '');
$lineName = trim($_POST['lineName'] ?? '');
$model = trim($_POST['model'] ?? '');
$brand = trim($_POST['brand'] ?? '');
$status = trim($_POST['status'] ?? '');
$id = (int)$_POST['id'];
$lineNumber = trim($_POST['lineNumber'] ?? '');
$lineName = trim($_POST['lineName'] ?? '');
$model = trim($_POST['model'] ?? '');
$brand = trim($_POST['brand'] ?? '');
$status = trim($_POST['status'] ?? '');
$color = trim($_POST['color'] ?? '#dc2626');
if ($lineNumber === '' || $lineName === '') {
echo json_encode(['success' => false, 'message' => 'Numero linea e nome sono obbligatori.']);
exit;
}
// Query UPDATE
$sql = "UPDATE production_lines
SET line_number = :line_number,
name = :name,
model = :model,
brand = :brand,
status = :status
WHERE id = :id";
$sql = "
UPDATE production_lines
SET line_number = :line_number,
name = :name,
model = :model,
brand = :brand,
status = :status,
color = :color
WHERE id = :id
";
$stmt = $pdo->prepare($sql);
$stmt->execute([
@ -41,6 +42,7 @@ try {
':model' => $model,
':brand' => $brand,
':status' => $status,
':color' => $color,
':id' => $id
]);

View File

@ -0,0 +1,52 @@
<?php
header('Content-Type: application/json');
require_once __DIR__ . '/class/db-functions.php';
try {
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
if (empty($_POST['production_id']) || empty($_POST['photo_type'])) {
throw new Exception("Dati mancanti");
}
$production_id = (int)$_POST['production_id'];
$type = $_POST['photo_type'];
if (!isset($_FILES['photo'])) {
throw new Exception("Nessuna foto caricata");
}
// Estensione
$ext = pathinfo($_FILES['photo']['name'], PATHINFO_EXTENSION);
$ext = strtolower($ext ?: "jpg");
// Inserimento record DB
$stmt = $pdo->prepare("
INSERT INTO production_photos (production_id, photo_type, filename)
VALUES (?, ?, '')
");
$stmt->execute([$production_id, $type]);
$photo_id = $pdo->lastInsertId();
$timestamp = time();
$filename = "{$production_id}-{$photo_id}-{$timestamp}.{$ext}";
$filepath = __DIR__ . "/photos/" . $filename;
if (!move_uploaded_file($_FILES['photo']['tmp_name'], $filepath)) {
throw new Exception("Errore salvataggio file");
}
// aggiorna filename completo
$pdo->prepare("
UPDATE production_photos SET filename = ? WHERE id = ?
")->execute([$filename, $photo_id]);
echo json_encode(["success" => true]);
} catch (Exception $e) {
echo json_encode([
"success" => false,
"message" => $e->getMessage()
]);
}