2001-07-08 15:54:40 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare - addressbook *
|
|
|
|
* http://www.phpgroupware.org *
|
|
|
|
* Written by Joseph Engo <jengo@phpgroupware.org> *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* 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)
|
|
|
|
{
|
2001-12-30 12:59:32 +01:00
|
|
|
$this->contacts = $GLOBALS['phpgw']->contacts;
|
2001-07-08 15:54:40 +02:00
|
|
|
$this->so = CreateObject('addressbook.soaddressbook');
|
|
|
|
if($session)
|
|
|
|
{
|
|
|
|
$this->read_sessiondata();
|
|
|
|
$this->use_session = True;
|
|
|
|
}
|
2003-08-28 16:16:30 +02:00
|
|
|
global $start,$limit,$query,$sort,$order,$filter,$cat_id;
|
2001-07-08 15:54:40 +02:00
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
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;
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function save_sessiondata()
|
|
|
|
{
|
2001-12-30 12:59:32 +01:00
|
|
|
global $start,$limit,$query,$sort,$order,$filter,$cat_id;
|
2001-07-08 15:54:40 +02:00
|
|
|
|
|
|
|
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 '<br>Save:'; _debug_array($data); }
|
2001-12-30 12:59:32 +01:00
|
|
|
$GLOBALS['phpgw']->session->appsession('session_data','addressbook',$data);
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function read_sessiondata()
|
|
|
|
{
|
2001-12-30 12:59:32 +01:00
|
|
|
$data = $GLOBALS['phpgw']->session->appsession('session_data','addressbook');
|
2003-08-28 16:16:30 +02:00
|
|
|
if($this->debug) { echo '<br>Read:'; _debug_array($data); }
|
2001-07-08 15:54:40 +02:00
|
|
|
|
|
|
|
$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'];
|
|
|
|
}
|
|
|
|
|
2001-07-13 19:57:10 +02:00
|
|
|
function import($tsvfile,$conv_type,$private,$fcat_id)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
include (PHPGW_APP_INC . '/import/' . $conv_type);
|
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
if ($private == '') { $private = 'public'; }
|
2001-07-08 15:54:40 +02:00
|
|
|
$row = 0;
|
|
|
|
$buffer = array();
|
|
|
|
$contacts = new import_conv;
|
|
|
|
|
|
|
|
$buffer = $contacts->import_start_file($buffer);
|
|
|
|
$fp = fopen($tsvfile,'r');
|
2003-08-28 16:16:30 +02:00
|
|
|
if ($contacts->type == 'csv')
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
while ($data = fgetcsv($fp,8000,','))
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$num = count($data);
|
|
|
|
$row++;
|
2003-08-28 16:16:30 +02:00
|
|
|
if ($row == 1)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$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);
|
2003-08-28 16:16:30 +02:00
|
|
|
for ($c=0; $c<$num; $c++ )
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
//Send name/value pairs along with the buffer
|
2003-08-28 16:16:30 +02:00
|
|
|
if ($contacts->import[$header[$c]] != '' && $data[$c] != '')
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$buffer = $contacts->import_new_attrib($buffer, $contacts->import[$header[$c]],$data[$c]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$buffer = $contacts->import_end_record($buffer,$private);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-08-28 16:16:30 +02:00
|
|
|
elseif ($contacts->type == 'ldif')
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
while ($data = fgets($fp,8000))
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$url = "";
|
|
|
|
list($name,$value,$extra) = split(':', $data);
|
2003-08-28 16:16:30 +02:00
|
|
|
if (substr($name,0,2) == 'dn')
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$buffer = $contacts->import_start_record($buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
$test = trim($value);
|
2003-08-28 16:16:30 +02:00
|
|
|
if ($name && !empty($test) && $extra)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
// Probable url string
|
|
|
|
$url = $test;
|
|
|
|
$value = $extra;
|
|
|
|
}
|
2003-08-28 16:16:30 +02:00
|
|
|
elseif ($name && empty($test) && $extra)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
// Probable multiline encoding
|
|
|
|
$newval = base64_decode(trim($extra));
|
|
|
|
$value = $newval;
|
|
|
|
//echo $name.':'.$value;
|
|
|
|
}
|
2001-12-30 12:59:32 +01:00
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
if ($name && $value)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$test = split(',mail=',$value);
|
2003-08-28 16:16:30 +02:00
|
|
|
if ($test[1])
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$name = "mail";
|
|
|
|
$value = $test[1];
|
|
|
|
}
|
2003-08-28 16:16:30 +02:00
|
|
|
if ($url)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$name = "homeurl";
|
|
|
|
$value = $url. ':' . $value;
|
|
|
|
}
|
|
|
|
//echo '<br>'.$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
|
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
while ($data = fgets($fp,8000))
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2001-12-30 12:59:32 +01:00
|
|
|
$data = trim($data);
|
|
|
|
// RB 2001/05/07 added for Lotus Organizer
|
2003-08-28 16:16:30 +02:00
|
|
|
while (substr($data,-1) == '=')
|
2001-12-30 12:59:32 +01:00
|
|
|
{
|
|
|
|
// '=' at end-of-line --> line to be continued with next line
|
2001-07-08 15:54:40 +02:00
|
|
|
$data = substr($data,0,-1) . trim(fgets($fp,8000));
|
|
|
|
}
|
2003-08-28 16:16:30 +02:00
|
|
|
if (strstr($data,';ENCODING=QUOTED-PRINTABLE'))
|
2001-12-30 12:59:32 +01:00
|
|
|
{
|
|
|
|
// RB 2001/05/07 added for Lotus Organizer
|
2001-07-08 15:54:40 +02:00
|
|
|
$data = quoted_printable_decode(str_replace(';ENCODING=QUOTED-PRINTABLE','',$data));
|
2001-12-30 12:59:32 +01:00
|
|
|
}
|
|
|
|
list($name,$value) = explode(':', $data,2); // RB 2001/05/09 to allow ':' in Values (not only in URL's)
|
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
if (strtolower(substr($name,0,5)) == 'begin')
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$buffer = $contacts->import_start_record($buffer);
|
|
|
|
}
|
2003-08-28 16:16:30 +02:00
|
|
|
if ($name && $value)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
reset($contacts->import);
|
2003-08-28 16:16:30 +02:00
|
|
|
while ( list($fname,$fvalue) = each($contacts->import) )
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
if ( strstr(strtolower($name), $contacts->import[$fname]) )
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$buffer = $contacts->import_new_attrib($buffer,$name,$value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$buffer = $contacts->import_end_record($buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose($fp);
|
2001-07-13 19:57:10 +02:00
|
|
|
$buffer = $contacts->import_end_file($buffer,$private,$fcat_id);
|
2001-07-10 22:47:26 +02:00
|
|
|
return $buffer;
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
2001-07-11 13:20:35 +02:00
|
|
|
function export($conv_type,$cat_id='')
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
include (PHPGW_APP_INC . '/export/' . $conv_type);
|
2003-08-28 16:16:30 +02:00
|
|
|
$buffer=array();
|
2001-07-08 15:54:40 +02:00
|
|
|
$contacts = new export_conv;
|
|
|
|
|
|
|
|
// Read in user custom fields, if any
|
|
|
|
$customfields = array();
|
2003-08-28 16:16:30 +02:00
|
|
|
while (list($col,$descr) = @each($GLOBALS['phpgw_info']['user']['preferences']['addressbook']))
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
if ( substr($col,0,6) == 'extra_' )
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$field = ereg_replace('extra_','',$col);
|
|
|
|
$field = ereg_replace(' ','_',$field);
|
|
|
|
$customfields[$field] = ucfirst($field);
|
|
|
|
}
|
|
|
|
}
|
2001-12-30 12:59:32 +01:00
|
|
|
$extrafields = array(
|
2001-07-08 15:54:40 +02:00
|
|
|
'ophone' => 'ophone',
|
|
|
|
'address2' => 'address2',
|
|
|
|
'address3' => 'address3'
|
|
|
|
);
|
2003-08-28 16:16:30 +02:00
|
|
|
if ($contacts->type != 'vcard')
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$contacts->qfields = $contacts->stock_contact_fields;# + $extrafields;# + $customfields;
|
|
|
|
}
|
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
if (!empty($cat_id))
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$buffer = $contacts->export_start_file($buffer,$cat_id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-10 01:20:46 +02:00
|
|
|
$buffer = $contacts->export_start_file($buffer);
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
for ($i=0;$i<count($contacts->ids);$i++)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$buffer = $contacts->export_start_record($buffer);
|
2003-08-28 16:16:30 +02:00
|
|
|
while( list($name,$value) = each($contacts->currentrecord) )
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$buffer = $contacts->export_new_attrib($buffer,$name,$value);
|
|
|
|
}
|
|
|
|
$buffer = $contacts->export_end_record($buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Here, buffer becomes a string suitable for printing
|
|
|
|
$buffer = $contacts->export_end_file($buffer);
|
|
|
|
|
2001-12-30 12:59:32 +01:00
|
|
|
$tsvfilename = $GLOBALS['phpgw_info']['server']['temp_dir'] . SEP . $tsvfilename;
|
2001-07-08 15:54:40 +02:00
|
|
|
|
|
|
|
return $buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|