added drag and photos

This commit is contained in:
2025-11-22 13:35:12 +01:00
parent eeb1d0d5de
commit 8edccbdfef
21 changed files with 2006 additions and 121 deletions
@@ -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>