diff --git a/addressbook/inc/class.boXport.inc.php b/addressbook/inc/class.boXport.inc.php
new file mode 100644
index 0000000000..5029e64d7d
--- /dev/null
+++ b/addressbook/inc/class.boXport.inc.php
@@ -0,0 +1,309 @@
+ *
+ * -------------------------------------------- *
+ * This program is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU General Public License as published by the *
+ * Free Software Foundation; either version 2 of the License, or (at your *
+ * option) any later version. *
+ \**************************************************************************/
+
+ /* $Id$ */
+
+ class boXport
+ {
+ var $public_functions = array(
+ 'import' => True,
+ 'export' => True
+ );
+
+ var $so;
+ var $contacts;
+
+ var $start;
+ var $limit;
+ var $query;
+ var $sort;
+ var $order;
+ var $filter;
+ var $cat_id;
+
+ var $use_session = False;
+
+ function boXport ($session=False)
+ {
+ global $phpgw;
+
+ $this->contacts = &$phpgw->contacts;
+ $this->so = CreateObject('addressbook.soaddressbook');
+ if($session)
+ {
+ $this->read_sessiondata();
+ $this->use_session = True;
+ }
+ global $start,$limit,$query,$sort,$order,$filter,$cat_id;
+
+ if($start || $start == 0) { $this->start = $start; }
+ if($limit) { $this->limit = $limit; }
+ if($query) { $this->query = $query; }
+ if($sort) { $this->sort = $sort; }
+ if($order) { $this->order = $order; }
+ if($filter) { $this->filter = $filter; }
+ $this->cat_id = $cat_id;
+ }
+
+ function save_sessiondata()
+ {
+ global $phpgw,$start,$limit,$query,$sort,$order,$filter,$cat_id;
+
+ if ($this->use_session)
+ {
+ $data = array(
+ 'start' => $start,
+ 'limit' => $limit,
+ 'query' => $query,
+ 'sort' => $sort,
+ 'order' => $order,
+ 'filter' => $filter,
+ 'cat_id' => $cat_id
+ );
+ if($this->debug) { echo '
Save:'; _debug_array($data); }
+ $phpgw->session->appsession('session_data','addressbook',$data);
+ }
+ }
+
+ function read_sessiondata()
+ {
+ global $phpgw;
+
+ $data = $phpgw->session->appsession('session_data','addressbook');
+ if($this->debug) { echo '
Read:'; _debug_array($data); }
+
+ $this->start = $data['start'];
+ $this->limit = $data['limit'];
+ $this->query = $data['query'];
+ $this->sort = $data['sort'];
+ $this->order = $data['order'];
+ $this->filter = $data['filter'];
+ $this->cat_id = $data['cat_id'];
+ }
+
+ function import()
+ {
+ global $tsvfile,$private;
+
+ include (PHPGW_APP_INC . '/import/' . $conv_type);
+
+ if ($private == '') { $private = 'public'; }
+ $row = 0;
+ $buffer = array();
+ $contacts = new import_conv;
+
+ $buffer = $contacts->import_start_file($buffer);
+ $fp = fopen($tsvfile,'r');
+ if ($contacts->type == 'csv')
+ {
+ while ($data = fgetcsv($fp,8000,','))
+ {
+ $num = count($data);
+ $row++;
+ if ($row == 1)
+ {
+ $header = $data;
+ /* Changed here to ignore the header, set to our array
+ while(list($lhs,$rhs) = each($contacts->import))
+ {
+ $header[] = $lhs;
+ }
+ */
+ }
+ else
+ {
+ $buffer = $contacts->import_start_record($buffer);
+ for ($c=0; $c<$num; $c++ )
+ {
+ //Send name/value pairs along with the buffer
+ if ($contacts->import[$header[$c]] != '' && $data[$c] != '')
+ {
+ $buffer = $contacts->import_new_attrib($buffer, $contacts->import[$header[$c]],$data[$c]);
+ }
+ }
+ $buffer = $contacts->import_end_record($buffer,$private);
+ }
+ }
+ }
+ elseif ($contacts->type == 'ldif')
+ {
+ while ($data = fgets($fp,8000))
+ {
+ $url = "";
+ list($name,$value,$extra) = split(':', $data);
+ if (substr($name,0,2) == 'dn')
+ {
+ $buffer = $contacts->import_start_record($buffer);
+ }
+
+ $test = trim($value);
+ if ($name && !empty($test) && $extra)
+ {
+ // Probable url string
+ $url = $test;
+ $value = $extra;
+ }
+ elseif ($name && empty($test) && $extra)
+ {
+ // Probable multiline encoding
+ $newval = base64_decode(trim($extra));
+ $value = $newval;
+ //echo $name.':'.$value;
+ }
+
+ if ($name && $value)
+ {
+ $test = split(',mail=',$value);
+ if ($test[1])
+ {
+ $name = "mail";
+ $value = $test[1];
+ }
+ if ($url)
+ {
+ $name = "homeurl";
+ $value = $url. ':' . $value;
+ }
+ //echo '
'.$j.': '.$name.' => '.$value;
+ if ($contacts->import[$name] != '' && $value != '')
+ {
+ $buffer = $contacts->import_new_attrib($buffer, $contacts->import[$name],$value);
+ }
+ }
+ else
+ {
+ $buffer = $contacts->import_end_record($buffer,$private);
+ }
+ }
+ }
+ else
+ {
+ while ($data = fgets($fp,8000))
+ {
+ $data = trim($data); // RB 2001/05/07 added for Lotus Organizer
+ while (substr($data,-1) == '=') { // '=' at end-of-line --> line to be continued with next line
+ $data = substr($data,0,-1) . trim(fgets($fp,8000));
+ }
+ if (strstr($data,';ENCODING=QUOTED-PRINTABLE')) { // RB 2001/05/07 added for Lotus Organizer
+ $data = quoted_printable_decode(str_replace(';ENCODING=QUOTED-PRINTABLE','',$data));
+ }
+ list($name,$value) = explode(':', $data,2); // RB 2001/05/09 to allow ':' in Values (not only in URL's)
+
+ if (strtolower(substr($name,0,5)) == 'begin')
+ {
+ $buffer = $contacts->import_start_record($buffer);
+ }
+ if ($name && $value)
+ {
+ reset($contacts->import);
+ while ( list($fname,$fvalue) = each($contacts->import) )
+ {
+ if ( strstr(strtolower($name), $contacts->import[$fname]) )
+ {
+ $buffer = $contacts->import_new_attrib($buffer,$name,$value);
+ }
+ }
+ }
+ else
+ {
+ $buffer = $contacts->import_end_record($buffer);
+ }
+ }
+ }
+
+ fclose($fp);
+ $buffer = $contacts->import_end_file($buffer,$private,$cat_id);
+
+ if ($download == '')
+ {
+ if($conv_type == 'Debug LDAP' || $conv_type == 'Debug SQL' )
+ {
+ // filename, default application/octet-stream, length of file, default nocache True
+ $phpgw->browser->content_header($tsvfilename,'',strlen($buffer));
+ echo $buffer;
+ }
+ else
+ {
+ $phpgw->common->phpgw_header();
+ echo parse_navbar();
+ echo "
$buffer"; + echo ''.lang("OK").''; + $phpgw->common->phpgw_footer(); + } + } + else + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + echo "
$buffer"; + echo ''.lang("OK").''; + $phpgw->common->phpgw_footer(); + } + } + + function export() + { + global $phpgw_info; + + include (PHPGW_APP_INC . '/export/' . $conv_type); + $buffer=array(); + $contacts = new export_conv; + + // Read in user custom fields, if any + $customfields = array(); + while (list($col,$descr) = @each($phpgw_info['user']['preferences']['addressbook'])) + { + if ( substr($col,0,6) == 'extra_' ) + { + $field = ereg_replace('extra_','',$col); + $field = ereg_replace(' ','_',$field); + $customfields[$field] = ucfirst($field); + } + } + $extrafields = array( + 'ophone' => 'ophone', + 'address2' => 'address2', + 'address3' => 'address3' + ); + if ($contacts->type != 'vcard') + { + $contacts->qfields = $contacts->stock_contact_fields;# + $extrafields;# + $customfields; + } + + if (!empty($cat_id)) + { + $buffer = $contacts->export_start_file($buffer,$cat_id); + } + else + { + $buffer = $contacts->export_start_file($buffer); + } + + for ($i=0;$i
$buffer"; + echo ''.lang("OK").''; + $phpgw->common->phpgw_footer(); + } + } + else + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + echo "
$buffer"; + echo ''.lang("OK").''; + $phpgw->common->phpgw_footer(); + } + + } + else + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + $this->template->set_file(array('import' => 'import.tpl')); + + $dir_handle = opendir(PHPGW_APP_INC . SEP . 'import'); + $i=0; $myfilearray = ''; + while ($file = readdir($dir_handle)) + { + //echo ""; + if ((substr($file, 0, 1) != '.') && is_file(PHPGW_APP_INC . SEP . 'import' . SEP . $file) ) + { + $myfilearray[$i] = $file; + $i++; + } + } + closedir($dir_handle); + sort($myfilearray); + for ($i=0;$i
\n"; + echo $buffer; + echo "\n\n"; + echo ''.lang('OK').''; + $phpgw->common->phpgw_footer(); + } + } + else + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + $this->template->set_file(array('export' => 'export.tpl')); + + $dir_handle = opendir(PHPGW_APP_INC. SEP . 'export'); + $i=0; $myfilearray = ''; + while ($file = readdir($dir_handle)) + { + #echo ""; + if ((substr($file, 0, 1) != '.') && is_file(PHPGW_APP_INC . SEP . 'export' . SEP . $file) ) + { + $myfilearray[$i] = $file; + $i++; + } + } + closedir($dir_handle); + sort($myfilearray); + for ($i=0;$i
' . lang('Address book - VCard in') . '
');
+ $this->template->set_var('action_url',$phpgw->link('/addressbook/main.php','menuaction=addressbook.boaddressbook.add_vcard'));
+ $this->template->set_var('lang_access',lang('Access'));
+ $this->template->set_var('lang_groups',lang('Which groups'));
+ $this->template->set_var('access_option',$access_option);
+ $this->template->set_var('group_option',$group_option);
+
+ $this->template->pparse('out','vcardin');
+
+ $phpgw->common->phpgw_footer();
+ }
+
+ function out()
+ {
+ global $phpgw,$phpgw_info,$ab_id;
+
+ if ($nolname || $nofname)
+ {
+ $phpgw->common->phpgw_header();
+ echo parse_navbar();
+ }
+
+ if (!$ab_id)
+ {
+ Header('Location: ' . $phpgw->link('/addressbook/index.php'));
+ $phpgw->common->phpgw_exit();
+ }
+
+ // First, make sure they have permission to this entry
+ $check = $this->bo->read_entry($ab_id,array('owner' => 'owner'));
+ $perms = $this->contacts->check_perms($this->contacts->grants[$check[0]['owner']],PHPGW_ACL_READ);
+
+ if ( (!$perms) && ($check[0]['owner'] != $phpgw_info['user']['account_id']) )
+ {
+ Header("Location: " . $phpgw->link('/addressbook/main.php','menuaction=addressbook.uiaddressbook.get_list'));
+ $phpgw->common->phpgw_exit();
+ }
+
+ $extrafields = array('address2' => 'address2');
+ $qfields = $this->contacts->stock_contact_fields + $extrafields;
+
+ $fieldlist = $this->bo->read_entry($ab_id,$qfields);
+ $fields = $fieldlist[0];
+
+ $email = $fields['email'];
+ $emailtype = $fields['email_type'];
+ if (!$emailtype)
+ {
+ $fields['email_type'] = 'INTERNET';
+ }
+ $hemail = $fields['email_home'];
+ $hemailtype = $fields['email_home_type'];
+ if (!$hemailtype)
+ {
+ $fields['email_home_type'] = 'INTERNET';
+ }
+ $firstname = $fields['n_given'];
+ $lastname = $fields['n_family'];
+
+ if(!$nolname && !$nofname)
+ {
+ /* First name and last must be in the vcard. */
+ if($lastname == '')
+ {
+ /* Run away here. */
+ Header('Location: ' . $phpgw->link('/addressbook/main.php',"menuaction=addressbook.uivcard.out&nolname=1&ab_id=$ab_id"));
+ }
+ if($firstname == '')
+ {
+ Header('Location: ' . $phpgw->link('/addressbook/main.php',"menuaction=addressbook.uivcard.out&nofname=1&ab_id=$ab_id"));
+ }
+
+ if ($email)
+ {
+ $fn = explode('@',$email);
+ $filename = sprintf("%s.vcf", $fn[0]);
+ }
+ elseif ($hemail)
+ {
+ $fn = explode('@',$hemail);
+ $filename = sprintf("%s.vcf", $fn[0]);
+ }
+ else
+ {
+ $fn = strtolower($firstname);
+ $filename = sprintf("%s.vcf", $fn);
+ }
+
+ // set translation variable
+ $myexport = $this->vcard->export;
+ // check that each $fields exists in the export array and
+ // set a new array to equal the translation and original value
+ while( list($name,$value) = each($fields) )
+ {
+ if ($myexport[$name] && ($value != "") )
+ {
+ //echo '
'.$name."=".$fields[$name]."\n";
+ $buffer[$myexport[$name]] = $value;
+ }
+ }
+
+ // create a vcard from this translated array
+ $entry = $this->vcard->out($buffer);
+ // print it using browser class for headers
+ // filename, mimetype, no length, default nocache True
+ $this->browser->content_header($filename,'text/x-vcard');
+ echo $entry;
+ $phpgw->common->exit;
+ } /* !nolname && !nofname */
+
+ if($nofname)
+ {
+ echo '