2006-11-10 16:35:35 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* eGroupWare
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package addressbook
|
|
|
|
* @subpackage importexport
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Cornelius Weiss <nelius@cwtech.de>
|
|
|
|
* @copyright Cornelius Weiss <nelius@cwtech.de>
|
2007-06-08 00:31:08 +02:00
|
|
|
* @version $Id: $
|
2006-11-10 16:35:35 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* export plugin of addressbook
|
|
|
|
*/
|
2010-03-22 16:11:12 +01:00
|
|
|
class addressbook_export_contacts_csv implements importexport_iface_export_plugin {
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2010-10-29 01:16:45 +02:00
|
|
|
// Used in conversions
|
|
|
|
static $types = array(
|
|
|
|
'select-account' => array('owner','creator','modifier'),
|
|
|
|
'date-time' => array('modified','created','last_event','next_event'),
|
|
|
|
'select-cat' => array('cat_id'),
|
|
|
|
);
|
|
|
|
|
2006-11-10 16:35:35 +01:00
|
|
|
/**
|
|
|
|
* Exports records as defined in $_definition
|
|
|
|
*
|
|
|
|
* @param egw_record $_definition
|
|
|
|
*/
|
2010-03-22 16:11:12 +01:00
|
|
|
public function export( $_stream, importexport_definition $_definition) {
|
2007-06-09 17:38:30 +02:00
|
|
|
$options = $_definition->plugin_options;
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2008-05-10 14:11:02 +02:00
|
|
|
$uicontacts = new addressbook_ui();
|
2006-11-10 16:35:35 +01:00
|
|
|
$selection = array();
|
2007-06-28 12:07:16 +02:00
|
|
|
if ($options['selection'] == 'use_all') {
|
2008-05-10 14:02:49 +02:00
|
|
|
// uicontacts selection with checkbox 'use_all'
|
2006-11-10 16:35:35 +01:00
|
|
|
$query = $GLOBALS['egw']->session->appsession('index','addressbook');
|
|
|
|
$query['num_rows'] = -1; // all
|
|
|
|
$uicontacts->get_rows($query,$selection,$readonlys,true); // true = only return the id's
|
|
|
|
}
|
2007-06-28 12:07:16 +02:00
|
|
|
elseif ( $options['selection'] == 'all_contacts' ) {
|
2008-05-10 14:02:49 +02:00
|
|
|
$selection = ExecMethod('addressbook.addressbook_bo.search',array());
|
2007-06-28 12:07:16 +02:00
|
|
|
//$uicontacts->get_rows($query,$selection,$readonlys,true);
|
|
|
|
} else {
|
2006-11-10 16:35:35 +01:00
|
|
|
$selection = explode(',',$options['selection']);
|
|
|
|
}
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2010-03-22 16:11:12 +01:00
|
|
|
$export_object = new importexport_export_csv($_stream, (array)$options);
|
2007-06-08 00:31:08 +02:00
|
|
|
$export_object->set_mapping($options['mapping']);
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2006-11-10 16:35:35 +01:00
|
|
|
// $options['selection'] is array of identifiers as this plugin doesn't
|
|
|
|
// support other selectors atm.
|
|
|
|
foreach ($selection as $identifier) {
|
2010-03-22 16:11:12 +01:00
|
|
|
$contact = new addressbook_egw_record($identifier);
|
2010-10-29 01:16:45 +02:00
|
|
|
|
|
|
|
// Some conversion
|
|
|
|
$this->convert($contact);
|
2006-11-10 16:35:35 +01:00
|
|
|
$export_object->export_record($contact);
|
|
|
|
unset($contact);
|
2008-05-10 14:02:49 +02:00
|
|
|
}
|
2006-11-10 16:35:35 +01:00
|
|
|
}
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2006-11-10 16:35:35 +01:00
|
|
|
/**
|
|
|
|
* returns translated name of plugin
|
|
|
|
*
|
|
|
|
* @return string name
|
|
|
|
*/
|
|
|
|
public static function get_name() {
|
|
|
|
return lang('Addressbook CSV export');
|
|
|
|
}
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2006-11-10 16:35:35 +01:00
|
|
|
/**
|
|
|
|
* returns translated (user) description of plugin
|
|
|
|
*
|
|
|
|
* @return string descriprion
|
|
|
|
*/
|
|
|
|
public static function get_description() {
|
2010-10-08 01:07:02 +02:00
|
|
|
return lang("Exports contacts from your Addressbook into a CSV File.");
|
2006-11-10 16:35:35 +01:00
|
|
|
}
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2006-11-10 16:35:35 +01:00
|
|
|
/**
|
|
|
|
* retruns file suffix for exported file
|
|
|
|
*
|
|
|
|
* @return string suffix
|
|
|
|
*/
|
|
|
|
public static function get_filesuffix() {
|
|
|
|
return 'csv';
|
|
|
|
}
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2010-10-13 00:50:12 +02:00
|
|
|
public static function get_mimetype() {
|
|
|
|
return 'text/csv';
|
|
|
|
}
|
|
|
|
|
2006-11-10 16:35:35 +01:00
|
|
|
/**
|
|
|
|
* return html for options.
|
|
|
|
* this way the plugin has all opertunities for options tab
|
2008-05-10 14:02:49 +02:00
|
|
|
*
|
2006-11-10 16:35:35 +01:00
|
|
|
* @return string html
|
|
|
|
*/
|
2007-06-09 17:38:30 +02:00
|
|
|
public function get_options_etpl() {
|
2006-11-10 16:35:35 +01:00
|
|
|
return 'addressbook.export_csv_options';
|
|
|
|
}
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2006-11-10 16:35:35 +01:00
|
|
|
/**
|
|
|
|
* returns slectors of this plugin via xajax
|
|
|
|
*
|
|
|
|
*/
|
2007-06-09 17:38:30 +02:00
|
|
|
public function get_selectors_etpl() {
|
2010-03-22 16:11:12 +01:00
|
|
|
return 'addressbook.export_csv_selectors';
|
2006-11-10 16:35:35 +01:00
|
|
|
}
|
2010-10-29 01:16:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert some internal data to something with more meaning
|
|
|
|
*
|
|
|
|
* Dates, times, user IDs, category IDs
|
|
|
|
*/
|
|
|
|
public static function convert(addressbook_egw_record &$record) {
|
|
|
|
$custom = config::get_customfields('addressbook');
|
|
|
|
foreach($custom as $name => $c_field) {
|
|
|
|
$name = '#' . $name;
|
|
|
|
if($c_field['type'] == 'date') {
|
|
|
|
self::$types['date-time'][] = $name;
|
|
|
|
} elseif ($c_field['type'] == 'select-account') {
|
|
|
|
self::$types['select-account'][] = $name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach(self::$types['select-account'] as $name) {
|
|
|
|
if ($record->$name) {
|
|
|
|
$record->$name = $GLOBALS['egw']->common->grab_owner_name($record->$name);
|
|
|
|
} elseif ($name == 'owner') {
|
|
|
|
$record->$name = lang('Accounts');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach(self::$types['date-time'] as $name) {
|
|
|
|
if ($record->$name) $record->$name = date('Y-m-d H:i:s',$record->$name);
|
|
|
|
}
|
|
|
|
if ($record->tel_prefer) {
|
|
|
|
$field = $record->tel_prefer;
|
|
|
|
$record->tel_prefer = $record->$field;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cats = array();
|
|
|
|
foreach(explode(',',$record->cat_id) as $n => $cat_id) {
|
|
|
|
if ($cat_id) $cats[] = $GLOBALS['egw']->categories->id2name($cat_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
$record->cat_id = implode(', ',$cats);
|
|
|
|
}
|
2007-06-08 00:31:08 +02:00
|
|
|
}
|