Skip to content

Commit

Permalink
move rcube_csv2vcard::list_fields to rcmail_action_contacts_import::l…
Browse files Browse the repository at this point in the history
…ist_fields as it relies on rcmail_action_contacts
  • Loading branch information
johndoh committed Jun 16, 2024
1 parent 90a7802 commit 7599443
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 53 deletions.
54 changes: 48 additions & 6 deletions program/actions/contacts/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'), '');
Expand Down Expand Up @@ -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;
}
}
47 changes: 0 additions & 47 deletions program/lib/Roundcube/rcube_csv2vcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 7599443

Please sign in to comment.