2001-07-08 15:54:40 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2004-01-25 23:02:59 +01:00
|
|
|
* eGroupWare - Addressbook *
|
|
|
|
* http://www.egroupware.org *
|
2003-11-19 15:05:01 +01:00
|
|
|
* Written by Miles Lott <milos@groupwhere.org> *
|
|
|
|
* ------------------------------------------------------------------------ *
|
2001-07-08 15:54:40 +02:00
|
|
|
* 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 uiXport
|
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
var $template;
|
2001-07-08 15:54:40 +02:00
|
|
|
var $public_functions = array(
|
|
|
|
'import' => True,
|
|
|
|
'export' => True
|
|
|
|
);
|
|
|
|
var $bo;
|
|
|
|
var $cat;
|
|
|
|
|
|
|
|
var $start;
|
|
|
|
var $limit;
|
|
|
|
var $query;
|
|
|
|
var $sort;
|
|
|
|
var $order;
|
|
|
|
var $filter;
|
|
|
|
var $cat_id;
|
|
|
|
|
|
|
|
function uiXport()
|
|
|
|
{
|
2005-05-01 16:34:59 +02:00
|
|
|
$this->template = $GLOBALS['egw']->template;
|
2001-07-08 15:54:40 +02:00
|
|
|
$this->cat = CreateObject('phpgwapi.categories');
|
|
|
|
$this->bo = CreateObject('addressbook.boXport',True);
|
2001-07-10 01:20:46 +02:00
|
|
|
$this->browser = CreateObject('phpgwapi.browser');
|
|
|
|
|
2003-10-19 09:00:53 +02:00
|
|
|
$this->_set_sessiondata();
|
|
|
|
}
|
|
|
|
|
|
|
|
function _set_sessiondata()
|
|
|
|
{
|
2001-07-10 01:20:46 +02:00
|
|
|
$this->start = $this->bo->start;
|
|
|
|
$this->limit = $this->bo->limit;
|
|
|
|
$this->query = $this->bo->query;
|
|
|
|
$this->sort = $this->bo->sort;
|
|
|
|
$this->order = $this->bo->order;
|
|
|
|
$this->filter = $this->bo->filter;
|
|
|
|
$this->cat_id = $this->bo->cat_id;
|
2003-10-19 09:00:53 +02:00
|
|
|
if($this->debug) { $this->_debug_sqsof(); }
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called only by index(), just prior to page footer. */
|
|
|
|
function save_sessiondata()
|
|
|
|
{
|
|
|
|
$data = array(
|
|
|
|
'start' => $this->start,
|
|
|
|
'limit' => $this->limit,
|
|
|
|
'query' => $this->query,
|
|
|
|
'sort' => $this->sort,
|
|
|
|
'order' => $this->order,
|
|
|
|
'filter' => $this->filter,
|
|
|
|
'cat_id' => $this->cat_id
|
|
|
|
);
|
|
|
|
$this->bo->save_sessiondata($data);
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return a select form element with the categories option dialog in it */
|
|
|
|
function cat_option($cat_id='',$notall=False,$java=True,$multiple=False)
|
|
|
|
{
|
2003-10-18 12:39:37 +02:00
|
|
|
if($java)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$jselect = ' onChange="this.form.submit();"';
|
|
|
|
}
|
|
|
|
/* Setup all and none first */
|
2001-07-13 19:57:10 +02:00
|
|
|
$cats_link = "\n" .'<select name="fcat_id'.($multiple?'[]':'').'"' .$jselect . ($multiple ? 'multiple size="3"' : '') . ">\n";
|
2003-10-18 12:39:37 +02:00
|
|
|
if(!$notall)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$cats_link .= '<option value=""';
|
2003-10-18 12:39:37 +02:00
|
|
|
if($cat_id=='all')
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$cats_link .= ' selected';
|
|
|
|
}
|
2001-12-30 12:57:02 +01:00
|
|
|
$cats_link .= '>'.lang('all').'</option>'."\n";
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get global and app-specific category listings */
|
2003-08-28 16:16:30 +02:00
|
|
|
$cats_link .= $this->cat->formated_list('select','all',$cat_id,True);
|
2001-07-08 15:54:40 +02:00
|
|
|
$cats_link .= '</select>'."\n";
|
|
|
|
return $cats_link;
|
|
|
|
}
|
|
|
|
|
|
|
|
function import()
|
|
|
|
{
|
2003-10-18 12:39:37 +02:00
|
|
|
$tsvfile = get_var('tsvfile','FILES');
|
|
|
|
$tsvfilename = get_var('tsvfilename','POST');
|
|
|
|
$convert = get_var('convert','POST');
|
|
|
|
$conv_type = get_var('conv_type','POST');
|
|
|
|
$fcat_id = get_var('fcat_id','POST');
|
|
|
|
$private = get_var('private','POST');
|
2003-12-03 02:13:14 +01:00
|
|
|
$download = get_var('download','POST');
|
2003-10-18 12:39:37 +02:00
|
|
|
|
|
|
|
if($convert)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2003-11-19 15:05:01 +01:00
|
|
|
if($conv_type == 'none')
|
|
|
|
{
|
2005-05-01 16:34:59 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['noheader'] = False;
|
|
|
|
$GLOBALS['egw_info']['flags']['noheader'] = True;
|
|
|
|
$GLOBALS['egw']->common->phpgw_header();
|
2003-11-19 15:05:01 +01:00
|
|
|
echo parse_navbar();
|
|
|
|
echo lang('<b>No conversion type <none> could be located.</b> Please choose a conversion type from the list');
|
2005-05-01 16:34:59 +02:00
|
|
|
echo ' <a href="'.$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiXport.import') . '">' . lang('OK') . '</a>';
|
|
|
|
$GLOBALS['egw']->common->phpgw_footer();
|
|
|
|
$GLOBALS['egw']->common->phpgw_exit();
|
2003-11-19 15:05:01 +01:00
|
|
|
}
|
2003-12-03 02:13:14 +01:00
|
|
|
$buffer = $this->bo->import($tsvfile,$conv_type,$private,$fcat_id);
|
2001-07-08 15:54:40 +02:00
|
|
|
|
2003-10-18 12:39:37 +02:00
|
|
|
if($download == '')
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2003-12-03 02:13:14 +01:00
|
|
|
if($conv_type == 'Debug LDAP' || $conv_type == 'Debug SQL')
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
// filename, default application/octet-stream, length of file, default nocache True
|
2005-05-01 16:34:59 +02:00
|
|
|
$GLOBALS['egw']->browser->content_header($tsvfilename,'',strlen($buffer));
|
2001-07-08 15:54:40 +02:00
|
|
|
echo $buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-05-01 16:34:59 +02:00
|
|
|
$GLOBALS['egw']->common->phpgw_header();
|
2003-08-28 16:16:30 +02:00
|
|
|
echo parse_navbar();
|
2001-07-08 15:54:40 +02:00
|
|
|
echo "<pre>$buffer</pre>";
|
2005-05-01 16:34:59 +02:00
|
|
|
echo '<a href="'.$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiaddressbook.index') . '">'.lang('OK').'</a>';
|
|
|
|
$GLOBALS['egw']->common->phpgw_footer();
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-05-01 16:34:59 +02:00
|
|
|
$GLOBALS['egw']->common->phpgw_header();
|
2003-08-28 16:16:30 +02:00
|
|
|
echo parse_navbar();
|
2001-07-08 15:54:40 +02:00
|
|
|
echo "<pre>$buffer</pre>";
|
2005-05-01 16:34:59 +02:00
|
|
|
echo '<a href="'.$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiaddressbook.index'). '">'.lang('OK').'</a>';
|
|
|
|
$GLOBALS['egw']->common->phpgw_footer();
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-05-01 16:34:59 +02:00
|
|
|
$GLOBALS['egw']->common->phpgw_header();
|
2003-08-28 16:16:30 +02:00
|
|
|
echo parse_navbar();
|
2001-07-08 15:54:40 +02:00
|
|
|
|
2002-08-24 20:04:27 +02:00
|
|
|
set_time_limit(0);
|
2002-06-23 20:52:50 +02:00
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
$this->template->set_file(array('import' => 'import.tpl'));
|
2001-07-08 15:54:40 +02:00
|
|
|
|
|
|
|
$dir_handle = opendir(PHPGW_APP_INC . SEP . 'import');
|
|
|
|
$i=0; $myfilearray = '';
|
2003-10-18 12:39:37 +02:00
|
|
|
while($file = readdir($dir_handle))
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2004-02-22 16:18:36 +01:00
|
|
|
if((substr($file, 0, 1) != '.') && is_file(PHPGW_APP_INC . SEP . 'import' . SEP . $file))
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$myfilearray[$i] = $file;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($dir_handle);
|
|
|
|
sort($myfilearray);
|
2003-10-18 12:39:37 +02:00
|
|
|
for($i=0;$i<count($myfilearray);$i++)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2004-09-18 17:18:28 +02:00
|
|
|
if ($myfilearray[$i] == 'Import_Multiple_VCard')
|
|
|
|
{
|
|
|
|
$fname = lang('import multiple vcard');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$fname = str_replace('Import_from_', lang('import from') . ' ' ,$myfilearray[$i]);
|
|
|
|
$fname = str_replace('_', ' ', $fname);
|
|
|
|
}
|
2001-07-08 15:54:40 +02:00
|
|
|
$conv .= '<OPTION VALUE="' . $myfilearray[$i].'">' . $fname . '</OPTION>';
|
|
|
|
}
|
|
|
|
|
2004-09-18 17:18:28 +02:00
|
|
|
$this->template->set_var('lang_none', lang('none'));
|
2003-08-28 16:16:30 +02:00
|
|
|
$this->template->set_var('lang_cancel',lang('Cancel'));
|
|
|
|
$this->template->set_var('lang_cat',lang('Select Category'));
|
2005-05-01 16:34:59 +02:00
|
|
|
$this->template->set_var('cancel_url',$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiaddressbook.index'));
|
|
|
|
$this->template->set_var('navbar_bg',$GLOBALS['egw_info']['theme']['navbar_bg']);
|
|
|
|
$this->template->set_var('navbar_text',$GLOBALS['egw_info']['theme']['navbar_text']);
|
2003-08-28 16:16:30 +02:00
|
|
|
$this->template->set_var('import_text',lang('Import from LDIF, CSV, or VCard'));
|
2005-05-01 16:34:59 +02:00
|
|
|
$this->template->set_var('action_url',$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiXport.import'));
|
2003-08-28 16:16:30 +02:00
|
|
|
$this->template->set_var('cat_link',$this->cat_option($this->cat_id,True,False));
|
|
|
|
$this->template->set_var('tsvfilename','');
|
|
|
|
$this->template->set_var('conv',$conv);
|
|
|
|
$this->template->set_var('debug',lang('Debug output in browser'));
|
|
|
|
$this->template->set_var('filetype',lang('LDIF'));
|
|
|
|
$this->template->set_var('download',lang('Submit'));
|
|
|
|
$this->template->set_var('start',$this->start);
|
|
|
|
$this->template->set_var('sort',$this->sort);
|
|
|
|
$this->template->set_var('order',$this->order);
|
|
|
|
$this->template->set_var('filter',$this->filter);
|
|
|
|
$this->template->set_var('query',$this->query);
|
|
|
|
$this->template->set_var('cat_id',$this->cat_id);
|
2003-12-03 02:13:14 +01:00
|
|
|
$this->template->set_var('lang_import_instructions',lang('import_instructions'));
|
2004-02-22 16:18:36 +01:00
|
|
|
$this->template->set_var('zip_note','');
|
2003-12-03 02:13:14 +01:00
|
|
|
if(extension_loaded('zip'))
|
|
|
|
{
|
|
|
|
$this->template->set_var('zip_note',lang('zip_note'));
|
|
|
|
}
|
2004-02-22 16:18:36 +01:00
|
|
|
|
2003-12-03 02:13:14 +01:00
|
|
|
$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'));
|
2003-08-28 16:16:30 +02:00
|
|
|
$this->template->pparse('out','import');
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
2005-05-01 16:34:59 +02:00
|
|
|
// $GLOBALS['egw']->common->phpgw_footer();
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function export()
|
|
|
|
{
|
2003-10-18 12:39:37 +02:00
|
|
|
$convert = get_var('convert','POST');
|
|
|
|
$conv_type = get_var('conv_type','POST');
|
2004-04-07 19:38:24 +02:00
|
|
|
$fcat_id = get_var('fcat_id','POST');
|
2003-10-18 12:39:37 +02:00
|
|
|
$download = get_var('download','POST');
|
|
|
|
$tsvfilename = get_var('tsvfilename','POST');
|
|
|
|
|
|
|
|
if($convert)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2003-10-18 12:39:37 +02:00
|
|
|
if($conv_type == 'none')
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2005-05-01 16:34:59 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['noheader'] = False;
|
|
|
|
$GLOBALS['egw_info']['flags']['noheader'] = True;
|
|
|
|
$GLOBALS['egw']->common->phpgw_header();
|
2003-08-28 16:16:30 +02:00
|
|
|
echo parse_navbar();
|
2001-07-08 15:54:40 +02:00
|
|
|
echo lang('<b>No conversion type <none> could be located.</b> Please choose a conversion type from the list');
|
2005-05-01 16:34:59 +02:00
|
|
|
echo ' <a href="'.$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiXport.export') . '">' . lang('OK') . '</a>';
|
|
|
|
$GLOBALS['egw']->common->phpgw_footer();
|
|
|
|
$GLOBALS['egw']->common->phpgw_exit();
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
2004-04-07 19:38:24 +02:00
|
|
|
$buffer = $this->bo->export($conv_type,$fcat_id);
|
2002-02-14 03:39:51 +01:00
|
|
|
|
2005-03-24 14:29:51 +01:00
|
|
|
if($conv_type == 'Palm_PDB')
|
|
|
|
{
|
|
|
|
$pdb = CreateObject('addressbook.pdb');
|
|
|
|
$pdb->fetch($buffer, 'phpgw Contacts', $tsvfilename);
|
|
|
|
}
|
|
|
|
elseif($download == 'on')
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
// filename, default application/octet-stream, length of file, default nocache True
|
2003-10-18 12:39:37 +02:00
|
|
|
$this->browser->content_header($tsvfilename,'application/x-octet-stream',strlen($buffer));
|
2001-07-08 15:54:40 +02:00
|
|
|
echo $buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-05-01 16:34:59 +02:00
|
|
|
$GLOBALS['egw']->common->phpgw_header();
|
2003-08-28 16:16:30 +02:00
|
|
|
echo parse_navbar();
|
2001-07-08 15:54:40 +02:00
|
|
|
echo "<pre>\n";
|
|
|
|
echo $buffer;
|
|
|
|
echo "\n</pre>\n";
|
2005-05-01 16:34:59 +02:00
|
|
|
echo '<a href="'.$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiXport.export') . '">' . lang('OK') . '</a>';
|
|
|
|
$GLOBALS['egw']->common->phpgw_footer();
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-05-01 16:34:59 +02:00
|
|
|
$GLOBALS['egw']->common->phpgw_header();
|
2003-08-28 16:16:30 +02:00
|
|
|
echo parse_navbar();
|
2001-07-08 15:54:40 +02:00
|
|
|
|
2002-08-24 20:04:27 +02:00
|
|
|
set_time_limit(0);
|
2004-01-02 00:17:19 +01:00
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
$this->template->set_file(array('export' => 'export.tpl'));
|
2001-07-08 15:54:40 +02:00
|
|
|
|
|
|
|
$dir_handle = opendir(PHPGW_APP_INC. SEP . 'export');
|
|
|
|
$i=0; $myfilearray = '';
|
2003-10-18 12:39:37 +02:00
|
|
|
while($file = readdir($dir_handle))
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2004-02-22 16:18:36 +01:00
|
|
|
if((substr($file, 0, 1) != '.') && is_file(PHPGW_APP_INC . SEP . 'export' . SEP . $file))
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$myfilearray[$i] = $file;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($dir_handle);
|
|
|
|
sort($myfilearray);
|
2003-10-18 12:39:37 +02:00
|
|
|
for($i=0;$i<count($myfilearray);$i++)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2004-09-18 17:18:28 +02:00
|
|
|
if ($myfilearray[$i] == 'Multiple_VCard')
|
|
|
|
{
|
|
|
|
$fname = lang('multiple vcard');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$fname = str_replace('_',' ',$myfilearray[$i]);
|
|
|
|
}
|
|
|
|
$conv .= ' <option value="'.$myfilearray[$i].'">'.$fname.'</option>'."\n";
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
2004-09-18 17:18:28 +02:00
|
|
|
$this->template->set_var('lang_none', lang('none'));
|
2003-08-28 16:16:30 +02:00
|
|
|
$this->template->set_var('lang_cancel',lang('Cancel'));
|
|
|
|
$this->template->set_var('lang_cat',lang('Select Category'));
|
2004-01-02 00:17:19 +01:00
|
|
|
$this->template->set_var('lang_export_instructions',lang('Download export file (Uncheck to debug output in browser)'));
|
|
|
|
$this->template->set_var('lang_select',lang('Select the type of conversion:'));
|
2003-08-28 16:16:30 +02:00
|
|
|
$this->template->set_var('cat_link',$this->cat_option($this->cat_id,False,False));
|
2005-05-01 16:34:59 +02:00
|
|
|
$this->template->set_var('cancel_url',$GLOBALS['egw']->link('/addressbook/index.php'));
|
|
|
|
$this->template->set_var('navbar_bg',$GLOBALS['egw_info']['theme']['navbar_bg']);
|
|
|
|
$this->template->set_var('navbar_text',$GLOBALS['egw_info']['theme']['navbar_text']);
|
2003-08-28 16:16:30 +02:00
|
|
|
$this->template->set_var('export_text',lang('Export from Addressbook'));
|
2005-05-01 16:34:59 +02:00
|
|
|
$this->template->set_var('action_url',$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiXport.export'));
|
2003-08-28 16:16:30 +02:00
|
|
|
$this->template->set_var('filename',lang('Export file name'));
|
|
|
|
$this->template->set_var('conv',$conv);
|
|
|
|
$this->template->set_var('debug',lang(''));
|
|
|
|
$this->template->set_var('download',lang('Submit'));
|
|
|
|
$this->template->set_var('start',$this->start);
|
|
|
|
$this->template->set_var('sort',$this->sort);
|
|
|
|
$this->template->set_var('order',$this->order);
|
|
|
|
$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->pparse('out','export');
|
|
|
|
|
2005-05-01 16:34:59 +02:00
|
|
|
$GLOBALS['egw']->common->phpgw_footer();
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|