From 4c503d61ea3cbb4fc7226501f968ba07f5bf3752 Mon Sep 17 00:00:00 2001 From: ralf Date: Tue, 29 Mar 2022 10:16:24 +0300 Subject: [PATCH] * Addressbook: allow keeping custom fileAs value (LDAP: displayname) by adding it as first option --- addressbook/inc/class.addressbook_ui.inc.php | 5 ++++- api/src/Contacts.php | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index b13390e367..52da710fd2 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -2922,6 +2922,9 @@ class addressbook_ui extends addressbook_bo $ret = array('doublicates' => array(), 'msg' => null); + // set not returned n_fileas value, to keep custom fileas value + $values['n_fileas'] = $this->fileas($values, $values['fileas_type']); + // if email changed, check for doublicates if (in_array($name, array('email', 'email_home')) && in_array('contact_'.$name, $fields)) { @@ -3595,4 +3598,4 @@ class addressbook_ui extends addressbook_bo // those options instead of the select-account options. $sel_options['history']['owner'] = ['ignore' => 'me']; } -} +} \ No newline at end of file diff --git a/api/src/Contacts.php b/api/src/Contacts.php index 3345d52142..818abf7a71 100755 --- a/api/src/Contacts.php +++ b/api/src/Contacts.php @@ -509,13 +509,14 @@ class Contacts extends Contacts\Storage { foreach($this->fileas_types as $type) { - if ($this->fileas($contact,$type) == $file_as) + if ($this->fileas($contact,$type) === $file_as) { return $type; } } } - return $this->prefs['fileas_default'] ? $this->prefs['fileas_default'] : $this->fileas_types[0]; + // if none of our types matches, but a non-empty value is set, keep it + return $file_as ?: $this->prefs['fileas_default'] ?: $this->fileas_types[0]; } /** @@ -558,9 +559,16 @@ class Contacts extends Contacts\Storage { if ($contact[$name]) $labels[$name] = $contact[$name]; } + $found = false; foreach($this->fileas_types as $fileas_type) { - $options[$fileas_type] = $this->fileas($labels,$fileas_type); + $options[$fileas_type] = $value = $this->fileas($labels,$fileas_type); + $found = $found || $value === $contact['n_fileas']; + } + // if we have a custom fileAs, add it as first option to keep it + if (!empty($contact['n_fileas']) && !$found) + { + $options = array_merge([$contact['n_fileas'] => lang('Custom').': '.$contact['n_fileas']], $options); } return $options; } @@ -2957,4 +2965,4 @@ class Contacts extends Contacts\Storage error_log("crm.php: calling push(#$this->user)->call('$func', $arg)"); return "calling push(#$this->user)->call('$func', $arg)"; } -} +} \ No newline at end of file