From c573a4631871673b0e41cba9d3c40014c2518bf2 Mon Sep 17 00:00:00 2001 From: "r.mubarakzyanov" Date: Sun, 29 Mar 2026 17:13:54 +0300 Subject: [PATCH] tolims filter, pagination --- public/userarea/add_record.php | 5 +- public/userarea/gridRenderer.js | 6 +- public/userarea/import_insert.php | 24 +- public/userarea/imported.php | 169 +++++++- public/userarea/modals_gridData.js | 14 +- public/userarea/saveAll.js | 2 + public/userarea/tolims.php | 605 +++++++++++++++++++++++++++-- 7 files changed, 768 insertions(+), 57 deletions(-) diff --git a/public/userarea/add_record.php b/public/userarea/add_record.php index 80eb1e5..fa711f7 100644 --- a/public/userarea/add_record.php +++ b/public/userarea/add_record.php @@ -5,6 +5,7 @@ header('Content-Type: application/json'); try { $input = json_decode(file_get_contents('php://input'), true); $templateId = intval($input['template_id'] ?? 0); + $importRefFromClient = trim($input['importreferencecode'] ?? ''); if (!$templateId) { throw new Exception('Template ID missing'); @@ -21,8 +22,8 @@ try { $template = $stmt->fetch(PDO::FETCH_ASSOC); $idclient = $template['idclient'] ?? null; - // Generate import reference code - $importReferenceCode = date('YmdHis') . '-' . uniqid(); + // Use provided importreferencecode (from filtered page) or generate new + $importReferenceCode = $importRefFromClient !== '' ? $importRefFromClient : date('YmdHis') . '-' . uniqid(); // Insert empty record $stmt = $pdo->prepare(" diff --git a/public/userarea/gridRenderer.js b/public/userarea/gridRenderer.js index 4416509..63c2c96 100644 --- a/public/userarea/gridRenderer.js +++ b/public/userarea/gridRenderer.js @@ -18,7 +18,7 @@ const data = window.gridData || []; const meta = window.gridMeta || {}; const columns = meta.columns || []; - const totalRows = data.length; + let totalRows = data.length; // ── DOM refs ──────────────────────────────────────────────────────────── let rowContainer = null; @@ -463,6 +463,10 @@ function renderVisibleRows() { if (!rowContainer) return; + // Refresh totalRows in case data was modified externally + totalRows = data.length; + if (revealedCount < totalRows) revealedCount = totalRows; + // Destroy Select2 on existing rows $(rowContainer).find('.select2-hidden-accessible').select2('destroy'); diff --git a/public/userarea/import_insert.php b/public/userarea/import_insert.php index 7b19854..8ddd231 100644 --- a/public/userarea/import_insert.php +++ b/public/userarea/import_insert.php @@ -147,28 +147,6 @@ foreach ($selected_rows as $rowIndex) { $_SESSION['inserted_ids'] = $insertedIds; -$params = [ - 'template_id' => $template_id, - 'filename' => $newFilename, -]; - -?> -
- - - - - - - - - - - -
- - \ No newline at end of file diff --git a/public/userarea/imported.php b/public/userarea/imported.php index 8afa340..77223e6 100644 --- a/public/userarea/imported.php +++ b/public/userarea/imported.php @@ -13,6 +13,12 @@ if (!$template_id) { $user_id = $iduserlogin ?? 1; $show_all_users = isset($_GET['all_users']) && $_GET['all_users'] == '1'; +$importref = trim($_GET['importref'] ?? ''); +$usePagination = ($importref === ''); +$allowedLimits = [20, 40, 60, 100]; +$rawLimit = (int)($_GET['limit'] ?? 20); +$perPage = in_array($rawLimit, $allowedLimits) ? $rawLimit : 20; +$page = max(1, (int)($_GET['page'] ?? 1)); $db = DBHandlerSelect::getInstance(); $pdo = $db->getConnection(); @@ -70,16 +76,29 @@ $default_idclient = $template['idclient'] ?? null; // Fetch records with status='i' for this template $userFilter = $show_all_users ? '' : 'AND d.user_id = ?'; +$importrefFilter = $importref !== '' ? 'AND d.importreferencecode = ?' : ''; +$baseWhere = "WHERE d.templateid = ? AND d.status = 'i' {$userFilter} {$importrefFilter}"; +$baseParams = [$template_id]; +if (!$show_all_users) $baseParams[] = $user_id; +if ($importref !== '') $baseParams[] = $importref; + +// Count total records +$countStmt = $pdo->prepare("SELECT COUNT(*) FROM datadb d {$baseWhere}"); +$countStmt->execute($baseParams); +$totalRows = (int)$countStmt->fetchColumn(); +$totalPages = $usePagination ? max(1, (int)ceil($totalRows / $perPage)) : 1; +if ($page > $totalPages) $page = $totalPages; + +$limitClause = $usePagination ? 'LIMIT ' . $perPage . ' OFFSET ' . (($page - 1) * $perPage) : ''; $stmt = $pdo->prepare(" SELECT d.*, CONCAT(u.first_name, ' ', u.last_name) AS user_name FROM datadb d LEFT JOIN auth_users u ON d.user_id = u.id - WHERE d.templateid = ? AND d.status = 'i' {$userFilter} + {$baseWhere} ORDER BY d.iddatadb DESC + {$limitClause} "); -$params = [$template_id]; -if (!$show_all_users) $params[] = $user_id; -$stmt->execute($params); +$stmt->execute($baseParams); $importedData = $stmt->fetchAll(PDO::FETCH_ASSOC); $insertedIds = array_column($importedData, 'iddatadb'); @@ -872,6 +891,14 @@ window.gridMeta = Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?> @@ -1003,6 +1111,7 @@ window.gridMeta = Imported (i) To LIMS (l) + - ( records) + + ( records) + + + + +
+
+ Rows per page +
+ $lim])); + ?> + + +
+
+ 1): ?> +
+ of + + + 1): ?> + 1 + 2): ?>... + + + + ... + + + + +
+ +
+
diff --git a/public/userarea/modals_gridData.js b/public/userarea/modals_gridData.js index 08e7d94..5960ec5 100644 --- a/public/userarea/modals_gridData.js +++ b/public/userarea/modals_gridData.js @@ -164,10 +164,12 @@ const templateId = window.gridMeta?.templateId; if (!templateId) { alert('Template ID missing'); return; } + const urlParams = new URLSearchParams(window.location.search); + const importref = urlParams.get('importref') || ''; const resp = await fetch('add_record.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ template_id: templateId }) + body: JSON.stringify({ template_id: templateId, importreferencecode: importref }) }); const result = await resp.json(); @@ -186,7 +188,7 @@ fixedFields: {}, details: {}, mainFieldValue: '', - _dirty: true, + _dirty: false, }; // Add to beginning of gridData @@ -195,6 +197,14 @@ // Re-render const gr = window.gridRenderer; if (gr) gr.renderVisibleRows(); + + // Highlight new row briefly + const newGridRow = document.querySelector(`.grid-row[data-id="${result.iddatadb}"]`); + if (newGridRow) { + newGridRow.classList.add('row-just-created'); + newGridRow.scrollIntoView({ behavior: 'smooth', block: 'center' }); + setTimeout(() => newGridRow.classList.remove('row-just-created'), 4000); + } } else { alert('Error: ' + (result.message || 'Unknown error')); } diff --git a/public/userarea/saveAll.js b/public/userarea/saveAll.js index eee5dba..28fb515 100644 --- a/public/userarea/saveAll.js +++ b/public/userarea/saveAll.js @@ -28,6 +28,7 @@ if (result.success) { row._dirty = false; + if (window.gridRenderer?.clearDirty) window.gridRenderer.clearDirty(rowIndex); // Flash success on row without re-rendering (preserves Select2 state) const gridRow = document.querySelector(`.grid-row[data-id="${row.iddatadb}"]`); if (gridRow) { @@ -94,6 +95,7 @@ const result = await resp.json(); if (result.success) { data[idx]._dirty = false; + if (window.gridRenderer?.clearDirty) window.gridRenderer.clearDirty(idx); success++; } else { fail++; diff --git a/public/userarea/tolims.php b/public/userarea/tolims.php index a254f33..a803a96 100644 --- a/public/userarea/tolims.php +++ b/public/userarea/tolims.php @@ -14,6 +14,10 @@ if (!$template_id) { $user_id = $iduserlogin ?? 1; $is_readonly = true; $show_all_users = isset($_GET['all_users']) && $_GET['all_users'] == '1'; +$allowedLimits = [20, 40, 60, 100]; +$rawLimit = (int)($_GET['limit'] ?? 20); +$perPage = in_array($rawLimit, $allowedLimits) ? $rawLimit : 20; +$page = max(1, (int)($_GET['page'] ?? 1)); $db = DBHandlerSelect::getInstance(); $pdo = $db->getConnection(); @@ -69,18 +73,80 @@ $template_stmt->execute([$template_id]); $template = $template_stmt->fetch(PDO::FETCH_ASSOC); $default_idclient = $template['idclient'] ?? null; +// Maps logical fixed_field_key → real datadb column name +$fixedAliasMap = [ + 'ClienteResponsabile' => 'cliente_responsabile_id', + 'ClienteFornitore' => 'cliente_fornitore_id', + 'ClienteAnalisi' => 'clienteAnalisi', + 'MoltiplicatorePrezzo' => 'moltiplicatore_prezzo_id', + 'AnagraficaCertestObject' => 'anagrafica_certest_object_id', + 'AnagraficaCertestService' => 'anagrafica_certest_service_id', + 'ConsegnaRichiesta' => 'consegna_richiesta', +]; + // Fetch records with status='l' (exported to LIMS) for this template $userFilter = $show_all_users ? '' : 'AND d.user_id = ?'; +$filters = $_GET['f'] ?? []; +if (!is_array($filters)) $filters = []; + +// Map of filter keys → datadb columns (direct columns) +$directColumnMap = [ + 'commessaweb' => 'd.commessaweb', + 'idclient' => 'd.idclient', + 'importreferencecode' => 'd.importreferencecode', + 'importdate' => 'd.importdate', + 'filename_import' => 'd.filename_import', + 'user_name' => "CONCAT(u.first_name, ' ', u.last_name)", +]; +// Add fixed field columns +foreach ($fixedAliasMap as $fixedKey => $dbCol) { + $directColumnMap[$fixedKey] = 'd.' . $dbCol; +} + +$filterSQL = ''; +$filterParams = []; +foreach ($filters as $key => $val) { + $val = trim($val); + if ($val === '') continue; + + if (isset($directColumnMap[$key])) { + // Direct datadb column + $filterSQL .= " AND {$directColumnMap[$key]} LIKE ?"; + $filterParams[] = '%' . $val . '%'; + } elseif (str_starts_with($key, 'detail_')) { + // import_data_details field: detail_{mapping_id} + $mappingId = (int)substr($key, 7); + if ($mappingId > 0) { + $filterSQL .= " AND EXISTS (SELECT 1 FROM import_data_details dd WHERE dd.id = d.iddatadb AND dd.mapping_id = ? AND dd.field_value LIKE ?)"; + $filterParams[] = $mappingId; + $filterParams[] = '%' . $val . '%'; + } + } +} + +$baseWhere = "WHERE d.templateid = ? AND d.status = 'l' {$userFilter} {$filterSQL}"; +$baseParams = [$template_id]; +if (!$show_all_users) $baseParams[] = $user_id; +$baseParams = array_merge($baseParams, $filterParams); + +// Check if any filter is active +$hasActiveFilters = !empty(array_filter($filters, fn($v) => trim($v) !== '')); + +$countStmt = $pdo->prepare("SELECT COUNT(*) FROM datadb d LEFT JOIN auth_users u ON d.user_id = u.id {$baseWhere}"); +$countStmt->execute($baseParams); +$totalRows = (int)$countStmt->fetchColumn(); +$totalPages = max(1, (int)ceil($totalRows / $perPage)); +if ($page > $totalPages) $page = $totalPages; + $stmt = $pdo->prepare(" SELECT d.*, CONCAT(u.first_name, ' ', u.last_name) AS user_name FROM datadb d LEFT JOIN auth_users u ON d.user_id = u.id - WHERE d.templateid = ? AND d.status = 'l' {$userFilter} + {$baseWhere} ORDER BY d.iddatadb DESC + LIMIT {$perPage} OFFSET " . (($page - 1) * $perPage) . " "); -$params = [$template_id]; -if (!$show_all_users) $params[] = $user_id; -$stmt->execute($params); +$stmt->execute($baseParams); $importedData = $stmt->fetchAll(PDO::FETCH_ASSOC); $insertedIds = array_column($importedData, 'iddatadb'); @@ -154,17 +220,6 @@ foreach ($tempMap as $f) { $fixedFields[] = $f; } -// Maps logical fixed_field_key → real datadb column name (mirrors JS fixedAliasMap) -$fixedAliasMap = [ - 'ClienteResponsabile' => 'cliente_responsabile_id', - 'ClienteFornitore' => 'cliente_fornitore_id', - 'ClienteAnalisi' => 'clienteAnalisi', - 'MoltiplicatorePrezzo' => 'moltiplicatore_prezzo_id', - 'AnagraficaCertestObject' => 'anagrafica_certest_object_id', - 'AnagraficaCertestService' => 'anagrafica_certest_service_id', - 'ConsegnaRichiesta' => 'consegna_richiesta', -]; - // helper default (DATE can use 'today' if you already use it elsewhere) function fixedDefaultValue(array $f): string { @@ -173,6 +228,66 @@ function fixedDefaultValue(array $f): string return (string)$v; } +// ── Build lookup maps: id → label for fixed fields ── +$fixedLookup = []; // e.g. $fixedLookup['MoltiplicatorePrezzo'][2] = 'Urgente (1.5x)' + +function loadCacheJson(string $path): ?array { + if (file_exists($path) && (time() - filemtime($path) < 3600)) { + return json_decode(file_get_contents($path), true); + } + return null; +} + +// MoltiplicatorePrezzo +$cached = loadCacheJson(__DIR__ . '/cache/moltiplicatori_prezzo.json'); +if ($cached) { + $items = $cached['value'] ?? $cached; + foreach ($items as $item) { + $id = $item['IdMoltiplicatorePrezzo'] ?? null; + if ($id !== null) $fixedLookup['MoltiplicatorePrezzo'][$id] = $item['Descrizione'] ?? $item['Codice'] ?? $id; + } +} + +// AnagraficaCertestObject +$cached = loadCacheJson(__DIR__ . '/cache/anagrafica_certest_object.json'); +if ($cached) { + $items = $cached['value'] ?? $cached; + foreach ($items as $item) { + $id = $item['IdAnagrafica'] ?? null; + if ($id !== null) $fixedLookup['AnagraficaCertestObject'][$id] = $item['NomeAnagrafica'] ?? $item['Codice'] ?? $id; + } +} + +// AnagraficaCertestService +$cached = loadCacheJson(__DIR__ . '/cache/anagrafica_certest_service.json'); +if ($cached) { + $items = $cached['value'] ?? $cached; + foreach ($items as $item) { + $id = $item['IdAnagrafica'] ?? null; + if ($id !== null) $fixedLookup['AnagraficaCertestService'][$id] = $item['NomeAnagrafica'] ?? $item['Codice'] ?? $id; + } +} + +// ClienteResponsabile — per-client cache files +$clienteIds = array_unique(array_filter(array_column($importedData, 'idclient'))); +foreach ($clienteIds as $cid) { + $cached = loadCacheJson(__DIR__ . '/cache/cliente_responsabili_' . (int)$cid . '.json'); + if ($cached) { + $items = $cached['Responsabili'] ?? []; + foreach ($items as $item) { + $id = $item['IdClienteResponsabile'] ?? null; + if ($id !== null) $fixedLookup['ClienteResponsabile'][$id] = $item['Nominativo'] ?? $id; + } + } +} + +// Helper: resolve fixed field id → label +function resolveFixedValue(string $key, $val, array $fixedLookup): string { + if ($val === '' || $val === null) return ''; + if (isset($fixedLookup[$key][(int)$val])) return $fixedLookup[$key][(int)$val]; + return (string)$val; +} + ?> @@ -850,6 +965,161 @@ function fixedDefaultValue(array $f): string /* View modals — ensure they sit above backdrop */ #partsViewModal, #photosViewModal { z-index: 1060 !important; } .modal-backdrop { z-index: 1050 !important; } + /* ── Grid filter row ── */ + .grid-filter-row { + background: #f0f4f8 !important; + border-bottom: 2px solid #dee2e6 !important; + position: sticky; + top: 0; + z-index: 5; + } + .grid-filter-row:hover { + background: #f0f4f8 !important; + } + .grid-filter-row .grid-cell { + padding: 4px 6px !important; + } + .grid-filter-input { + width: 100% !important; + padding: 3px 6px !important; + font-size: 11px !important; + border: 1px solid #ced4da !important; + border-radius: 3px !important; + background: #fff !important; + color: #333 !important; + box-sizing: border-box; + } + .grid-filter-input:focus { + border-color: #80bdff !important; + box-shadow: 0 0 0 2px rgba(0,123,255,.15) !important; + outline: none !important; + } + .grid-filter-input::placeholder { + color: #adb5bd; + font-style: italic; + } + .grid-filter-row .grid-filter-input.has-value { + border-color: #0d6efd !important; + background: #f0f7ff !important; + } + select.grid-filter-input { + cursor: pointer; + padding-right: 18px !important; + appearance: auto; + } + .filter-wrap { + display: flex; + align-items: center; + gap: 2px; + width: 100%; + } + .filter-wrap .grid-filter-input { + flex: 1; + min-width: 0; + } + .filter-clear-btn { + flex-shrink: 0; + border: none; + background: #dc3545; + color: #fff; + font-size: 10px; + cursor: pointer; + padding: 2px 4px; + line-height: 1; + border-radius: 3px; + } + .filter-clear-btn:hover { + background: #c82333; + } + .grid-filter-row .grid-cell { + background: #f0f4f8 !important; + } + /* First sticky cell fills full row height */ + .grid-filter-row .grid-cell.button-cell { + align-self: stretch; + } + + /* ── Pagination bar ── */ + .pager-bar { + display: flex; + align-items: center; + justify-content: space-between; + background: #f8f9fa; + border: 1px solid #dee2e6; + border-radius: 6px; + padding: 6px 14px; + font-size: 13px; + color: #495057; + } + .pager-rows-per-page { + display: flex; + align-items: center; + gap: 8px; + } + .pager-label { + font-weight: 500; + white-space: nowrap; + } + .pager-limit-group { + display: inline-flex; + border: 1px solid #ced4da; + border-radius: 4px; + overflow: hidden; + } + .pager-limit-btn { + padding: 3px 10px; + text-decoration: none; + color: #495057; + border-right: 1px solid #ced4da; + transition: background .15s, color .15s; + font-weight: 500; + } + .pager-limit-btn:last-child { border-right: none; } + .pager-limit-btn:hover { background: #e9ecef; text-decoration: none; color: #212529; } + .pager-limit-btn.active { + background: #0d6efd; + color: #fff; + } + .pager-limit-btn.active:hover { background: #0b5ed7; color: #fff; } + .pager-nav { + display: flex; + align-items: center; + gap: 4px; + } + .pager-info { + margin-right: 8px; + font-weight: 500; + white-space: nowrap; + } + .pager-btn, .pager-num { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 28px; + height: 28px; + padding: 0 6px; + border: 1px solid #ced4da; + border-radius: 4px; + text-decoration: none; + color: #495057; + font-weight: 500; + transition: background .15s, color .15s, border-color .15s; + } + .pager-btn:hover, .pager-num:hover { background: #e9ecef; text-decoration: none; color: #212529; } + .pager-num.active { + background: #0d6efd; + color: #fff; + border-color: #0d6efd; + } + .pager-btn.disabled { + pointer-events: none; + opacity: .4; + } + .pager-dots { + padding: 0 2px; + color: #adb5bd; + user-select: none; + } Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?> @@ -865,17 +1135,72 @@ function fixedDefaultValue(array $f): string To LIMS (l) - ( records) + + ( of records) + +
+ +
+
+ Rows per page +
+ $lim])); + ?> + + +
+
+ 1): ?> +
+ of + + + 1): ?> + 1 + 2): ?>... + + + + ... + + + + +
+
Exported to LIMS + + Clear filters +
@@ -1146,6 +1471,131 @@ function fixedDefaultValue(array $f): string
+ + ×" + : ''; + return "
{$inner}{$btn}
"; + } + // Helper: render a select filter from a lookup array + function renderFilterSelect(string $name, array $options, string $currentVal, string $style = ''): string { + $html = ""; + return wrapFilter($html, $currentVal !== ''); + } + // Helper: render a text filter + function renderFilterInput(string $name, string $currentVal): string { + $inner = ""; + return wrapFilter($inner, $currentVal !== ''); + } + // Helper: render a select filter populated by JS + function renderFilterSelectJS(string $name, string $currentVal, string $jsClass, string $dataAttr = ''): string { + $html = ""; + return wrapFilter($html, $currentVal !== ''); + } + // Fields that are client-id lookups + $clientFilterKeys = ['ClienteFornitore', 'ClienteAnalisi']; + ?> +
+
+ +
+ + + + + +
+ + +
+ +
+ +
+ +
+ "; + if ($mapping['data_type'] === 'SceltaMultipla') { + echo renderFilterSelectJS("f[$fKey]", $fVal, 'scelta-filter', "data-field-id='{$mapping['field_id']}'"); + } else { + echo renderFilterInput("f[$fKey]", $fVal); + } + echo "
"; + } + } + // Manual fields + foreach ($allMappings as $mapping) { + if ($mapping['is_manual'] && $mapping['main_field'] != 1 && $mapping['is_visible_import'] == 1) { + $fKey = 'detail_' . $mapping['id']; + $fVal = $filters[$fKey] ?? ''; + echo "
"; + if ($mapping['data_type'] === 'SceltaMultipla') { + echo renderFilterSelectJS("f[$fKey]", $fVal, 'scelta-filter', "data-field-id='{$mapping['field_id']}'"); + } else { + echo renderFilterInput("f[$fKey]", $fVal); + } + echo "
"; + } + } + // Tested Component, AWB, Tracking + echo "
"; + echo "
"; + echo "
"; + + // Fixed fields + if (!empty($fixedFields)) { + $insertedFilterAfterConsegna = false; + foreach ($fixedFields as $f) { + $key = $f['fixed_field_key']; + $fVal = $filters[$key] ?? ''; + echo "
"; + if (in_array($key, $clientFilterKeys, true)) { + // Client-based selects (populated by JS) + echo renderFilterSelectJS("f[$key]", $fVal, 'client-filter'); + } elseif (isset($fixedLookup[$key]) && !empty($fixedLookup[$key])) { + // PHP-cached lookups + echo renderFilterSelect("f[$key]", $fixedLookup[$key], $fVal); + } elseif ($key === 'ConsegnaRichiesta') { + echo renderFilterInput("f[$key]", $fVal); + } else { + echo renderFilterInput("f[$key]", $fVal); + } + echo "
"; + + if ($key === 'ConsegnaRichiesta' && !$insertedFilterAfterConsegna) { + echo "
" . renderFilterInput('f[importreferencecode]', $filters['importreferencecode'] ?? '') . "
"; + echo "
" . renderFilterInput('f[filename_import]', $filters['filename_import'] ?? '') . "
"; + echo "
" . renderFilterInput('f[importdate]', $filters['importdate'] ?? '') . "
"; + $insertedFilterAfterConsegna = true; + } + } + } + ?> +
+ $row): ?>
@@ -1156,9 +1606,10 @@ function fixedDefaultValue(array $f): string $detail = array_filter($manualDetails, fn($d) => $d['mapping_id'] == $mainFieldMapping['id'] && $d['datadb_id'] == $row['iddatadb']); $detail = reset($detail) ?: ['field_value' => $mainFieldMapping['manual_default']]; $fieldValue = $detail['field_value'] ?? $mainFieldMapping['manual_default'] ?? ''; + $isScelta = ($mainFieldMapping['data_type'] === 'SceltaMultipla'); ?>
- + >
@@ -1180,8 +1631,11 @@ function fixedDefaultValue(array $f): string $detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']); $detail = reset($detail) ?: ['field_value' => $mapping['manual_default']]; $fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? ''; + $isScelta = ($mapping['data_type'] === 'SceltaMultipla'); echo "
"; - echo "" . htmlspecialchars($fieldValue) . ""; + echo $isScelta + ? "" . htmlspecialchars($fieldValue) . "" + : "" . htmlspecialchars($fieldValue) . ""; echo "
"; $cellIndex++; $autoIndex++; @@ -1192,8 +1646,11 @@ function fixedDefaultValue(array $f): string $detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']); $detail = reset($detail) ?: ['field_value' => $mapping['manual_default']]; $fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? ''; + $isScelta = ($mapping['data_type'] === 'SceltaMultipla'); echo "
"; - echo "" . htmlspecialchars($fieldValue) . ""; + echo $isScelta + ? "" . htmlspecialchars($fieldValue) . "" + : "" . htmlspecialchars($fieldValue) . ""; echo "
"; $cellIndex++; } @@ -1218,9 +1675,15 @@ function fixedDefaultValue(array $f): string $key = $f['fixed_field_key']; $dbCol = $fixedAliasMap[$key] ?? $key; $val = $row[$dbCol] ?? ''; + $isClientField = in_array($key, ['ClienteFornitore', 'ClienteAnalisi'], true); + $displayVal = $isClientField ? (string)$val : resolveFixedValue($key, $val, $fixedLookup); echo "
"; - echo "" . htmlspecialchars((string)$val) . ""; + if ($isClientField && $val !== '' && $val !== null) { + echo "" . htmlspecialchars((string)$val) . ""; + } else { + echo "" . htmlspecialchars($displayVal) . ""; + } echo "
"; $cellIndex++; @@ -1286,18 +1749,80 @@ function fixedDefaultValue(array $f): string