From 4d447a5c0d29b1392bb4a2f77a69b4d7aebc375c Mon Sep 17 00:00:00 2001 From: solocla Date: Wed, 15 Jul 2026 12:08:26 +0200 Subject: [PATCH] fixed accettatore --- public/userarea/import_insert.php | 54 ++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/public/userarea/import_insert.php b/public/userarea/import_insert.php index 268565ab..aa1ea870 100644 --- a/public/userarea/import_insert.php +++ b/public/userarea/import_insert.php @@ -154,8 +154,60 @@ foreach ($selected_rows as $rowIndex) { } } +// ------------------------------------------------------------ +// AUTO SET: schema field_id = 244 (Accettatore) con auth_users.lims_user_id +// Spostato dal vecchio flusso (import_edit.php) al flusso nuovo. +// Autocompila il custom field 244 con il lims_user_id dell'utente loggato. +// ------------------------------------------------------------ +try { + // 1) Leggi il lims_user_id dell'utente loggato + $stmtUser = $pdo->prepare("SELECT lims_user_id FROM auth_users WHERE id = ? LIMIT 1"); + $stmtUser->execute([(int)$user_id]); + $limsUserId = $stmtUser->fetchColumn(); + + // normalize + $limsUserId = ($limsUserId !== false && $limsUserId !== null && $limsUserId !== '') ? (string)$limsUserId : ''; + + if ($limsUserId !== '' && !empty($insertedIds)) { + + // 2) Trova il mapping_id per field_id = 244 in questo template + $stmtMap = $pdo->prepare("SELECT id FROM template_mapping WHERE template_id = ? AND field_id = 244 LIMIT 1"); + $stmtMap->execute([(int)$template_id]); + $mappingId244 = (int)$stmtMap->fetchColumn(); + + if ($mappingId244 > 0) { + + // 3) Upsert del valore in import_data_details per ogni riga inserita + $pdo->beginTransaction(); + + $updStmt = $pdo->prepare("UPDATE import_data_details SET field_value = ? WHERE id = ? AND mapping_id = ?"); + $insStmt = $pdo->prepare("INSERT INTO import_data_details (id, mapping_id, field_value) VALUES (?, ?, ?)"); + + foreach ($insertedIds as $iddatadb) { + $iddatadb = (int)$iddatadb; + if ($iddatadb <= 0) continue; + + $updStmt->execute([$limsUserId, $iddatadb, $mappingId244]); + + if ($updStmt->rowCount() === 0) { + $insStmt->execute([$iddatadb, $mappingId244, $limsUserId]); + } + } + + $pdo->commit(); + } else { + error_log("[AUTO FIELD 244] Nessun mapping field_id=244 per template $template_id"); + } + } else { + error_log("[AUTO FIELD 244] limsUserId vuoto per user_id=$user_id o nessuna riga inserita"); + } +} catch (Exception $e) { + // Non bloccare l'import se questo fallisce; logga soltanto + error_log("[AUTO FIELD 244] " . $e->getMessage()); + if ($pdo->inTransaction()) $pdo->rollBack(); +} + $_SESSION['inserted_ids'] = $insertedIds; header("Location: imported.php?id=" . urlencode($template_id) . "&importref=" . urlencode($importReferenceCode)); exit; -?>