fixed accettatore

This commit is contained in:
2026-07-15 12:08:26 +02:00
parent c6168dd5d4
commit 4d447a5c0d
+53 -1
View File
@@ -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; $_SESSION['inserted_ids'] = $insertedIds;
header("Location: imported.php?id=" . urlencode($template_id) . "&importref=" . urlencode($importReferenceCode)); header("Location: imported.php?id=" . urlencode($template_id) . "&importref=" . urlencode($importReferenceCode));
exit; exit;
?>