get_clienti.php, get_fixed_field_data.php: simulate mode support CustomField dropdown values mock added (get_customfield_values.php) exportUnsavedModal: prompt save before export, MutationObserver waits for save, then proceeds to confirm Removed old jQuery .export-lims-btn handler that bypassed confirm modal Fix false "Unsaved changes" on page load: data-restoring guard in all programmatic trigger/dispatchEvent calls (populateSelect, populateClientDropdowns, populateDropdowns) Fix ConsegnaRichiesta not shown on refresh: add to PHP $fixedAliasMap Add step5_2_photos, step9_1_importa
94 lines
3.2 KiB
PHP
94 lines
3.2 KiB
PHP
<?php
|
|
// get_fixed_field_data.php
|
|
|
|
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
|
require_once dirname(__FILE__) . '/class/VisualLimsApiClient.class.php';
|
|
|
|
header('Content-Type: application/json');
|
|
ini_set('display_errors', '0');
|
|
error_reporting(E_ALL);
|
|
|
|
$field = $_GET['field'] ?? ''; // es: MoltiplicatorePrezzo, AnagraficaCertestObject, ...
|
|
|
|
if (!$field) {
|
|
http_response_code(400);
|
|
echo json_encode(['error' => 'Parametro "field" mancante']);
|
|
exit;
|
|
}
|
|
|
|
$api = VisualLimsApiClient::getInstance(); // also loads dotenv as a side-effect
|
|
$simulate = ($_ENV['SIMULATE_EXPORT_LIMS'] ?? '') === 'true';
|
|
$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) {
|
|
if (!$simulate) {
|
|
http_response_code(400);
|
|
echo json_encode(['error' => 'Manca o invalido id_cliente']);
|
|
exit;
|
|
}
|
|
$id_cliente = 1; // dummy — mock ignores the actual ID
|
|
}
|
|
$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;
|
|
}
|
|
|
|
// Caching skipped in simulate mode to avoid polluting real-data cache files
|
|
if (!$simulate && $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 (!$simulate && $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()]);
|
|
}
|