diff --git a/program/actions/contacts/import.php b/program/actions/contacts/import.php index a759588f52..89742532e2 100644 --- a/program/actions/contacts/import.php +++ b/program/actions/contacts/import.php @@ -367,43 +367,13 @@ public static function import_map($attrib) $rcmail = rcmail::get_instance(); $params = $_SESSION['contactcsvimport']['params']; - $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']; - } - } + $available_fields = rcube_csv2vcard::list_fields(); - // allow importing of group assignments - if (!empty($params['with_groups'])) { - $available_fields['groups'] = $rcmail->gettext('groups'); + // remove groups field if group import is not enabled + if (empty($params['with_groups'])) { + unset($available_fields['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); - $fieldlist = new html_select(['name' => '_map[]']); $fieldlist->add($rcmail->gettext('fieldnotmapped'), ''); $fieldlist->add(array_values($available_fields), array_keys($available_fields)); diff --git a/program/lib/Roundcube/rcube_csv2vcard.php b/program/lib/Roundcube/rcube_csv2vcard.php index b9bbdbd964..5addf35dc1 100644 --- a/program/lib/Roundcube/rcube_csv2vcard.php +++ b/program/lib/Roundcube/rcube_csv2vcard.php @@ -342,6 +342,53 @@ 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 *