diff --git a/public/userarea/error_log.txt b/public/userarea/error_log.txt index b6251a2..9619b2d 100644 --- a/public/userarea/error_log.txt +++ b/public/userarea/error_log.txt @@ -16,3 +16,14 @@ 2026-01-27 15:34:06 - Errore nel recupero dati: HTTP 404, Risposta: 2026-01-27 15:34:10 - Errore nel recupero dati: HTTP 404, Risposta: 2026-01-27 15:35:13 - Errore nel recupero dati: HTTP 404, Risposta: +2026-01-29 14:33:38 [ClienteResponsabile] Errore nel recupero dati: HTTP 404, Risposta: +2026-01-29 14:33:39 [MoltiplicatorePrezzo] Autenticazione fallita: HTTP 400, Errore cURL: , Risposta: {"title":"Bad Request","status":400,"detail":"Cannot persist the object. It was modified or deleted (purged) by another application.","instance":"POST /api/authentication/authenticate","errorCode":"96bfc1252b"} +2026-01-29 14:34:04 [ClienteResponsabile] Errore nel recupero dati: HTTP 404, Risposta: +2026-01-29 14:37:29 [ClienteResponsabile] Errore nel recupero dati: HTTP 404, Risposta: +2026-01-29 14:41:55 [ClienteResponsabile] Errore nel recupero dati: HTTP 404, Risposta: +2026-01-29 14:42:03 [ClienteResponsabile] Errore nel recupero dati: HTTP 404, Risposta: +2026-01-29 14:42:52 [ClienteResponsabile] Errore nel recupero dati: HTTP 404, Risposta: +2026-01-29 14:43:00 [ClienteResponsabile] Errore nel recupero dati: HTTP 404, Risposta: +2026-01-30 10:50:43 [AnagraficaCertestService] Autenticazione fallita: HTTP 400, Errore cURL: , Risposta: {"title":"Bad Request","status":400,"detail":"Cannot persist the object. It was modified or deleted (purged) by another application.","instance":"POST /api/authentication/authenticate","errorCode":"96bfc1252b"} +2026-01-30 10:50:43 [MoltiplicatorePrezzo] Autenticazione fallita: HTTP 400, Errore cURL: , Risposta: {"title":"Bad Request","status":400,"detail":"Cannot persist the object. It was modified or deleted (purged) by another application.","instance":"POST /api/authentication/authenticate","errorCode":"96bfc1252b"} +2026-01-30 11:09:22 [MoltiplicatorePrezzo] Autenticazione fallita: HTTP 400, Errore cURL: , Risposta: {"title":"Bad Request","status":400,"detail":"Cannot persist the object. It was modified or deleted (purged) by another application.","instance":"POST /api/authentication/authenticate","errorCode":"96bfc1252b"} diff --git a/public/userarea/get_fixed_field_data.php b/public/userarea/get_fixed_field_data.php new file mode 100644 index 0000000..a9fbd28 --- /dev/null +++ b/public/userarea/get_fixed_field_data.php @@ -0,0 +1,89 @@ + 'Parametro "field" mancante']); + exit; +} + +$api = VisualLimsApiClient::getInstance(); +$base_url = 'https://93.43.5.102/limsapi/api/odata/'; + +$data = null; +$endpoint = null; +$cache_file = null; +$options = []; // qui puoi aggiungere filtri/ordering per campo se serve + +try { + switch ($field) { + case 'MoltiplicatorePrezzo': + $endpoint = 'MoltiplicatorePrezzi'; + $cache_file = __DIR__ . '/cache/moltiplicatori_prezzo.json'; + break; + + case 'AnagraficaCertestObject': + $endpoint = 'AnagraficaCertestObject'; + $cache_file = __DIR__ . '/cache/anagrafica_certest_object.json'; + break; + + case 'AnagraficaCertestService': + $endpoint = 'AnagraficaCertestService'; + $cache_file = __DIR__ . '/cache/anagrafica_certest_service.json'; + break; + + case 'ClienteResponsabile': + $id_cliente = (int)($_GET['id_cliente'] ?? 0); + if ($id_cliente <= 0) { + http_response_code(400); + echo json_encode(['error' => 'Manca o invalido id_cliente']); + exit; + } + $endpoint = "Cliente($id_cliente)?\$expand=Responsabili"; + $cache_file = __DIR__ . '/cache/cliente_responsabili_' . $id_cliente . '.json'; + break; + + // case 'FuturoCampo5': + // $endpoint = 'QualcosaElse'; + // break; + + default: + http_response_code(400); + echo json_encode(['error' => "Campo non supportato: $field"]); + exit; + } + + // Opzionale: caching semplice (molto utile se i dati cambiano poco) + if ($cache_file && file_exists($cache_file) && (time() - filemtime($cache_file) < 3600)) { // 1 ora + $data = json_decode(file_get_contents($cache_file), true); + } else { + $data = $api->get($endpoint, $options); + + if ($cache_file) { + file_put_contents($cache_file, json_encode($data, JSON_PRETTY_PRINT)); + } + } + + // Log ultimo URL (opzionale, per debug) + $full_url = $base_url . $endpoint . ($options ? '?' . http_build_query($options) : ''); + file_put_contents(__DIR__ . '/last_urls.log', date('c') . " - $field - $full_url\n", FILE_APPEND); + + echo json_encode($data); +} catch (Exception $e) { + file_put_contents( + __DIR__ . '/error_log.txt', + date('Y-m-d H:i:s') . " [$field] " . $e->getMessage() . PHP_EOL, + FILE_APPEND + ); + http_response_code(500); + echo json_encode(['error' => $e->getMessage()]); +} diff --git a/public/userarea/import_edit2.php b/public/userarea/import_edit2.php index e8544ab..7e5e5e4 100644 --- a/public/userarea/import_edit2.php +++ b/public/userarea/import_edit2.php @@ -74,6 +74,25 @@ $slugMapping = []; foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { $slugMapping[$row['mysql_column_name']] = $row['user_friendly_slug']; } + +// ---------------- FIXED FIELDS (from template_fixed_mapping) ---------------- +$fixedStmt = $pdo->prepare(" + SELECT id, fixed_field_key, is_manual, data_type, is_required, default_value, is_visible_import + FROM template_fixed_mapping + WHERE template_id = ? AND is_visible_import = 1 + ORDER BY id +"); +$fixedStmt->execute([$template_id]); +$fixedFields = $fixedStmt->fetchAll(PDO::FETCH_ASSOC); + +// helper default (DATE can use 'today' if you already use it elsewhere) +function fixedDefaultValue(array $f): string +{ + $v = $f['default_value'] ?? ''; + if ($f['data_type'] === 'DATE' && $v === 'today') return date('Y-m-d'); + return (string)$v; +} + ?> @@ -456,6 +475,21 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { .select2-container--default .select2-selection--single .select2-selection__arrow { height: 31px; } + + .api-fixed-select+.select2-container .select2-selection__rendered { + color: #333; + } + + .api-fixed-select option[value=""] { + color: #999; + font-style: italic; + } + + .api-fixed-select.required-input:invalid, + .api-fixed-select[required]:not([value]):not([data-select2-id]) { + background-color: #f8d7da !important; + border-color: #dc3545 !important; + } Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?> @@ -577,6 +611,68 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { echo "
"; echo "
"; echo "
"; + // ---------------- FIXED FIELDS TOP (propagate) ---------------- + if (!empty($fixedFields)) { + foreach ($fixedFields as $fx => $f) { + + $key = $f['fixed_field_key']; // datadb column + + $val = fixedDefaultValue($f); + + $isRequired = ((int)$f['is_required'] === 1); + $inputClass = 'manual-input' . ($isRequired ? ' required-input' : ''); + $topRequiredClass = ($isRequired && ($val === '' || $val === null)) ? 'missing-required' : ''; + + echo "
"; + + // Forza DATE anche se per errore nel DB è diversa + $isDate = ($f['data_type'] === 'DATE' || $key === 'ConsegnaRichiesta'); + + if ($isDate) { + + echo ""; + } else { + + $isApiField = in_array($key, [ + 'MoltiplicatorePrezzo', + 'ClienteResponsabile', + 'AnagraficaCertestObject', + 'AnagraficaCertestService' + ], true); + + if ($isApiField) { + $placeholder = ($key === 'ClienteResponsabile') ? 'Seleziona cliente prima...' : 'Seleziona...'; + + echo ""; + } else { + + echo ""; + } + } + + // UNA SOLA freccia + echo ""; + echo "
"; + } + } + + ?> @@ -619,6 +715,22 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { $headerIndex++; echo "
" . ($slugMapping['importdate'] ?? 'importdate') . "
"; ?> + " + . htmlspecialchars($label) . + "
"; + $headerIndex++; + } + } + ?> + $row): ?> @@ -768,6 +880,56 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { + "; + + if ($f['data_type'] === 'DATE') { + echo ""; + } else { // INT → diventa select se è uno dei campi API + $isApiField = in_array($key, ['MoltiplicatorePrezzo', 'ClienteResponsabile', 'AnagraficaCertestObject', 'AnagraficaCertestService']); + $selectClass = $isApiField ? 'api-fixed-select' : ''; + + echo ""; + } + + echo ""; + $cellIndex++; + } + } + ?> + @@ -910,6 +1072,20 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { if (idclientSelect) { formData.append('idclient', idclientSelect.value); } + + // ---- FIXED FIELDS (NEW) ---- + const fixedInputs = row.querySelectorAll(`input[name^="rows[${rowIndex}]["], select[name^="rows[${rowIndex}]["]`); + fixedInputs.forEach(inp => { + // prendo solo quelli che NON sono details e NON idclient/status/importdate/filename/importreferencecode ecc. + // filtro tramite classe fixed-input (che abbiamo messo) + if (!inp.classList.contains('fixed-input')) return; + + const m = inp.name.match(/rows\[\d+\]\[([^\]]+)\]/); + if (m && m[1]) { + formData.append(m[1], inp.value); + } + }); + formData.append('iddatadb', iddatadb); fetch('save_edited_row.php', { @@ -982,6 +1158,16 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { if (idclientSelect) { formData.append('idclient', idclientSelect.value); } + // ---- FIXED FIELDS (NEW) ---- + const fixedInputs = row.querySelectorAll(`input[name^="rows[${rowIndex}]["], select[name^="rows[${rowIndex}]["]`); + fixedInputs.forEach(inp => { + if (!inp.classList.contains('fixed-input')) return; + const m = inp.name.match(/rows\[\d+\]\[([^\]]+)\]/); + if (m && m[1]) { + formData.append(m[1], inp.value); + } + }); + formData.append('iddatadb', iddatadb); try { @@ -1093,6 +1279,10 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { populateClientDropdowns(); clientLoadingStatus.textContent = "Clienti caricati."; + // ✅ force refresh of header dependent fixed fields + $('#clientSelect').trigger('change'); + $('.grid-top .api-fixed-select[data-fixed-key="ClienteResponsabile"]').trigger('fixed:reload'); + } catch (error) { clientLoadingStatus.textContent = "Errore nel caricamento."; console.error("Errore nel caricamento dei client:", error); @@ -1251,7 +1441,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { const dropdownData = {}; async function populateDropdowns() { - const dropdowns = document.querySelectorAll('.dropdown-select:not(.client-select)'); + const dropdowns = document.querySelectorAll('.dropdown-select:not(.client-select):not(.api-fixed-select)'); if (dropdowns.length === 0) { return; } @@ -1564,6 +1754,227 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { }); }); +