From 650a2ecf1569b22c1ca486e29dfa0e5c69cabe58 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer Date: Tue, 7 Oct 2025 22:02:37 +0200 Subject: [PATCH 1/3] Contacts import: If a table column has no name/header, it "Column NN" instead Spreadsheet import returns NULL on empty cells, so a column without headers would have a null value to be displayed in the combobox, causing admidio to crash. This patch makes sure that all columns have a human-readable name for display. Internally, the column index is used anyway. --- languages/en.xml | 1 + modules/contacts/import_column_config.php | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/languages/en.xml b/languages/en.xml index 6401bb6caf..f8762b0a4f 100644 --- a/languages/en.xml +++ b/languages/en.xml @@ -344,6 +344,7 @@ Secondary Color The secondary color used for Admidio. The side bar will use this color, as well as the preferences sections. Column + Column #VAR1# Column selection Selects the columns to be displayed in the list.\n\n Inactive roles are marked with (*). Comma (,) diff --git a/modules/contacts/import_column_config.php b/modules/contacts/import_column_config.php index 42e8a6bc50..2c5d30800d 100644 --- a/modules/contacts/import_column_config.php +++ b/modules/contacts/import_column_config.php @@ -70,6 +70,13 @@ $categoryId = null; $arrayImportableFields = array(); + // Cleanup CSV columns: If a column does not have a header (null value), use its position instead + foreach ($arrayCsvColumns as $pos => $column) { + if (empty($column)) { + $arrayCsvColumns[$pos] = $gL10n->get('SYS_COLUMN_POS', array($pos)); + } + } + $arrayImportableFields[] = array( 'cat_name' => $gL10n->get('SYS_BASIC_DATA'), 'cat_tooltip' => '', From 18ce54462630077bd4e05d046e7e7dff4ba1d44f Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer Date: Tue, 7 Oct 2025 22:04:30 +0200 Subject: [PATCH 2/3] Contacts Import: Allow importing usename without password Allows importing a username without setting a password. The user will need to reset the password immediately. This is much more secure than setting some default password and telling the user via mail. --- modules/contacts/import_user.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/modules/contacts/import_user.php b/modules/contacts/import_user.php index 229c1858ac..07b2810808 100644 --- a/modules/contacts/import_user.php +++ b/modules/contacts/import_user.php @@ -122,11 +122,25 @@ } // add login data to the user - if ($userLoginName !== '' && $userPassword !== '') { - try { - $userImport->setLoginData($userLoginName, $userPassword); - } catch (Exception $e) { - $importMessages[] = $e->getMessage(); + // Ideally, both username and password are set using the same import + // Setting username without password is possible (user needs to reset password to be able to log in) + // Setting the password only should only be possible if an existing user already has a username assigned + if ($userPassword !== '') { + if ($userLoginName == '') { + $userLoginName = $userImport->getValue('usr_login_name'); + } + if (!empty($userLoginName)) { + try { + $userImport->setLoginData($userLoginName, $userPassword); + } catch (Exception $e) { + $importMessages[] = $e->getMessage(); + } + } else { + $importMessages[] = $userImport->getValue('FIRST_NAME') . ' ' . $userImport->getValue('LAST_NAME') . ": password given for new user, but no username"; + } + } else { + if (!empty($userLoginName)) { + $userImport->setValue('usr_login_name', $userLoginName); } } From 9d603daa1ce6c0303b43cfaf47b1b0c08c5d3142 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer Date: Tue, 7 Oct 2025 23:14:08 +0200 Subject: [PATCH 3/3] Contacts Import: Allow using the same column for multiple profile fields Rather than looping through all columns of the imported data and retrieve the column to which it is assigned (implicit assumption: each column in the imported data shall only be assigned to one profile field), we now loop through all profile fields that are assigned an import column. Use cases: company name (employer and licensee), names (personal data and contact for business memberships), etc. --- modules/contacts/import_user.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/modules/contacts/import_user.php b/modules/contacts/import_user.php index 07b2810808..98ce8d71db 100644 --- a/modules/contacts/import_user.php +++ b/modules/contacts/import_user.php @@ -93,13 +93,9 @@ ); } - foreach ($line as $columnKey => $columnValue) { - if (empty($columnValue)) { - $columnValue = ''; - } + foreach ($importProfileFields as $assignedFieldColumnId => $columnKey) { + $columnValue = $line[$columnKey] ?? ''; - // get usf id or database column name - $assignedFieldColumnId = array_search($columnKey, $importProfileFields); // remove spaces and html tags $columnValue = trim(strip_tags($columnValue));