getConnection(); /** * Helpers */ function h($v) { return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8'); } function formatDateIT($d) { if (!$d || $d === '0000-00-00') return ''; return date("d/m/Y", strtotime($d)); } function formatDateTimeIT($d) { if (!$d || $d === '0000-00-00 00:00:00') return ''; return date("d/m/Y H:i", strtotime($d)); } function formatNullable($v, $fallback = '—') { $v = trim((string)$v); return $v !== '' ? $v : $fallback; } function worksheetNumberLabel($n) { $n = (int)$n; return $n > 0 ? 'FL' . $n : '—'; } function revisionLabel($rev) { $rev = trim((string)$rev); return $rev !== '' ? $rev : '0'; } /** * DIFFICOLTÀ MATRICE (1 = più facile, 10 = più difficile) * Per aggiungere un'etichetta basta una riga qui (es. 8 => 'Molto difficile'). */ const DIFF_LABELS = [1 => 'Facile', 5 => 'Media', 10 => 'Difficile']; // fasce usate dal filtro in tabella const DIFF_BANDS = [ 'facile' => ['label' => 'Facile (1–3)', 'min' => 1, 'max' => 3], 'media' => ['label' => 'Media (4–7)', 'min' => 4, 'max' => 7], 'difficile' => ['label' => 'Difficile (8–10)', 'min' => 8, 'max' => 10], ]; function diffValue($v) { $n = (int)$v; return ($n >= 1 && $n <= 10) ? $n : null; } /** testo: "5 · Media", "3", "" */ function diffText($v) { $n = diffValue($v); if ($n === null) return ''; return isset(DIFF_LABELS[$n]) ? $n . ' · ' . DIFF_LABELS[$n] : (string)$n; } /** colore dal verde (1) al rosso (10) */ function diffStyle($v) { $n = diffValue($v); if ($n === null) return ''; $hue = (int)round(120 * (10 - $n) / 9); return "background:hsl($hue,75%,90%);color:hsl($hue,70%,26%);border-color:hsl($hue,55%,68%);"; } function diffBadge($v) { $n = diffValue($v); if ($n === null) return "—"; return "" . h(diffText($n)) . ""; } ?> Gestione Matrici - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?>
Gestione elenco Profili
Elenco Completo
query(" SELECT m.*, COALESCE(lg.linee_associate, '—') AS linee_associate, COALESCE(mg.mescole_associate, '') AS mescole_associate, COALESCE(mg.mescole_count, 0) AS mescole_count, COALESCE(wsg.worksheets_count, 0) AS worksheets_count FROM matrice m LEFT JOIN ( SELECT ml.idmatrice, GROUP_CONCAT(pl.name ORDER BY pl.name SEPARATOR ', ') AS linee_associate FROM matrici_lines ml JOIN production_lines pl ON pl.id = ml.idlinea GROUP BY ml.idmatrice ) lg ON lg.idmatrice = m.id LEFT JOIN ( SELECT mm.idmatrice, GROUP_CONCAT(ms.nome ORDER BY ms.nome SEPARATOR ', ') AS mescole_associate, COUNT(*) AS mescole_count FROM matrici_mescole mm JOIN mescole ms ON ms.id = mm.idmescola GROUP BY mm.idmatrice ) mg ON mg.idmatrice = m.id LEFT JOIN ( SELECT ws.idmatrice, COUNT(*) AS worksheets_count FROM work_sheets ws GROUP BY ws.idmatrice ) wsg ON wsg.idmatrice = m.id ORDER BY CASE WHEN TRIM(COALESCE(m.nome, '')) = '' THEN 1 ELSE 0 END, m.nome ASC "); if ($stmt->rowCount() === 0) { echo ""; } else { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $dataIT = formatDateIT($row['data_produzione']); $foto = $row['photo'] ?? ''; $pathFoto = "photos/matrici/" . $foto; $placeholder = "assets/images/no-photo.png"; if ($foto && file_exists($pathFoto)) { $thumb = $pathFoto; $hasPhoto = true; } else { $thumb = $placeholder; $hasPhoto = false; } echo ""; $imgSrc = $hasPhoto ? $thumb : ''; echo ""; echo ""; echo ""; $diff = diffValue($row['difficolta'] ?? null); echo ""; $lineeTxt = $row['linee_associate'] ?? '—'; $mescoleTxt = $row['mescole_associate'] ?? ''; $mescoleCount = (int)($row['mescole_count'] ?? 0); $worksheetsCount = (int)($row['worksheets_count'] ?? 0); $btnMescole = ''; if ($mescoleCount > 0) { $btnMescole = " "; } echo ""; echo ""; echo ""; echo ""; } } ?>
Foto Nome Cliente Difficoltà Linee Fogli Azioni
Nessuna matrice presente
NP " . htmlspecialchars($row['nome']) . "" . htmlspecialchars($row['cliente']) . "" . diffBadge($diff) . "" . htmlspecialchars($lineeTxt) . $btnMescole . "
{$worksheetsCount}"; if ($worksheetsCount > 0) { echo ""; } else { echo "—"; } echo "