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' => '', diff --git a/modules/contacts/import_user.php b/modules/contacts/import_user.php index 229c1858ac..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)); @@ -122,11 +118,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); } }