diff options
Diffstat (limited to 'program/steps/addressbook/import.inc')
-rw-r--r-- | program/steps/addressbook/import.inc | 65 |
1 files changed, 40 insertions, 25 deletions
diff --git a/program/steps/addressbook/import.inc b/program/steps/addressbook/import.inc index 4583be508..fdac9625f 100644 --- a/program/steps/addressbook/import.inc +++ b/program/steps/addressbook/import.inc @@ -13,9 +13,10 @@ | | +-----------------------------------------------------------------------+ | Author: Thomas Bruederli <roundcube@gmail.com> | + | Author: Aleksander Machniak <machniak@kolabsys.com> | +-----------------------------------------------------------------------+ - $Id: $ + $Id$ */ @@ -26,30 +27,44 @@ function rcmail_import_form($attrib) { global $RCMAIL, $OUTPUT; $target = get_input_value('_target', RCUBE_INPUT_GPC); - + $attrib += array('id' => "rcmImportForm"); - - $abook = new html_hiddenfield(array('name' => '_target', 'value' => $target)); - $form = $abook->show(); + + $writable_books = $RCMAIL->get_address_sources(true); $upload = new html_inputfield(array('type' => 'file', 'name' => '_file', 'id' => 'rcmimportfile', 'size' => 40)); - $form .= html::p(null, html::label('rcmimportfile', rcube_label('importfromfile')) . html::br() . $upload->show()); - + $form = html::p(null, html::label('rcmimportfile', rcube_label('importfromfile')) . $upload->show()); + + // addressbook selector + if (count($writable_books) > 1) { + $select = new html_select(array('name' => '_target', 'id' => 'rcmimporttarget')); + + foreach ($writable_books as $book) + $select->add($book['name'], $book['id']); + + $form .= html::p(null, html::label('rcmimporttarget', rcube_label('importtarget')) + . $select->show($target)); + } + else { + $abook = new html_hiddenfield(array('name' => '_target', 'value' => key($writable_books))); + $form .= $abook->show(); + } + $check_replace = new html_checkbox(array('name' => '_replace', 'value' => 1, 'id' => 'rcmimportreplace')); $form .= html::p(null, $check_replace->show(get_input_value('_replace', RCUBE_INPUT_GPC)) . html::label('rcmimportreplace', rcube_label('importreplace'))); - + $OUTPUT->add_label('selectimportfile','importwait'); $OUTPUT->add_gui_object('importform', $attrib['id']); - + $out = html::p(null, Q(rcube_label('importtext'), 'show')); - + $out .= $OUTPUT->form_tag(array( 'action' => $RCMAIL->url('import'), 'method' => 'post', 'enctype' => 'multipart/form-data') + $attrib, $form); - + return $out; } @@ -60,19 +75,19 @@ function rcmail_import_form($attrib) function rcmail_import_confirm($attrib) { global $IMPORT_STATS; - + $vars = get_object_vars($IMPORT_STATS); $vars['names'] = $vars['skipped_names'] = ''; - + $content = html::p(null, rcube_label(array( 'name' => 'importconfirm', 'nr' => $IMORT_STATS->inserted, 'vars' => $vars, )) . ($IMPORT_STATS->names ? ':' : '.')); - + if ($IMPORT_STATS->names) $content .= html::p('em', join(', ', array_map('Q', $IMPORT_STATS->names))); - + if ($IMPORT_STATS->skipped) { $content .= html::p(null, rcube_label(array( 'name' => 'importconfirmskipped', @@ -81,7 +96,7 @@ function rcmail_import_confirm($attrib) )) . ':'); $content .= html::p('em', join(', ', array_map('Q', $IMPORT_STATS->skipped_names))); } - + return html::div($attrib, $content); } @@ -93,10 +108,10 @@ function rcmail_import_buttons($attrib) { global $IMPORT_STATS, $OUTPUT; $target = get_input_value('_target', RCUBE_INPUT_GPC); - + $attrib += array('type' => 'input'); unset($attrib['name']); - + if (is_object($IMPORT_STATS)) { $attrib['class'] = trim($attrib['class'] . ' mainaction'); $out = $OUTPUT->button(array('command' => 'list', 'prop' => $target, 'label' => 'done') + $attrib); @@ -107,7 +122,7 @@ function rcmail_import_buttons($attrib) $attrib['class'] = trim($attrib['class'] . ' mainaction'); $out .= $OUTPUT->button(array('command' => 'import', 'label' => 'import') + $attrib); } - + return $out; } @@ -137,13 +152,13 @@ if ($_FILES['_file']['tmp_name'] && is_uploaded_file($_FILES['_file']['tmp_name' $IMPORT_STATS->skipped_names = array(); $IMPORT_STATS->count = count($vcards); $IMPORT_STATS->inserted = $IMPORT_STATS->skipped = $IMPORT_STATS->nomail = $IMPORT_STATS->errors = 0; - + if ($replace) $CONTACTS->delete_all(); - + foreach ($vcards as $vcard) { $email = $vcard->email[0]; - + // skip entries without an e-mail address if (empty($email)) { $IMPORT_STATS->nomail++; @@ -152,7 +167,7 @@ if ($_FILES['_file']['tmp_name'] && is_uploaded_file($_FILES['_file']['tmp_name' // We're using UTF8 internally $email = rcube_idn_to_utf8($email); - + if (!$replace && $email) { // compare e-mail address $existing = $CONTACTS->search('email', $email, false, false); @@ -165,10 +180,10 @@ if ($_FILES['_file']['tmp_name'] && is_uploaded_file($_FILES['_file']['tmp_name' continue; } } - + $a_record = $vcard->get_assoc(); $a_record['vcard'] = $vcard->export(); - + $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $a_record, 'source' => null)); $a_record = $plugin['record']; |