fixed matrici
This commit is contained in:
parent
51cca3448a
commit
1edf7b7239
36
public/userarea/get_matrice_lines.php
Normal file
36
public/userarea/get_matrice_lines.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
include('include/headscript.php');
|
||||||
|
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$idmatrice = (int)($_GET['id'] ?? 0);
|
||||||
|
if ($idmatrice <= 0) {
|
||||||
|
echo json_encode(['success' => false, 'message' => 'Invalid id']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = DBHandlerSelect::getInstance();
|
||||||
|
$pdo = $db->getConnection();
|
||||||
|
|
||||||
|
// tutte le linee (attive + inattive se vuoi: qui prendo tutte)
|
||||||
|
$stmt = $pdo->query("
|
||||||
|
SELECT id, line_number, name
|
||||||
|
FROM production_lines
|
||||||
|
ORDER BY line_number ASC
|
||||||
|
");
|
||||||
|
$lines = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
// linee già associate
|
||||||
|
$stmt = $pdo->prepare("SELECT idlinea FROM matrici_lines WHERE idmatrice = ?");
|
||||||
|
$stmt->execute([$idmatrice]);
|
||||||
|
$selected_ids = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'success' => true,
|
||||||
|
'lines' => $lines,
|
||||||
|
'selected_ids' => $selected_ids
|
||||||
|
]);
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
echo json_encode(['success' => false, 'message' => 'Server error']);
|
||||||
|
}
|
||||||
35
public/userarea/get_matrice_mescole.php
Normal file
35
public/userarea/get_matrice_mescole.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
include('include/headscript.php');
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$idmatrice = (int)($_GET['id'] ?? 0);
|
||||||
|
if ($idmatrice <= 0) {
|
||||||
|
echo json_encode(['success' => false, 'message' => 'Invalid id']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = DBHandlerSelect::getInstance();
|
||||||
|
$pdo = $db->getConnection();
|
||||||
|
|
||||||
|
// tutte le mescole
|
||||||
|
$stmt = $pdo->query("
|
||||||
|
SELECT id, nome, nomeuscita
|
||||||
|
FROM mescole
|
||||||
|
ORDER BY nome ASC
|
||||||
|
");
|
||||||
|
$mescole = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
// mescole già associate
|
||||||
|
$stmt = $pdo->prepare("SELECT idmescola FROM matrici_mescole WHERE idmatrice = ?");
|
||||||
|
$stmt->execute([$idmatrice]);
|
||||||
|
$selected_ids = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'success' => true,
|
||||||
|
'mescole' => $mescole,
|
||||||
|
'selected_ids' => $selected_ids
|
||||||
|
]);
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
echo json_encode(['success' => false, 'message' => 'Server error']);
|
||||||
|
}
|
||||||
@ -11,13 +11,12 @@
|
|||||||
|
|
||||||
<!-- jQuery, Bootstrap, SweetAlert -->
|
<!-- jQuery, Bootstrap, SweetAlert -->
|
||||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||||
|
|
||||||
<!-- DataTables -->
|
<!-- DataTables -->
|
||||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css">
|
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css">
|
||||||
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
|
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
|
||||||
<script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>
|
|
||||||
|
|
||||||
<!-- Select2 -->
|
<!-- Select2 -->
|
||||||
<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@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
|
||||||
@ -176,13 +175,14 @@
|
|||||||
max-width: 320px;
|
max-width: 320px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Data: piccola */
|
/* Linee: media */
|
||||||
#tabellaMatrici th:nth-child(4),
|
#tabellaMatrici th:nth-child(4),
|
||||||
#tabellaMatrici td:nth-child(4) {
|
#tabellaMatrici td:nth-child(4) {
|
||||||
width: 120px;
|
width: 220px;
|
||||||
max-width: 120px;
|
max-width: 220px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Azioni: fissa */
|
/* Azioni: fissa */
|
||||||
#tabellaMatrici th:nth-child(5),
|
#tabellaMatrici th:nth-child(5),
|
||||||
#tabellaMatrici td:nth-child(5) {
|
#tabellaMatrici td:nth-child(5) {
|
||||||
@ -230,7 +230,7 @@
|
|||||||
<th>Foto</th>
|
<th>Foto</th>
|
||||||
<th>Nome</th>
|
<th>Nome</th>
|
||||||
<th>Cliente</th>
|
<th>Cliente</th>
|
||||||
<th>Data</th>
|
<th>Linee</th>
|
||||||
<th>Azioni</th>
|
<th>Azioni</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -241,7 +241,34 @@
|
|||||||
$db = DBHandlerSelect::getInstance();
|
$db = DBHandlerSelect::getInstance();
|
||||||
$pdo = $db->getConnection();
|
$pdo = $db->getConnection();
|
||||||
|
|
||||||
$stmt = $pdo->query("SELECT * FROM matrice ORDER BY id DESC");
|
$stmt = $pdo->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
|
||||||
|
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
|
||||||
|
ORDER BY m.id DESC
|
||||||
|
");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function formatDateIT($d)
|
function formatDateIT($d)
|
||||||
{
|
{
|
||||||
@ -300,8 +327,27 @@
|
|||||||
. "</td>";
|
. "</td>";
|
||||||
|
|
||||||
|
|
||||||
// colonna DATA
|
// colonna LINEE
|
||||||
echo "<td>{$dataIT}</td>";
|
$lineeTxt = $row['linee_associate'] ?? '—';
|
||||||
|
$mescoleTxt = $row['mescole_associate'] ?? '';
|
||||||
|
$mescoleCount = (int)($row['mescole_count'] ?? 0);
|
||||||
|
|
||||||
|
$btnMescole = '';
|
||||||
|
if ($mescoleCount > 0) {
|
||||||
|
$btnMescole = " <button type='button'
|
||||||
|
class='btn btn-sm btn-outline-secondary ms-2 show-mescole'
|
||||||
|
data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'
|
||||||
|
data-mescole='" . htmlspecialchars($mescoleTxt, ENT_QUOTES) . "'
|
||||||
|
data-bs-toggle='tooltip' data-bs-title='Vedi mescole associate'>
|
||||||
|
<i class='fa-solid fa-flask'></i>
|
||||||
|
</button>";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "<td title='" . htmlspecialchars($lineeTxt, ENT_QUOTES) . "'>"
|
||||||
|
. htmlspecialchars($lineeTxt)
|
||||||
|
. $btnMescole
|
||||||
|
. "</td>";
|
||||||
|
|
||||||
|
|
||||||
// colonna AZIONI
|
// colonna AZIONI
|
||||||
echo "<td>
|
echo "<td>
|
||||||
@ -309,23 +355,34 @@
|
|||||||
data-id='{$row['id']}'
|
data-id='{$row['id']}'
|
||||||
data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'
|
data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'
|
||||||
data-cliente='" . htmlspecialchars($row['cliente'], ENT_QUOTES) . "'
|
data-cliente='" . htmlspecialchars($row['cliente'], ENT_QUOTES) . "'
|
||||||
data-data='{$dataIT}'>
|
data-data='{$dataIT}'
|
||||||
|
data-bs-toggle='tooltip' data-bs-title='Modifica'>
|
||||||
<i class='fa-solid fa-pen-to-square'></i>
|
<i class='fa-solid fa-pen-to-square'></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button class='action-btn delete' data-id='{$row['id']}'>
|
<button class='action-btn delete'
|
||||||
|
data-id='{$row['id']}'
|
||||||
|
data-bs-toggle='tooltip' data-bs-title='Elimina'>
|
||||||
<i class='fa-solid fa-trash'></i>
|
<i class='fa-solid fa-trash'></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button class='action-btn linee' data-id='{$row['id']}' data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'>
|
<button class='action-btn linee'
|
||||||
|
data-id='{$row['id']}'
|
||||||
|
data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'
|
||||||
|
data-bs-toggle='tooltip' data-bs-title='Linee associate'>
|
||||||
<i class='fa-solid fa-sitemap'></i>
|
<i class='fa-solid fa-sitemap'></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button class='action-btn mescole' data-id='{$row['id']}' data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'>
|
|
||||||
|
<button class='action-btn mescole'
|
||||||
|
data-id='{$row['id']}'
|
||||||
|
data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'
|
||||||
|
data-bs-toggle='tooltip' data-bs-title='Mescole associate'>
|
||||||
<i class='fa-solid fa-flask'></i>
|
<i class='fa-solid fa-flask'></i>
|
||||||
</button>
|
</button>
|
||||||
</td>";
|
</td>";
|
||||||
|
|
||||||
|
|
||||||
echo "</tr>";
|
echo "</tr>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -382,6 +439,70 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- MODALE LINEE ASSOCIATE -->
|
||||||
|
<div class="modal fade" id="matriceLineeModal" tabindex="-1" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered">
|
||||||
|
<div class="modal-content">
|
||||||
|
|
||||||
|
<div class="modal-header" style="background-color:#b9ebc7;">
|
||||||
|
<h5 class="modal-title">Linee associate</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-body">
|
||||||
|
<input type="hidden" id="ml_idmatrice">
|
||||||
|
|
||||||
|
<div class="mb-2">
|
||||||
|
<div class="fw-semibold" id="ml_matrice_name" style="color:#1f2d3d;"></div>
|
||||||
|
<small class="text-muted">Seleziona una o più linee di produzione</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="fw-semibold">Linee</label>
|
||||||
|
<select id="ml_linee" class="form-select" multiple="multiple" style="width:100%;"></select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<button type="button" class="btn btn-add" id="ml_save_btn">💾 Salva Linee</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- MODALE MESCOLE ASSOCIATE -->
|
||||||
|
<div class="modal fade" id="matriceMescoleModal" tabindex="-1" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered">
|
||||||
|
<div class="modal-content">
|
||||||
|
|
||||||
|
<div class="modal-header" style="background-color:#b9ebc7;">
|
||||||
|
<h5 class="modal-title">Mescole associate</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-body">
|
||||||
|
<input type="hidden" id="mm_idmatrice">
|
||||||
|
|
||||||
|
<div class="mb-2">
|
||||||
|
<div class="fw-semibold" id="mm_matrice_name" style="color:#1f2d3d;"></div>
|
||||||
|
<small class="text-muted">Seleziona una o più mescole</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="fw-semibold">Mescole</label>
|
||||||
|
<select id="mm_mescole" class="form-select" multiple="multiple" style="width:100%;"></select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<button type="button" class="btn btn-add" id="mm_save_btn">💾 Salva Mescole</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<?php include('jsinclude.php'); ?>
|
<?php include('jsinclude.php'); ?>
|
||||||
|
|
||||||
@ -483,6 +604,180 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
// Bootstrap 5 tooltips
|
||||||
|
document.querySelectorAll('[data-bs-toggle="tooltip"]').forEach(el => new bootstrap.Tooltip(el));
|
||||||
|
|
||||||
|
// === LINEE ASSOCIATE (MODALE) ===
|
||||||
|
|
||||||
|
// init Select2 (dentro modal)
|
||||||
|
$('#ml_linee').select2({
|
||||||
|
theme: 'bootstrap-5',
|
||||||
|
dropdownParent: $('#matriceLineeModal'),
|
||||||
|
placeholder: 'Seleziona le linee...'
|
||||||
|
});
|
||||||
|
|
||||||
|
// open modal + load data
|
||||||
|
$(document).on("click", ".linee", function() {
|
||||||
|
const idmatrice = $(this).data("id");
|
||||||
|
const nome = $(this).data("nome") || "";
|
||||||
|
|
||||||
|
$("#ml_idmatrice").val(idmatrice);
|
||||||
|
$("#ml_matrice_name").text(nome);
|
||||||
|
|
||||||
|
// pulizia select
|
||||||
|
const $sel = $("#ml_linee");
|
||||||
|
$sel.empty().trigger("change");
|
||||||
|
|
||||||
|
fetch("get_matrice_lines.php?id=" + encodeURIComponent(idmatrice))
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(data => {
|
||||||
|
if (!data.success) {
|
||||||
|
Swal.fire({
|
||||||
|
icon: "error",
|
||||||
|
title: "Errore",
|
||||||
|
text: data.message || "Impossibile caricare le linee"
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// riempi opzioni linee
|
||||||
|
data.lines.forEach(l => {
|
||||||
|
const label = `Linea ${l.line_number} - ${l.name}`;
|
||||||
|
const opt = new Option(label, l.id, false, false);
|
||||||
|
$sel.append(opt);
|
||||||
|
});
|
||||||
|
|
||||||
|
// seleziona quelle già associate
|
||||||
|
$sel.val((data.selected_ids || []).map(String)).trigger("change");
|
||||||
|
|
||||||
|
// apri modale (BS5)
|
||||||
|
const modal = new bootstrap.Modal(document.getElementById('matriceLineeModal'));
|
||||||
|
modal.show();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// save associations
|
||||||
|
$("#ml_save_btn").on("click", function() {
|
||||||
|
const idmatrice = $("#ml_idmatrice").val();
|
||||||
|
const selected = $("#ml_linee").val() || []; // array di idlinea
|
||||||
|
|
||||||
|
fetch("save_matrice_lines.php", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded"
|
||||||
|
},
|
||||||
|
body: "idmatrice=" + encodeURIComponent(idmatrice) +
|
||||||
|
"&idlinee=" + encodeURIComponent(JSON.stringify(selected))
|
||||||
|
})
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(data => {
|
||||||
|
Swal.fire({
|
||||||
|
icon: data.success ? "success" : "error",
|
||||||
|
title: data.success ? "Salvato!" : "Errore",
|
||||||
|
text: data.message || ""
|
||||||
|
}).then(() => {
|
||||||
|
if (data.success) {
|
||||||
|
bootstrap.Modal.getInstance(document.getElementById('matriceLineeModal')).hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// === MESCOLE ASSOCIATE (MODALE) ===
|
||||||
|
|
||||||
|
// init Select2 (dentro modal)
|
||||||
|
$('#mm_mescole').select2({
|
||||||
|
theme: 'bootstrap-5',
|
||||||
|
dropdownParent: $('#matriceMescoleModal'),
|
||||||
|
placeholder: 'Cerca e seleziona le mescole...',
|
||||||
|
minimumResultsForSearch: 0, // <-- search sempre visibile
|
||||||
|
width: '100%'
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// open modal + load data
|
||||||
|
$(document).on("click", ".mescole", function() {
|
||||||
|
const idmatrice = $(this).data("id");
|
||||||
|
const nome = $(this).data("nome") || "";
|
||||||
|
|
||||||
|
$("#mm_idmatrice").val(idmatrice);
|
||||||
|
$("#mm_matrice_name").text(nome);
|
||||||
|
|
||||||
|
const $sel = $("#mm_mescole");
|
||||||
|
$sel.empty().trigger("change");
|
||||||
|
|
||||||
|
fetch("get_matrice_mescole.php?id=" + encodeURIComponent(idmatrice))
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(data => {
|
||||||
|
if (!data.success) {
|
||||||
|
Swal.fire({
|
||||||
|
icon: "error",
|
||||||
|
title: "Errore",
|
||||||
|
text: data.message || "Impossibile caricare le mescole"
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// riempi opzioni mescole
|
||||||
|
data.mescole.forEach(m => {
|
||||||
|
const label = m.nomeuscita ? `${m.nome} (${m.nomeuscita})` : m.nome;
|
||||||
|
const opt = new Option(label, m.id, false, false);
|
||||||
|
$sel.append(opt);
|
||||||
|
});
|
||||||
|
|
||||||
|
// seleziona quelle già associate
|
||||||
|
$sel.val((data.selected_ids || []).map(String)).trigger("change");
|
||||||
|
|
||||||
|
// apri modale (BS5)
|
||||||
|
const modal = new bootstrap.Modal(document.getElementById('matriceMescoleModal'));
|
||||||
|
modal.show();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// save associations
|
||||||
|
$("#mm_save_btn").on("click", function() {
|
||||||
|
const idmatrice = $("#mm_idmatrice").val();
|
||||||
|
const selected = $("#mm_mescole").val() || []; // array di idmescola
|
||||||
|
|
||||||
|
fetch("save_matrice_mescole.php", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded"
|
||||||
|
},
|
||||||
|
body: "idmatrice=" + encodeURIComponent(idmatrice) +
|
||||||
|
"&idmescole=" + encodeURIComponent(JSON.stringify(selected))
|
||||||
|
})
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(data => {
|
||||||
|
Swal.fire({
|
||||||
|
icon: data.success ? "success" : "error",
|
||||||
|
title: data.success ? "Salvato!" : "Errore",
|
||||||
|
text: data.message || ""
|
||||||
|
}).then(() => {
|
||||||
|
if (data.success) {
|
||||||
|
bootstrap.Modal.getInstance(document.getElementById('matriceMescoleModal')).hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// click: mostra elenco mescole associate (read-only)
|
||||||
|
$(document).on('click', '.show-mescole', function() {
|
||||||
|
const nome = $(this).data('nome') || '';
|
||||||
|
const mescole = $(this).data('mescole') || '';
|
||||||
|
|
||||||
|
$("#mlm_matrice_name").text(nome);
|
||||||
|
|
||||||
|
if (!mescole.trim()) {
|
||||||
|
$("#mlm_list").html("<span class='text-muted'>Nessuna mescola associata</span>");
|
||||||
|
} else {
|
||||||
|
// elenco in badge
|
||||||
|
const items = mescole.split(',').map(s => s.trim()).filter(Boolean);
|
||||||
|
$("#mlm_list").html(items.map(x => `<span class="badge bg-secondary me-1 mb-1">${x}</span>`).join(''));
|
||||||
|
}
|
||||||
|
|
||||||
|
const modal = new bootstrap.Modal(document.getElementById('mescoleListModal'));
|
||||||
|
modal.show();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -523,6 +818,24 @@
|
|||||||
<img id="bigImg" src=""
|
<img id="bigImg" src=""
|
||||||
style="max-width:70vw; max-height:90vh; border-radius:12px;">
|
style="max-width:70vw; max-height:90vh; border-radius:12px;">
|
||||||
</div>
|
</div>
|
||||||
|
<!-- MODALE LISTA MESCOLE ASSOCIATE (READ-ONLY) -->
|
||||||
|
<div class="modal fade" id="mescoleListModal" tabindex="-1" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered">
|
||||||
|
<div class="modal-content">
|
||||||
|
|
||||||
|
<div class="modal-header" style="background-color:#b9ebc7;">
|
||||||
|
<h5 class="modal-title">Mescole associate</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="fw-semibold mb-2" id="mlm_matrice_name" style="color:#1f2d3d;"></div>
|
||||||
|
<div id="mlm_list" class="text-muted"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
43
public/userarea/save_matrice_lines.php
Normal file
43
public/userarea/save_matrice_lines.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
include('include/headscript.php');
|
||||||
|
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$idmatrice = (int)($_POST['idmatrice'] ?? 0);
|
||||||
|
$raw = $_POST['idlinee'] ?? '[]';
|
||||||
|
$idlinee = json_decode($raw, true);
|
||||||
|
|
||||||
|
if ($idmatrice <= 0) {
|
||||||
|
echo json_encode(['success' => false, 'message' => 'Invalid idmatrice']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (!is_array($idlinee)) $idlinee = [];
|
||||||
|
|
||||||
|
// normalizza a int e rimuovi duplicati
|
||||||
|
$idlinee = array_values(array_unique(array_filter(array_map('intval', $idlinee), fn($v) => $v > 0)));
|
||||||
|
|
||||||
|
$db = DBHandlerSelect::getInstance();
|
||||||
|
$pdo = $db->getConnection();
|
||||||
|
|
||||||
|
$pdo->beginTransaction();
|
||||||
|
|
||||||
|
// rimuovi vecchie associazioni
|
||||||
|
$stmt = $pdo->prepare("DELETE FROM matrici_lines WHERE idmatrice = ?");
|
||||||
|
$stmt->execute([$idmatrice]);
|
||||||
|
|
||||||
|
// inserisci nuove
|
||||||
|
if (!empty($idlinee)) {
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO matrici_lines (idmatrice, idlinea) VALUES (?, ?)");
|
||||||
|
foreach ($idlinee as $idlinea) {
|
||||||
|
$stmt->execute([$idmatrice, $idlinea]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$pdo->commit();
|
||||||
|
|
||||||
|
echo json_encode(['success' => true, 'message' => 'Associazioni aggiornate']);
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
if (isset($pdo) && $pdo->inTransaction()) $pdo->rollBack();
|
||||||
|
echo json_encode(['success' => false, 'message' => 'Server error']);
|
||||||
|
}
|
||||||
@ -1,27 +1,42 @@
|
|||||||
<?php
|
<?php
|
||||||
include('../class/db-functions.php');
|
include('include/headscript.php');
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$data = json_decode(file_get_contents('php://input'), true);
|
$idmatrice = (int)($_POST['idmatrice'] ?? 0);
|
||||||
$idMatrice = intval($data['id']);
|
$raw = $_POST['idmescole'] ?? '[]';
|
||||||
$mescole = $data['mescole'] ?? [];
|
$idmescole = json_decode($raw, true);
|
||||||
|
|
||||||
|
if ($idmatrice <= 0) {
|
||||||
|
echo json_encode(['success' => false, 'message' => 'Invalid idmatrice']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (!is_array($idmescole)) $idmescole = [];
|
||||||
|
|
||||||
|
// normalizza a int e rimuovi duplicati
|
||||||
|
$idmescole = array_values(array_unique(array_filter(array_map('intval', $idmescole), fn($v) => $v > 0)));
|
||||||
|
|
||||||
$db = DBHandlerSelect::getInstance();
|
$db = DBHandlerSelect::getInstance();
|
||||||
$pdo = $db->getConnection();
|
$pdo = $db->getConnection();
|
||||||
|
|
||||||
// Rimuove tutte le precedenti associazioni
|
$pdo->beginTransaction();
|
||||||
$pdo->prepare("DELETE FROM matrice_mescole WHERE idmatrice = ?")->execute([$idMatrice]);
|
|
||||||
|
|
||||||
// Inserisce le nuove
|
// rimuovi vecchie associazioni
|
||||||
if (!empty($mescole)) {
|
$stmt = $pdo->prepare("DELETE FROM matrici_mescole WHERE idmatrice = ?");
|
||||||
$stmt = $pdo->prepare("INSERT INTO matrice_mescole (idmatrice, idmescola) VALUES (?, ?)");
|
$stmt->execute([$idmatrice]);
|
||||||
foreach ($mescole as $idMescola) {
|
|
||||||
$stmt->execute([$idMatrice, $idMescola]);
|
// inserisci nuove
|
||||||
|
if (!empty($idmescole)) {
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO matrici_mescole (idmatrice, idmescola) VALUES (?, ?)");
|
||||||
|
foreach ($idmescole as $idmescola) {
|
||||||
|
$stmt->execute([$idmatrice, $idmescola]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo json_encode(['success' => true, 'message' => 'Associazioni mescole aggiornate.']);
|
$pdo->commit();
|
||||||
} catch (Exception $e) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'Errore: ' . $e->getMessage()]);
|
echo json_encode(['success' => true, 'message' => 'Associazioni aggiornate']);
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
if (isset($pdo) && $pdo->inTransaction()) $pdo->rollBack();
|
||||||
|
echo json_encode(['success' => false, 'message' => 'Server error']);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user