2001-01-14 22:35:04 +01: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$ */
|
|
|
|
|
2001-05-20 23:03:23 +02:00
|
|
|
$phpgw_info['flags'] = array(
|
|
|
|
'currentapp' => 'addressbook',
|
|
|
|
'enable_contacts_class' => True,
|
|
|
|
'enable_browser_class' => True
|
|
|
|
);
|
|
|
|
include('../header.inc.php');
|
2001-01-14 22:35:04 +01:00
|
|
|
|
2001-05-10 14:21:16 +02:00
|
|
|
if (!$convert)
|
|
|
|
{
|
|
|
|
$t = new Template(PHPGW_APP_TPL);
|
2001-05-20 23:03:23 +02:00
|
|
|
$t->set_file(array('import' => 'import.tpl'));
|
2001-01-14 22:35:04 +01:00
|
|
|
|
2001-06-27 07:11:38 +02:00
|
|
|
$dir_handle=opendir(PHPGW_APP_ROOT . SEP . 'import');
|
2001-05-20 23:03:23 +02:00
|
|
|
$i=0; $myfilearray='';
|
2001-05-10 14:21:16 +02:00
|
|
|
while ($file = readdir($dir_handle))
|
|
|
|
{
|
2001-03-20 17:39:28 +01:00
|
|
|
//echo "<!-- ".is_file($phpgw_info["server"]["app_root"].$sep."import".$sep.$file)." -->";
|
2001-06-27 07:11:38 +02:00
|
|
|
if ((substr($file, 0, 1) != '.') && is_file(PHPGW_APP_ROOT . SEP . 'import' . SEP . $file) )
|
2001-05-10 14:21:16 +02:00
|
|
|
{
|
2001-03-11 07:58:20 +01:00
|
|
|
$myfilearray[$i] = $file;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($dir_handle);
|
|
|
|
sort($myfilearray);
|
2001-05-10 14:21:16 +02:00
|
|
|
for ($i=0;$i<count($myfilearray);$i++)
|
|
|
|
{
|
2001-03-16 15:27:22 +01:00
|
|
|
$fname = ereg_replace('_',' ',$myfilearray[$i]);
|
2001-05-20 23:03:23 +02:00
|
|
|
$conv .= '<OPTION VALUE="' . $myfilearray[$i].'">' . $fname . '</OPTION>';
|
2001-03-11 07:58:20 +01:00
|
|
|
}
|
2001-01-14 22:35:04 +01:00
|
|
|
|
2001-05-20 23:03:23 +02:00
|
|
|
$t->set_var('lang_cancel',lang('Cancel'));
|
|
|
|
$t->set_var('lang_cat',lang('Select Category'));
|
|
|
|
$t->set_var('cancel_url',$phpgw->link('/addressbook/index.php'));
|
|
|
|
$t->set_var('navbar_bg',$phpgw_info['theme']['navbar_bg']);
|
|
|
|
$t->set_var('navbar_text',$phpgw_info['theme']['navbar_text']);
|
|
|
|
$t->set_var('import_text',lang('Import from LDIF, CSV, or VCard'));
|
|
|
|
$t->set_var('action_url',$phpgw->link('/addressbook/import.php'));
|
|
|
|
$t->set_var('cat_link',cat_option($cat_id,True,False));
|
|
|
|
$t->set_var('tsvfilename','');
|
|
|
|
$t->set_var('conv',$conv);
|
|
|
|
$t->set_var('debug',lang('Debug output in browser'));
|
|
|
|
$t->set_var('filetype',lang('LDIF'));
|
|
|
|
$t->set_var('download',lang('Submit'));
|
|
|
|
$t->set_var('start',$start);
|
|
|
|
$t->set_var('sort',$sort);
|
|
|
|
$t->set_var('order',$order);
|
|
|
|
$t->set_var('filter',$filter);
|
|
|
|
$t->set_var('query',$query);
|
|
|
|
$t->set_var('cat_id',$cat_id);
|
|
|
|
$t->pparse('out','import');
|
2001-03-11 07:58:20 +01:00
|
|
|
$phpgw->common->phpgw_footer();
|
2001-05-10 14:21:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-06-27 07:11:38 +02:00
|
|
|
include (PHPGW_APP_ROOT . SEP. 'import' . SEP . $conv_type);
|
2001-01-14 22:35:04 +01:00
|
|
|
|
2001-05-20 23:03:23 +02:00
|
|
|
if ($private == '') { $private = 'public'; }
|
2001-03-11 07:58:20 +01:00
|
|
|
$row=0;
|
|
|
|
$buffer=array();
|
2001-07-03 09:17:13 +02:00
|
|
|
$contacts = new import_conv;
|
|
|
|
$buffer = $contacts->import_start_file($buffer);
|
2001-05-20 23:03:23 +02:00
|
|
|
$fp=fopen($tsvfile,'r');
|
2001-07-03 09:17:13 +02:00
|
|
|
if ($contacts->type == 'csv')
|
2001-05-10 14:21:16 +02:00
|
|
|
{
|
2001-05-20 23:03:23 +02:00
|
|
|
while ($data = fgetcsv($fp,8000,','))
|
2001-05-10 14:21:16 +02:00
|
|
|
{
|
2001-03-11 18:34:58 +01:00
|
|
|
$num = count($data);
|
|
|
|
$row++;
|
2001-05-10 14:21:16 +02:00
|
|
|
if ($row == 1)
|
|
|
|
{
|
2001-05-29 04:57:27 +02:00
|
|
|
// Changed here to ignore the header, set to our array
|
2001-07-03 09:17:13 +02:00
|
|
|
while(list($lhs,$rhs) = each($contacts->import))
|
2001-05-29 04:57:27 +02:00
|
|
|
{
|
|
|
|
$header[] = $lhs;
|
|
|
|
}
|
2001-05-10 14:21:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-03 09:17:13 +02:00
|
|
|
$buffer = $contacts->import_start_record($buffer);
|
2001-05-10 14:21:16 +02:00
|
|
|
for ($c=0; $c<$num; $c++ )
|
|
|
|
{
|
2001-03-11 18:34:58 +01:00
|
|
|
//Send name/value pairs along with the buffer
|
2001-07-03 09:17:13 +02:00
|
|
|
if ($contacts->import[$header[$c]] != '' && $data[$c] != '')
|
2001-05-10 14:21:16 +02:00
|
|
|
{
|
2001-07-03 09:17:13 +02:00
|
|
|
$buffer = $contacts->import_new_attrib($buffer, $contacts->import[$header[$c]],$data[$c]);
|
2001-03-11 18:34:58 +01:00
|
|
|
}
|
|
|
|
}
|
2001-07-03 09:17:13 +02:00
|
|
|
$buffer = $contacts->import_end_record($buffer,$private);
|
2001-03-11 18:34:58 +01:00
|
|
|
}
|
|
|
|
}
|
2001-05-10 14:21:16 +02:00
|
|
|
}
|
2001-07-03 09:17:13 +02:00
|
|
|
elseif ($contacts->type == 'ldif')
|
2001-05-10 14:21:16 +02:00
|
|
|
{
|
|
|
|
while ($data = fgets($fp,8000))
|
|
|
|
{
|
2001-03-23 23:01:29 +01:00
|
|
|
$url = "";
|
|
|
|
list($name,$value,$extra) = split(':', $data);
|
2001-05-10 14:21:16 +02:00
|
|
|
if (substr($name,0,2) == 'dn')
|
|
|
|
{
|
2001-07-03 09:17:13 +02:00
|
|
|
$buffer = $contacts->import_start_record($buffer);
|
2001-03-11 18:34:58 +01:00
|
|
|
}
|
2001-03-23 23:01:29 +01:00
|
|
|
|
|
|
|
$test = trim($value);
|
2001-05-10 14:21:16 +02:00
|
|
|
if ($name && !empty($test) && $extra)
|
|
|
|
{
|
2001-03-23 23:01:29 +01:00
|
|
|
// Probable url string
|
|
|
|
$url = $test;
|
|
|
|
$value = $extra;
|
2001-05-10 14:21:16 +02:00
|
|
|
}
|
|
|
|
elseif ($name && empty($test) && $extra)
|
|
|
|
{
|
2001-03-23 23:01:29 +01:00
|
|
|
// Probable multiline encoding
|
|
|
|
$newval = base64_decode(trim($extra));
|
|
|
|
$value = $newval;
|
2001-03-30 05:31:50 +02:00
|
|
|
//echo $name.':'.$value;
|
2001-03-23 23:01:29 +01:00
|
|
|
}
|
|
|
|
|
2001-05-10 14:21:16 +02:00
|
|
|
if ($name && $value)
|
|
|
|
{
|
2001-03-11 18:34:58 +01:00
|
|
|
$test = split(',mail=',$value);
|
2001-05-10 14:21:16 +02:00
|
|
|
if ($test[1])
|
|
|
|
{
|
2001-03-11 18:34:58 +01:00
|
|
|
$name = "mail";
|
|
|
|
$value = $test[1];
|
|
|
|
}
|
2001-05-10 14:21:16 +02:00
|
|
|
if ($url)
|
|
|
|
{
|
2001-03-12 03:05:20 +01:00
|
|
|
$name = "homeurl";
|
2001-03-23 23:01:29 +01:00
|
|
|
$value = $url. ':' . $value;
|
2001-03-12 03:05:20 +01:00
|
|
|
}
|
2001-03-11 18:34:58 +01:00
|
|
|
//echo '<br>'.$j.': '.$name.' => '.$value;
|
2001-07-03 09:17:13 +02:00
|
|
|
if ($contacts->import[$name] != '' && $value != '')
|
2001-05-10 14:21:16 +02:00
|
|
|
{
|
2001-07-03 09:17:13 +02:00
|
|
|
$buffer = $contacts->import_new_attrib($buffer, $contacts->import[$name],$value);
|
2001-03-11 07:58:20 +01:00
|
|
|
}
|
2001-05-10 14:21:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-03 09:17:13 +02:00
|
|
|
$buffer = $contacts->import_end_record($buffer,$private);
|
2001-03-11 07:58:20 +01:00
|
|
|
}
|
|
|
|
}
|
2001-05-10 14:21:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while ($data = fgets($fp,8000))
|
|
|
|
{
|
2001-05-23 22:18:57 +02:00
|
|
|
$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)
|
|
|
|
|
2001-05-10 14:21:16 +02:00
|
|
|
if (strtolower(substr($name,0,5)) == 'begin')
|
|
|
|
{
|
2001-07-03 09:17:13 +02:00
|
|
|
$buffer = $contacts->import_start_record($buffer);
|
2001-03-20 23:55:03 +01:00
|
|
|
}
|
2001-05-10 14:21:16 +02:00
|
|
|
if ($name && $value)
|
|
|
|
{
|
2001-07-03 09:17:13 +02:00
|
|
|
reset($contacts->import);
|
|
|
|
while ( list($fname,$fvalue) = each($contacts->import) )
|
2001-05-10 14:21:16 +02:00
|
|
|
{
|
2001-07-03 09:17:13 +02:00
|
|
|
if ( strstr(strtolower($name), $contacts->import[$fname]) )
|
2001-05-10 14:21:16 +02:00
|
|
|
{
|
2001-07-03 09:17:13 +02:00
|
|
|
$buffer = $contacts->import_new_attrib($buffer,$name,$value);
|
2001-03-20 23:55:03 +01:00
|
|
|
}
|
|
|
|
}
|
2001-05-10 14:21:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-03 09:17:13 +02:00
|
|
|
$buffer = $contacts->import_end_record($buffer);
|
2001-03-20 19:14:46 +01:00
|
|
|
}
|
|
|
|
}
|
2001-03-11 07:58:20 +01:00
|
|
|
}
|
2001-01-14 22:35:04 +01:00
|
|
|
|
2001-03-11 07:58:20 +01:00
|
|
|
fclose($fp);
|
2001-07-03 09:17:13 +02:00
|
|
|
$buffer = $contacts->import_end_file($buffer,$private,$cat_id);
|
2001-03-20 19:14:46 +01:00
|
|
|
|
2001-05-20 23:03:23 +02:00
|
|
|
if ($download == '')
|
2001-05-10 14:21:16 +02:00
|
|
|
{
|
2001-05-20 23:03:23 +02:00
|
|
|
if($conv_type == 'Debug LDAP' || $conv_type == 'Debug SQL' )
|
2001-05-10 14:21:16 +02:00
|
|
|
{
|
2001-04-14 04:42:50 +02:00
|
|
|
// filename, default application/octet-stream, length of file, default nocache True
|
|
|
|
$phpgw->browser->content_header($tsvfilename,'',strlen($buffer));
|
2001-03-11 07:58:20 +01:00
|
|
|
echo $buffer;
|
2001-05-10 14:21:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-11 07:58:20 +01:00
|
|
|
echo "<pre>$buffer</pre>";
|
2001-05-20 23:03:23 +02:00
|
|
|
echo '<a href="'.$phpgw->link('/addressbook/index.php',
|
2001-03-29 17:39:10 +02:00
|
|
|
"sort=$sort&order=$order&filter=$filter&start=$start&query=$query&cat_id=$cat_id")
|
2001-03-28 03:59:08 +02:00
|
|
|
. '">'.lang("OK").'</a>';
|
2001-03-11 07:58:20 +01:00
|
|
|
$phpgw->common->phpgw_footer();
|
|
|
|
}
|
2001-05-10 14:21:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-11 07:58:20 +01:00
|
|
|
echo "<pre>$buffer</pre>";
|
2001-05-20 23:03:23 +02:00
|
|
|
echo '<a href="'.$phpgw->link('/addressbook/index.php',
|
2001-03-29 17:39:10 +02:00
|
|
|
"sort=$sort&order=$order&filter=$filter&start=$start&query=$query&cat_id=$cat_id")
|
2001-03-28 03:59:08 +02:00
|
|
|
. '">'.lang("OK").'</a>';
|
2001-03-11 07:58:20 +01:00
|
|
|
$phpgw->common->phpgw_footer();
|
|
|
|
}
|
|
|
|
}
|
2001-01-14 22:35:04 +01:00
|
|
|
?>
|