diff --git a/public/userarea/class/VisualLimsApiClient.class.php b/public/userarea/class/VisualLimsApiClient.class.php
index e9b4a80..48e600e 100644
--- a/public/userarea/class/VisualLimsApiClient.class.php
+++ b/public/userarea/class/VisualLimsApiClient.class.php
@@ -120,4 +120,71 @@ class VisualLimsApiClient
return $data;
}
+
+ public function post($endpoint, $payload)
+ {
+ $token = $this->getToken();
+ $url = "{$this->baseUrl}/api/odata/{$endpoint}";
+
+ $ch = curl_init($url);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
+ curl_setopt($ch, CURLOPT_HTTPHEADER, [
+ "Authorization: Bearer {$token}",
+ "Content-Type: application/json",
+ "Accept: application/json"
+ ]);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+
+ $response = curl_exec($ch);
+ $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ $curl_error = curl_error($ch);
+ curl_close($ch);
+
+ if ($response === false) {
+ throw new Exception("Errore nella richiesta POST: {$curl_error}");
+ }
+
+ if ($http_code < 200 || $http_code >= 300) {
+ throw new Exception("POST fallito: HTTP {$http_code}, Risposta: " . substr($response, 0, 1000));
+ }
+
+ return json_decode($response, true);
+ }
+
+ public function patch($endpoint, $payload)
+ {
+ $token = $this->getToken();
+ $url = "{$this->baseUrl}/api/odata/{$endpoint}";
+
+ $ch = curl_init($url);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
+ curl_setopt($ch, CURLOPT_HTTPHEADER, [
+ "Authorization: Bearer {$token}",
+ "Content-Type: application/json",
+ "Accept: application/json"
+ ]);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+
+ $response = curl_exec($ch);
+ $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ $curl_error = curl_error($ch);
+ curl_close($ch);
+
+ if ($response === false) {
+ throw new Exception("Errore nella richiesta PATCH: {$curl_error}");
+ }
+
+ if ($http_code < 200 || $http_code >= 300) {
+ throw new Exception("PATCH fallito: HTTP {$http_code}, Risposta: " . substr($response, 0, 1000));
+ }
+
+ return json_decode($response, true);
+ }
+
}
diff --git a/public/userarea/export_to_lims.php b/public/userarea/export_to_lims.php
new file mode 100644
index 0000000..2a09ebf
--- /dev/null
+++ b/public/userarea/export_to_lims.php
@@ -0,0 +1,96 @@
+getConnection();
+
+header("Content-Type: application/json");
+
+try {
+ $iddatadb = $_POST['iddatadb'] ?? null;
+ if (!$iddatadb) {
+ throw new Exception("Missing iddatadb");
+ }
+
+ // ⚠️ IMPORTANT: Disable API calls, keep only DB real
+ $simulate = true;
+
+ // 🔹 STEP 1: Fetch Cliente ID from your DB
+ // get client id here
+
+ $clienteId = 12345; // Replace with actual client ID fetching logic
+
+ // 🔹 STEP 2: Fetch Parts (Campioni) for this record
+ $stmt = $pdo->prepare("
+ SELECT part_number, part_description, material, color, mix
+ FROM identification_parts
+ WHERE iddatadb = :iddatadb
+ ");
+ $stmt->execute(['iddatadb' => $iddatadb]);
+ $parts = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+ // 🔹 STEP 3: Fetch Field Values from import_data_details
+ $stmt = $pdo->prepare("
+ SELECT mapping_id, field_value
+ FROM import_data_details
+ WHERE id = :iddatadb
+ ");
+ $stmt->execute(['iddatadb' => $iddatadb]);
+ $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+ $fieldValues = [];
+ foreach ($rows as $row) {
+ $fieldValues[] = [
+ "MappingId" => (int) $row['mapping_id'],
+ "FieldValue" => $row['field_value']
+ ];
+ }
+
+ if ($simulate) {
+ // Simulated CommessaWeb
+ $commessaId = 999999;
+ $commessa = [
+ "IdCommessa" => $commessaId,
+ "CodiceCommessa" => "TEST001",
+ "StatoCommessaWeb" => "Nuova",
+ "Cliente" => $clienteId
+ ];
+
+ // Use REAL parts fetched from DB
+ $createdParts = [];
+ foreach ($parts as $p) {
+ $createdParts[] = array_merge($p, [
+ "Commessa" => $commessaId,
+ // optional: give each part a fake Campione ID just for simulation
+ "IdCampione" => rand(1000, 9999)
+ ]);
+ }
+
+ // Simulated CommessaField values
+ $createdFields = [];
+ foreach ($fieldValues as $f) {
+ $createdFields[] = [
+ "Commessa" => $commessaId,
+ "MappingId" => $f["MappingId"],
+ "FieldValue" => $f["FieldValue"],
+ "IdCommessaField" => rand(2000, 9999)
+ ];
+ }
+ }
+
+ echo json_encode([
+ "success" => true,
+ "commessaId" => $commessaId,
+ "commessa" => $commessa,
+ "parts" => $createdParts, // now comes from DB
+ "fields" => $createdFields, // simulated push
+ "simulation" => $simulate
+ ]);
+
+} catch (Exception $e) {
+ echo json_encode([
+ "success" => false,
+ "message" => $e->getMessage()
+ ]);
+}
diff --git a/public/userarea/import_edit2.php b/public/userarea/import_edit2.php
index e23039d..7c48046 100644
--- a/public/userarea/import_edit2.php
+++ b/public/userarea/import_edit2.php
@@ -709,6 +709,32 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {