diff --git a/addressbook/inc/class.boXport.inc.php b/addressbook/inc/class.boXport.inc.php index 001ee201b2..55a653230c 100644 --- a/addressbook/inc/class.boXport.inc.php +++ b/addressbook/inc/class.boXport.inc.php @@ -133,7 +133,15 @@ $contacts = new import_conv; $buffer = $contacts->import_start_file($buffer); - $fp = fopen($tsvfile,'r'); + + if($tsvfile['type'] == 'application/zip') + { + $fp = $this->unzip($tsvfile['tmp_name'],$contacts->type); + } + else + { + $fp = fopen($tsvfile['tmp_name'],'r'); + } if($contacts->type == 'csv') { while($data = fgetcsv($fp,8000,',')) @@ -269,6 +277,56 @@ return $buffer; } + /* Use the Zip extension to open a zip file, hopefully containing multiple .vcf files + * Return a pointer to a temporary file that will then contain all files concatenated. + */ + function unzip($filename,$type) + { + $ext = ''; + switch($type) + { + case 'vcard': + $ext = '.vcf'; + break; + case 'csv': + $ext = '.csv'; + break; + case 'ldif': + $ext = '.ldif'; + break; + default: + return False; + } + + /* Open the (uploaded) zip file */ + $zip = zip_open($filename); + + $temp = tempnam('/tmp','zip2vcf'); + /* Open a temp file for read/write */ + $fp = fopen($temp, 'w+'); + + $out = ''; + /* Now read each entry in the zip file */ + while($dirent = zip_read($zip)) + { + if(zip_entry_open($zip,$dirent,'r')) + { + //echo '
zip_entry_name==' . zip_entry_name($dirent); + /* If an allowed extenstion based on conversion type */ + if(ereg($ext,zip_entry_name($dirent))) + { + /* Write the data to our temp file */ + $data = zip_entry_read($dirent,zip_entry_filesize($dirent)); + //echo $data; + fwrite($fp,$data); + } + zip_entry_close($dirent); + } + } + rewind($fp); + return $fp; + } + function export($conv_type,$cat_id='') { if($conv_type == 'none') diff --git a/addressbook/inc/class.uiXport.inc.php b/addressbook/inc/class.uiXport.inc.php index 8ffce2d464..41c505c8ce 100644 --- a/addressbook/inc/class.uiXport.inc.php +++ b/addressbook/inc/class.uiXport.inc.php @@ -101,6 +101,7 @@ $cat_id = get_var('cat_id','POST'); $fcat_id = get_var('fcat_id','POST'); $private = get_var('private','POST'); + $download = get_var('download','POST'); if($convert) { @@ -115,11 +116,11 @@ $GLOBALS['phpgw']->common->phpgw_footer(); $GLOBALS['phpgw']->common->phpgw_exit(); } - $buffer = $this->bo->import($tsvfile['tmp_name'],$conv_type,$private,$fcat_id); + $buffer = $this->bo->import($tsvfile,$conv_type,$private,$fcat_id); if($download == '') { - if($conv_type == 'Debug LDAP' || $conv_type == 'Debug SQL' ) + if($conv_type == 'Debug LDAP' || $conv_type == 'Debug SQL') { // filename, default application/octet-stream, length of file, default nocache True $GLOBALS['phpgw']->browser->content_header($tsvfilename,'',strlen($buffer)); @@ -189,6 +190,19 @@ $this->template->set_var('filter',$this->filter); $this->template->set_var('query',$this->query); $this->template->set_var('cat_id',$this->cat_id); + $this->template->set_var('lang_import_instructions',lang('import_instructions')); + if(extension_loaded('zip')) + { + $this->template->set_var('zip_note',lang('zip_note')); + } + else + { + $this->template->set_var('zip_note',''); + } + $this->template->set_var('lang_exported_file',lang('enter the path to the exported file here')); + $this->template->set_var('lang_conv_type',lang('select the type of conversion')); + $this->template->set_var('lang_mark_priv',lang('Mark records as private')); + $this->template->set_var('lang_debug',lang('Debug output in browser')); $this->template->pparse('out','import'); } // $GLOBALS['phpgw']->common->phpgw_footer(); diff --git a/addressbook/setup/phpgw_en.lang b/addressbook/setup/phpgw_en.lang index 3360fec078..ba93bb08b5 100644 --- a/addressbook/setup/phpgw_en.lang +++ b/addressbook/setup/phpgw_en.lang @@ -147,3 +147,9 @@ work phone addressbook en Work Phone you must select a vcard. (*.vcf) addressbook en You must select a vcard. (*.vcf) you must select at least 1 column to display addressbook en You must select at least 1 column to display zip code common en ZIP Code +import_instructions addressbook en In Netscape, open the Addressbook and select Export from the File menu. The file exported will be in LDIF format.

Or, in Outlook, select your Contacts folder, select Import and Export... from the File menu and export your contacts into a comma separated text (CSV) file.

Or, in Palm Desktop 4.0 or greater, visit your addressbook and select Export from the File menu. The file exported will be in VCard format. +zip_note addressbook en

Note: The file may be a zip file collection of .csv, .vcf, or .ldif files. However, do not mix file types per import. +enter the path to the exported file here addressbook en Enter the path to the exported file here +select the type of conversion addressbook en Select the type of conversion +mark records as private addressbook en Mark records as private +debug output in browser addressbook en Debug output in browser diff --git a/addressbook/templates/default/import.tpl b/addressbook/templates/default/import.tpl index b94948de5f..667f163814 100644 --- a/addressbook/templates/default/import.tpl +++ b/addressbook/templates/default/import.tpl @@ -1,50 +1,45 @@ -

- - - - - -
{import_text}
-
- - - - - + + -
-
    -
  1. In Netscape, open the Addressbook and select Export from the File menu. - The file exported will be in LDIF format. -

    Or, in Outlook, select your Contacts folder, select Import - and Export... from the File - menu and export your contacts into a comma separated text (CSV) file. -

    Or, in Palm Desktop 4.0 or greater, visit your addressbook and select Export from the File menu. - The file exported will be in VCard format.

    -

  2. -
  3. Enter the path to the exported file here: -

  4. -
  5. Select the type of conversion: - + + + + + + + + - -
    {import_text}
    + + + +
    +
      +
    1. {lang_import_instructions}{zip_note}
    2. +
    3. {lang_exported_file} +

    4. +
    5. {lang_conv_type}: +

    6. -
    7. {lang_cat}:{cat_link}
    8. -
    9. Mark records as private
    10. -
    11. Debug output in browser
    12. -
    13. -
    +

    +

  6. {lang_cat}:{cat_link}
  7. +
  8. {lang_mark_priv}
  9. +
  10. {lang_debug}
  11. + +
    +
    +
    + + -
    -
-
@@ -58,6 +53,6 @@
   
- +
+