]> git.donarmstrong.com Git - roundcube.git/blobdiff - program/steps/addressbook/import.inc
Imported Upstream version 0.5.1
[roundcube.git] / program / steps / addressbook / import.inc
index 8140a85266e9a749c9c6717380d1b84f8194c730..7f979de825928042877605af7829cfd6f3ab1dc7 100644 (file)
@@ -4,8 +4,8 @@
  +-----------------------------------------------------------------------+
  | program/steps/addressbook/import.inc                                  |
  |                                                                       |
- | This file is part of the RoundCube Webmail client                     |
- | Copyright (C) 2008-2009, RoundCube Dev. - Switzerland                 |
+ | This file is part of the Roundcube Webmail client                     |
+ | Copyright (C) 2008-2009, Roundcube Dev. - Switzerland                 |
  | Licensed under the GNU GPL                                            |
  |                                                                       |
  | PURPOSE:                                                              |
 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();
+
   $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')) . html::br() . $upload->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)) .
@@ -74,19 +78,20 @@ function rcmail_import_confirm($attrib)
 function rcmail_import_buttons($attrib)
 {
   global $IMPORT_STATS, $OUTPUT;
+  $target = get_input_value('_target', RCUBE_INPUT_GPC);
   
-  $attrib += array('type' => "input");
+  $attrib += array('type' => 'input');
   unset($attrib['name']);
   
   if (is_object($IMPORT_STATS)) {
     $attrib['class'] = trim($attrib['class'] . ' mainaction');
-    $out = $OUTPUT->button(array('command' => "list", 'label' => "done") + $attrib);
+    $out = $OUTPUT->button(array('command' => 'list', 'prop' => $target, 'label' => 'done') + $attrib);
   }
   else {
-    $out = $OUTPUT->button(array('command' => "list", 'label' => "cancel") + $attrib);
+    $out = $OUTPUT->button(array('command' => 'list', 'label' => 'cancel') + $attrib);
     $out .= ' ';
     $attrib['class'] = trim($attrib['class'] . ' mainaction');
-    $out .= $OUTPUT->button(array('command' => "import", 'label' => "import") + $attrib);
+    $out .= $OUTPUT->button(array('command' => 'import', 'label' => 'import') + $attrib);
   }
   
   return $out;
@@ -98,9 +103,9 @@ function rcmail_import_buttons($attrib)
 $importstep = 'rcmail_import_form';
 
 if ($_FILES['_file']['tmp_name'] && is_uploaded_file($_FILES['_file']['tmp_name'])) {
-
   $replace = (bool)get_input_value('_replace', RCUBE_INPUT_GPC);
-  $CONTACTS = $RCMAIL->get_address_book(null, true);
+  $target = get_input_value('_target', RCUBE_INPUT_GPC);
+  $CONTACTS = $RCMAIL->get_address_book($target, true);
 
   // let rcube_vcard do the hard work :-)
   $vcards = rcube_vcard::import(file_get_contents($_FILES['_file']['tmp_name']));
@@ -129,6 +134,9 @@ if ($_FILES['_file']['tmp_name'] && is_uploaded_file($_FILES['_file']['tmp_name'
         $IMPORT_STATS->nomail++;
         continue;
       }
+
+      // We're using UTF8 internally
+      $email = rcube_idn_to_utf8($email);
       
       if (!$replace) {
         // compare e-mail address
@@ -142,19 +150,27 @@ if ($_FILES['_file']['tmp_name'] && is_uploaded_file($_FILES['_file']['tmp_name'
         }
       }
       
-      $success = $CONTACTS->insert(array(
+      $a_record = array(
         'name' => $vcard->displayname,
         'firstname' => $vcard->firstname,
         'surname' => $vcard->surname,
         'email' => $email,
         'vcard' => $vcard->export(),
-      ));
+      );
       
+      $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $a_record, 'source' => null));
+      $a_record = $plugin['record'];
+
+      // insert record and send response
+      if (!$plugin['abort'])
+        $success = $CONTACTS->insert($a_record);
+      else
+        $success = $plugin['result'];
+
       if ($success) {
         $IMPORT_STATS->inserted++;
         $IMPORT_STATS->names[] = $vcard->displayname;
-      }
-      else {
+      } else {
         $IMPORT_STATS->errors++;
       }
     }
@@ -165,8 +181,7 @@ if ($_FILES['_file']['tmp_name'] && is_uploaded_file($_FILES['_file']['tmp_name'
 else if ($err = $_FILES['_file']['error']) {
   if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) {
     $OUTPUT->show_message('filesizeerror', 'error', array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize')))));
-  }
-  else {
+  } else {
     $OUTPUT->show_message('fileuploaderror', 'error');
   }
 }
@@ -181,5 +196,3 @@ $OUTPUT->add_handlers(array(
 
 // render page
 $OUTPUT->send('importcontacts');
-
-?>
\ No newline at end of file