diff options
author | Aleksander Machniak <alec@alec.pl> | 2012-11-16 13:22:10 +0100 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2012-11-16 13:22:10 +0100 |
commit | 3833790db4dee8607b31c84f26eb0e95bae4c906 (patch) | |
tree | f2444e19804f2174cba31d9dd61921caedfb63ee /program/steps/addressbook | |
parent | c055587d4554d5317a4bb57eaf5acbd9d56789f6 (diff) |
Support contacts import from CSV file (#1486399)
Diffstat (limited to 'program/steps/addressbook')
-rw-r--r-- | program/steps/addressbook/import.inc | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/program/steps/addressbook/import.inc b/program/steps/addressbook/import.inc index fb2251f18..6d60f829c 100644 --- a/program/steps/addressbook/import.inc +++ b/program/steps/addressbook/import.inc @@ -64,7 +64,7 @@ function rcmail_import_form($attrib) $OUTPUT->add_label('selectimportfile','importwait'); $OUTPUT->add_gui_object('importform', $attrib['id']); - $out = html::p(null, Q(rcube_label('importtext'), 'show')); + $out = html::p(null, Q(rcube_label('importdesc'), 'show')); $out .= $OUTPUT->form_tag(array( 'action' => $RCMAIL->url('import'), @@ -159,11 +159,22 @@ if (is_array($_FILES['_file'])) { $upload_error = $err; } else { + $file_content = file_get_contents($filepath); + // let rcube_vcard do the hard work :-) $vcard_o = new rcube_vcard(); $vcard_o->extend_fieldmap($CONTACTS->vcard_map); + $v_list = $vcard_o->import($file_content); + + if (!empty($v_list)) { + $vcards = array_merge($vcards, $v_list); + continue; + } - $v_list = $vcard_o->import(file_get_contents($filepath)); + // no vCards found, try CSV + $csv = new rcube_csv2vcard($_SESSION['language']); + $csv->import($file_content); + $v_list = $csv->export(); if (!empty($v_list)) { $vcards = array_merge($vcards, $v_list); @@ -181,7 +192,7 @@ if (is_array($_FILES['_file'])) { $OUTPUT->show_message('fileuploaderror', 'error'); } else { - $OUTPUT->show_message('importerror', 'error'); + $OUTPUT->show_message('importformaterror', 'error'); } } else { |