From 68c867a3f45b98d40fbf3dd421e35339b556e2b1 Mon Sep 17 00:00:00 2001 From: Claudio Date: Thu, 9 Oct 2025 15:30:44 +0200 Subject: [PATCH] change clienti to datadb and fixed column pages --- .../class/VisualLimsApiClient.class.php | 11 +- public/userarea/get_clienti.php | 50 ++- public/userarea/import_edit2.php | 404 +++++++++++++++--- public/userarea/import_insert.php | 11 +- public/userarea/process_import_xls2.php | 5 +- public/userarea/save_edited_row.php | 36 +- 6 files changed, 435 insertions(+), 82 deletions(-) diff --git a/public/userarea/class/VisualLimsApiClient.class.php b/public/userarea/class/VisualLimsApiClient.class.php index f1df702..ca7d5ec 100644 --- a/public/userarea/class/VisualLimsApiClient.class.php +++ b/public/userarea/class/VisualLimsApiClient.class.php @@ -29,7 +29,7 @@ class VisualLimsApiClient return self::$instance; } - private function authenticate() + private function authenticate($retryCount = 0, $maxRetries = 3) { $ch = curl_init("{$this->baseUrl}/api/authentication/authenticate"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @@ -45,16 +45,22 @@ class VisualLimsApiClient curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_VERBOSE, true); - $log = fopen(__DIR__ . '/curl_auth_debug.log', 'w') ?: fopen('php://stderr', 'w'); + $log = fopen(__DIR__ . '/curl_auth_debug.log', 'a') ?: fopen('php://stderr', 'w'); curl_setopt($ch, CURLOPT_STDERR, $log); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curl_error = curl_error($ch); + $log_message = date('Y-m-d H:i:s') . " - Auth attempt {$retryCount}: HTTP {$http_code}, Error: {$curl_error}, Response: " . substr($response, 0, 1000) . "\n"; + fwrite($log, $log_message); fclose($log); curl_close($ch); if ($response === false || $http_code != 200) { + if ($http_code === 400 && strpos($response, 'Cannot persist the object') !== false && $retryCount < $maxRetries) { + usleep(500000); // Ritardo di 500ms + return $this->authenticate($retryCount + 1, $maxRetries); // Riprova + } throw new Exception("Autenticazione fallita: HTTP {$http_code}, Errore cURL: {$curl_error}, Risposta: " . substr($response, 0, 1000)); } @@ -191,5 +197,4 @@ class VisualLimsApiClient { return $this->baseUrl; } - } diff --git a/public/userarea/get_clienti.php b/public/userarea/get_clienti.php index 4e4866a..c07c32b 100644 --- a/public/userarea/get_clienti.php +++ b/public/userarea/get_clienti.php @@ -23,16 +23,52 @@ try { // Componi endpoint finale $endpoint = "Cliente?$queryString"; - // Richiama API - $data = $api->get($endpoint); + // Funzione per eseguire la chiamata con retry + function makeApiRequest($api, $endpoint, $maxRetries = 3) + { + for ($retry = 0; $retry < $maxRetries; $retry++) { + try { + // Tenta la chiamata API + $data = $api->get($endpoint); + // Salva risposta per debug + file_put_contents(__DIR__ . '/clienti_response.json', json_encode($data, JSON_PRETTY_PRINT)); + return $data; + } catch (Exception $e) { + $errorMessage = $e->getMessage(); + // Controlla se l'errore è legato all'autenticazione (HTTP 400 con messaggio specifico) + if (strpos($errorMessage, 'HTTP 400') !== false && strpos($errorMessage, 'Cannot persist the object') !== false) { + // Forza il refresh del token + try { + // Assumi che VisualLimsApiClient abbia un metodo per il refresh del token + $api->refreshToken(); // Da implementare in VisualLimsApiClient se non esiste + error_log("Tentativo $retry: Refresh token eseguito per endpoint $endpoint"); + } catch (Exception $refreshEx) { + error_log("Errore durante il refresh del token: " . $refreshEx->getMessage()); + throw new Exception("Impossibile eseguire il refresh del token: " . $refreshEx->getMessage()); + } + // Ritarda leggermente prima del retry + usleep(500000); // 500ms + continue; + } + // Altri errori non gestiti dal retry + throw $e; + } + } + throw new Exception("Massimo numero di tentativi raggiunto per $endpoint"); + } - // Salva risposta per debug - file_put_contents(__DIR__ . '/clienti_response.json', json_encode($data, JSON_PRETTY_PRINT)); + // Esegui la chiamata con retry + $data = makeApiRequest($api, $endpoint); echo json_encode($data); } catch (Exception $e) { http_response_code(500); - echo json_encode([ - 'error' => $e->getMessage() - ]); + $errorResponse = [ + 'error' => $e->getMessage(), + 'file' => $e->getFile(), + 'line' => $e->getLine(), + 'trace' => $e->getTraceAsString() + ]; + error_log("Errore in get_clienti.php: " . json_encode($errorResponse)); + echo json_encode($errorResponse); } diff --git a/public/userarea/import_edit2.php b/public/userarea/import_edit2.php index 6aed56e..a47bf51 100644 --- a/public/userarea/import_edit2.php +++ b/public/userarea/import_edit2.php @@ -40,6 +40,12 @@ foreach ($allMappings as $mapping) { } } +// Recupera l'idclient di default dal template (se presente) +$template_stmt = $pdo->prepare("SELECT idclient FROM excel_templates WHERE id = ?"); +$template_stmt->execute([$template_id]); +$template = $template_stmt->fetch(PDO::FETCH_ASSOC); +$default_idclient = $template['idclient'] ?? null; + $insertedIds = $_POST['inserted_ids'] ?? $_SESSION['inserted_ids']; // Recupera i dati appena inseriti con i nomi degli utenti @@ -410,6 +416,46 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { .flatpickr-input { cursor: pointer; } + + .client-input { + width: 100%; + box-sizing: border-box; + border: 1px solid #ced4da; + border-radius: 4px; + padding: 5px; + font-size: 14px; + color: #333; + } + + + .client-input:focus { + outline: none; + border-color: #80bdff; + box-shadow: 0 0 5px rgba(0, 123, 255, 0.5); + } + + .select2-container { + width: 100% !important; + } + + .select2-dropdown-smaller { + font-size: 14px; + } + + .select2-container--default .select2-selection--single { + height: 31px; + border: 1px solid #ced4da; + border-radius: 4px; + padding: 5px; + } + + .select2-container--default .select2-selection--single .select2-selection__rendered { + line-height: 20px; + } + + .select2-container--default .select2-selection--single .select2-selection__arrow { + height: 31px; + } Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?> @@ -471,6 +517,13 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { ?> +
+ + + +
fetchAll(PDO::FETCH_ASSOC) as $row) {
-
Status
+
Client
+
+
Status
" . htmlspecialchars($mapping['field_label']) . "
"; @@ -604,14 +659,19 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { -
+
+ +
+
$d['datadb_id'] == $row['iddatadb']); $autoIndex = 0; foreach ($allMappings as $mapping) { @@ -840,11 +900,16 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { if (matches) { const mappingId = matches[1]; formData.append(`details${mappingId}field_value`, input.value); - if (input.tagName === 'SELECT' && input.classList.contains('dropdown-select')) { + if (input.tagName === 'SELECT') { input.setAttribute('data-selected-value', input.value); } } }); + + const idclientSelect = row.querySelector(`select[name="rows[${rowIndex}][idclient]"]`); + if (idclientSelect) { + formData.append('idclient', idclientSelect.value); + } formData.append('iddatadb', iddatadb); fetch('save_edited_row.php', { @@ -912,6 +977,11 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { } } }); + + const idclientSelect = row.querySelector(`select[name="rows[${rowIndex}][idclient]"]`); + if (idclientSelect) { + formData.append('idclient', idclientSelect.value); + } formData.append('iddatadb', iddatadb); try { @@ -984,6 +1054,90 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { - +