diff --git a/public/userarea/get_macro_matrici.php b/public/userarea/get_macro_matrici.php index 33b181e..a9f2467 100644 --- a/public/userarea/get_macro_matrici.php +++ b/public/userarea/get_macro_matrici.php @@ -1,59 +1,46 @@ 'Unauthorized']); exit; } -// Set JSON header header('Content-Type: application/json'); -// Debug: Log the path where we expect the .env file -$envPath = dirname(__DIR__, 2); -file_put_contents(__DIR__ . '/debug_log.txt', date('Y-m-d H:i:s') . ' - Expected .env path: ' . $envPath . PHP_EOL, FILE_APPEND); - -// Carica il file .env dalla root del progetto try { - $dotenv = Dotenv::createImmutable($envPath); - $dotenv->load(); -} catch (Exception $e) { - file_put_contents(__DIR__ . '/error_log.txt', date('Y-m-d H:i:s') . ' - Errore caricamento .env: ' . $e->getMessage() . PHP_EOL, FILE_APPEND); - echo json_encode(['success' => false, 'message' => 'Errore caricamento configurazione: ' . $e->getMessage()]); - exit(1); -} + // Read from matrici cache (populated by get_matrici.php / warm_cache.php) + $cacheFile = __DIR__ . '/cache/matrici.json'; + if (file_exists($cacheFile)) { + $data = json_decode(file_get_contents($cacheFile), true); + $matrici = $data['value'] ?? []; + } else { + // Fallback: trigger cache creation + require_once __DIR__ . '/class/VisualLimsApiClient.class.php'; + $api = VisualLimsApiClient::getInstance(); + $apiData = $api->get('Matrice'); + $matrici = []; + foreach (($apiData['value'] ?? []) as $item) { + $nome = $item['NomeMatrice'] ?? ''; + if ($nome !== '' && substr($nome, 0, 1) !== '*') { + $matrici[] = ['IdMatrice' => $item['IdMatrice'], 'NomeMatrice' => $nome, 'MacroMatrice' => $item['MacroMatrice'] ?? null]; + } + } + if (!is_dir(__DIR__ . '/cache')) mkdir(__DIR__ . '/cache', 0777, true); + file_put_contents($cacheFile, json_encode(['success' => true, 'value' => $matrici])); + } -// Recupera le variabili d'ambiente -$dbHost = $_ENV['DB_HOST']; -$dbName = $_ENV['DB_DATABASE']; -$dbUser = $_ENV['DB_USERNAME']; -$dbPass = $_ENV['DB_PASSWORD']; -$dbPrefix = $_ENV['DB_PREFIX']; + // Extract unique MacroMatrice values + $macroValues = []; + foreach ($matrici as $m) { + $macro = $m['MacroMatrice'] ?? null; + if ($macro !== null && $macro !== '' && substr($macro, 0, 1) !== '*') { + $macroValues[$macro] = true; + } + } + $macroMatrici = array_keys($macroValues); + sort($macroMatrici); -// Debug: Log database connection details (excluding password) -file_put_contents(__DIR__ . '/debug_log.txt', date('Y-m-d H:i:s') . " - DB Connection: host=$dbHost, dbname=$dbName, user=$dbUser, prefix=$dbPrefix" . PHP_EOL, FILE_APPEND); - -// Connessione al database MySQL -try { - $pdo = new PDO("mysql:host=$dbHost;dbname=$dbName;charset=utf8mb4", $dbUser, $dbPass); - $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); -} catch (PDOException $e) { - file_put_contents(__DIR__ . '/error_log.txt', date('Y-m-d H:i:s') . ' - Errore connessione DB: ' . $e->getMessage() . PHP_EOL, FILE_APPEND); - echo json_encode(['success' => false, 'message' => 'Errore connessione al database: ' . $e->getMessage()]); - exit(1); -} - -try { - // Query per recuperare i valori distinti di MacroMatrice, escludendo quelli che iniziano con '*' e ordinandoli - $query = "SELECT DISTINCT MacroMatrice FROM {$dbPrefix}matrici WHERE MacroMatrice IS NOT NULL AND MacroMatrice NOT LIKE '*%' ORDER BY MacroMatrice ASC"; - $stmt = $pdo->prepare($query); - $stmt->execute(); - $macroMatrici = $stmt->fetchAll(PDO::FETCH_COLUMN); - - // Debug: Log del numero di MacroMatrice recuperate - file_put_contents(__DIR__ . '/debug_log.txt', date('Y-m-d H:i:s') . ' - Retrieved ' . count($macroMatrici) . ' MacroMatrice from database' . PHP_EOL, FILE_APPEND); - - // Restituisci risposta JSON echo json_encode(['success' => true, 'value' => $macroMatrici]); -} catch (PDOException $e) { - // Log errore e restituisci risposta di errore - file_put_contents(__DIR__ . '/error_log.txt', date('Y-m-d H:i:s') . ' - Errore nel recupero delle MacroMatrice: ' . $e->getMessage() . PHP_EOL, FILE_APPEND); - echo json_encode(['success' => false, 'message' => 'Errore nel recupero delle MacroMatrice: ' . $e->getMessage()]); - exit(1); +} catch (Exception $e) { + http_response_code(500); + echo json_encode(['success' => false, 'message' => $e->getMessage()]); } diff --git a/public/userarea/get_matrici.php b/public/userarea/get_matrici.php index 7f481b6..539408f 100644 --- a/public/userarea/get_matrici.php +++ b/public/userarea/get_matrici.php @@ -1,5 +1,9 @@ 'Unauthorized']); exit; } + require_once __DIR__ . '/class/VisualLimsApiClient.class.php'; header('Content-Type: application/json'); diff --git a/public/userarea/import_insert.php b/public/userarea/import_insert.php index 04eeced..268565a 100644 --- a/public/userarea/import_insert.php +++ b/public/userarea/import_insert.php @@ -24,7 +24,7 @@ $columns = json_decode(urldecode($_POST['columns'] ?? '[]'), true); $rows = json_decode(urldecode($_POST['rows'] ?? '[]'), true); $excelrows = json_decode(urldecode($_POST['excelrows'] ?? '[]'), true); -$newFilename = htmlspecialchars($_POST['filename']); +$newFilename = $_POST['filename']; $_SESSION['template_id'] = $template_id; $_SESSION['selected_rows'] = $selected_rows; diff --git a/public/userarea/modal_partsTable.php b/public/userarea/modal_partsTable.php index 6ea4483..886d860 100644 --- a/public/userarea/modal_partsTable.php +++ b/public/userarea/modal_partsTable.php @@ -19,8 +19,6 @@ Analysis - diff --git a/public/userarea/partsTable.js b/public/userarea/partsTable.js index 6516bce..a15b002 100644 --- a/public/userarea/partsTable.js +++ b/public/userarea/partsTable.js @@ -342,51 +342,12 @@ $(document).ready(function () { // =================== function loadParts(iddatadb, idquotations, callback = null) { if (iddatadb) { - if (matrici.length === 0) { - $.ajax({ - url: "get_matrici.php", - method: "GET", - dataType: "json", - success: function (data) { - matrici = data.value || []; - loadMacroMatrici(); - initializeGlobalSelect2(); - loadPartsExtraField(iddatadb, function () { - loadPhoto(iddatadb, idquotations); - loadExistingParts(iddatadb, idquotations, callback); - }); - }, - error: function (xhr, status, error) { - matrici = []; - loadMacroMatrici(); - initializeGlobalSelect2(); - loadPartsExtraField(iddatadb, function () { - loadPhoto(iddatadb, idquotations); - loadExistingParts(iddatadb, idquotations, callback); - }); - const errorMsg = $( - '", - ); - $("#partsModal .modal-body").prepend(errorMsg); - setTimeout(function () { - errorMsg.fadeOut(500, function () { - $(this).remove(); - }); - }, 5000); - }, - }); - } else { - loadMacroMatrici(); - initializeGlobalSelect2(); - loadPartsExtraField(iddatadb, function () { - loadPhoto(iddatadb, idquotations); - loadExistingParts(iddatadb, idquotations, callback); - }); - } + loadMacroMatrici(); + initializeGlobalSelect2(); + loadPartsExtraField(iddatadb, function () { + loadPhoto(iddatadb, idquotations); + loadExistingParts(iddatadb, idquotations, callback); + }); } else { loadPartsExtraField(iddatadb, function () { loadPhoto(iddatadb, idquotations); @@ -1518,7 +1479,7 @@ $(document).ready(function () { function loadMacroMatrici() { $.ajax({ - url: "get_macro_matrici.php", + url: "search_matrici.php?macro_list=1", method: "GET", dataType: "json", success: function (data) { diff --git a/public/userarea/process_import_xls2.php b/public/userarea/process_import_xls2.php index bdfa32a..afd0cf0 100644 --- a/public/userarea/process_import_xls2.php +++ b/public/userarea/process_import_xls2.php @@ -154,7 +154,7 @@ try { $columnLetter = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($physCol); $cell = $worksheet->getCell($columnLetter . $row); $cellValue = $cell ? $cell->getCalculatedValue() : ''; - $rowData[] = htmlspecialchars($cellValue ?: ''); + $rowData[] = $cellValue ?: ''; } // Count how many header columns have data in this row diff --git a/public/userarea/search_clienti.php b/public/userarea/search_clienti.php index 1d87d91..f624c6e 100644 --- a/public/userarea/search_clienti.php +++ b/public/userarea/search_clienti.php @@ -1,6 +1,10 @@ 'Unauthorized']); exit; } + +require_once __DIR__ . '/class/VisualLimsApiClient.class.php'; header('Content-Type: application/json'); ini_set('display_errors', '0'); diff --git a/public/userarea/search_customfield_values.php b/public/userarea/search_customfield_values.php index 65fb77e..f0c8273 100644 --- a/public/userarea/search_customfield_values.php +++ b/public/userarea/search_customfield_values.php @@ -1,6 +1,10 @@ 'Unauthorized']); exit; } + +require_once __DIR__ . '/class/VisualLimsApiClient.class.php'; header('Content-Type: application/json'); ini_set('display_errors', '0'); diff --git a/public/userarea/search_matrici.php b/public/userarea/search_matrici.php index c41f274..eb75d91 100644 --- a/public/userarea/search_matrici.php +++ b/public/userarea/search_matrici.php @@ -1,4 +1,9 @@ 'Unauthorized']); exit; } + header('Content-Type: application/json'); ini_set('display_errors', '0'); @@ -42,6 +47,18 @@ if ($id !== null) { exit; } +// Return unique MacroMatrice list +if (isset($_GET['macro_list'])) { + $macros = []; + foreach ($matrici as $m) { + $mv = $m['MacroMatrice'] ?? ''; + if ($mv !== '' && !in_array($mv, $macros, true)) $macros[] = $mv; + } + sort($macros); + echo json_encode(['success' => true, 'value' => $macros]); + exit; +} + // Search (with optional MacroMatrice filter) $results = []; foreach ($matrici as $m) {