From 7599443545c367ffb6fe9d8811d1552da08ac0e8 Mon Sep 17 00:00:00 2001 From: PhilW Date: Sun, 16 Jun 2024 11:17:45 +0100 Subject: [PATCH] move rcube_csv2vcard::list_fields to rcmail_action_contacts_import::list_fields as it relies on rcmail_action_contacts --- program/actions/contacts/import.php | 54 ++++++++++++++++++++--- program/lib/Roundcube/rcube_csv2vcard.php | 47 -------------------- 2 files changed, 48 insertions(+), 53 deletions(-) diff --git a/program/actions/contacts/import.php b/program/actions/contacts/import.php index fe97a591b31..6f234b4e8d6 100644 --- a/program/actions/contacts/import.php +++ b/program/actions/contacts/import.php @@ -368,12 +368,7 @@ public static function import_map($attrib) $rcmail = rcmail::get_instance(); $params = $_SESSION['contactcsvimport']['params']; - $available_fields = rcube_csv2vcard::list_fields(); - - // remove groups field if group import is not enabled - if (empty($params['with_groups'])) { - unset($available_fields['groups']); - } + $available_fields = self::list_fields(!empty($params['with_groups'])); $fieldlist = new html_select(['name' => '_map[]']); $fieldlist->add($rcmail->gettext('fieldnotmapped'), ''); @@ -470,4 +465,51 @@ public static function import_group_id($group_name, $contacts, $create, &$import return $group_id; } + + /** + * Returns the list of contact fields available for import + */ + public static function list_fields($groups) + { + $rcmail = rcmail::get_instance(); + $available_fields = []; + + foreach (self::$CONTACT_COLTYPES as $id => $field) { + if ($id == 'photo') { + // skip photo field because there are no photos in CSV files + continue; + } + + if (!empty($field['subtypes'])) { + $subtype_names = array_map('rcmail_action_contacts_index::get_type_label', $field['subtypes']); + + for ($i = 0; $i < count($field['subtypes']); $i++) { + if (!empty($field['childs'])) { + foreach ($field['childs'] as $cid => $child) { + $available_fields[$cid . ':' . $field['subtypes'][$i]] = $child['label'] . ' - ' . $subtype_names[$i]; + } + } else { + $available_fields[$id . ':' . $field['subtypes'][$i]] = $field['label'] . ' - ' . $subtype_names[$i]; + } + } + } else { + $available_fields[$id] = $field['label']; + } + } + + if ($groups) { + // allow importing of group assignments + $available_fields['groups'] = $rcmail->gettext('groups'); + } + + // add separate birthday date parts fields for thunderbird imports + $available_fields['birthday-d'] = $rcmail->gettext('birth_day'); + $available_fields['birthday-m'] = $rcmail->gettext('birth_month'); + $available_fields['birthday-y'] = $rcmail->gettext('birth_year'); + + // sort by label for easy use + asort($available_fields, \SORT_LOCALE_STRING); + + return $available_fields; + } } diff --git a/program/lib/Roundcube/rcube_csv2vcard.php b/program/lib/Roundcube/rcube_csv2vcard.php index 5addf35dc10..b9bbdbd9646 100644 --- a/program/lib/Roundcube/rcube_csv2vcard.php +++ b/program/lib/Roundcube/rcube_csv2vcard.php @@ -342,53 +342,6 @@ public function import($csv, $dry_run = false, $skip_head = true) return null; } - /** - * Get list of contact fields available for import - * - * @return array string List of fields - */ - public static function list_fields() - { - $rcmail = rcmail::get_instance(); - $available_fields = []; - - foreach (rcmail_action_contacts_index::$CONTACT_COLTYPES as $id => $field) { - if ($id == 'photo') { - // skip photo field because there are no photos in CSV files - continue; - } - - if (!empty($field['subtypes'])) { - $subtype_names = array_map('rcmail_action_contacts_index::get_type_label', $field['subtypes']); - - for ($i = 0; $i < count($field['subtypes']); $i++) { - if (!empty($field['childs'])) { - foreach ($field['childs'] as $cid => $child) { - $available_fields[$cid . ':' . $field['subtypes'][$i]] = $child['label'] . ' - ' . $subtype_names[$i]; - } - } else { - $available_fields[$id . ':' . $field['subtypes'][$i]] = $field['label'] . ' - ' . $subtype_names[$i]; - } - } - } else { - $available_fields[$id] = $field['label']; - } - } - - // allow importing of group assignments - $available_fields['groups'] = $rcmail->gettext('groups'); - - // add separate birthday date parts fields for thunderbird imports - $available_fields['birthday-d'] = $rcmail->gettext('birth_day'); - $available_fields['birthday-m'] = $rcmail->gettext('birth_month'); - $available_fields['birthday-y'] = $rcmail->gettext('birth_year'); - - // sort by label for easy use - asort($available_fields, \SORT_LOCALE_STRING); - - return $available_fields; - } - /** * Set field mapping info *