2011-04-12 17:38:27 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2016-04-27 21:12:20 +02:00
|
|
|
* EGroupware - Export plugin for users
|
2011-04-12 17:38:27 +02:00
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package admin
|
|
|
|
* @subpackage importexport
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @copyright Nathan Gray 2011
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Export users plugin
|
|
|
|
*/
|
2016-04-27 21:12:20 +02:00
|
|
|
class admin_export_users_csv implements importexport_iface_export_plugin
|
|
|
|
{
|
2011-04-12 17:38:27 +02:00
|
|
|
/**
|
|
|
|
* Exports records as defined in $_definition
|
|
|
|
*
|
|
|
|
* @param egw_record $_definition
|
|
|
|
*/
|
2018-11-29 18:33:56 +01:00
|
|
|
public function export( $_stream, importexport_definition $_definition)
|
|
|
|
{
|
2011-04-12 17:38:27 +02:00
|
|
|
$options = $_definition->plugin_options;
|
|
|
|
|
|
|
|
$query = array(
|
|
|
|
'type' => 'accounts',
|
|
|
|
);
|
2018-11-29 18:33:56 +01:00
|
|
|
if($options['selection']['group_id'])
|
|
|
|
{
|
2011-04-12 17:38:27 +02:00
|
|
|
$query['type'] = (int)$options['selection']['group_id'];
|
|
|
|
}
|
|
|
|
$selection = $GLOBALS['egw']->accounts->search($query);
|
|
|
|
|
|
|
|
$options['begin_with_fieldnames'] = true;
|
|
|
|
$export_object = new importexport_export_csv($_stream, (array)$options);
|
|
|
|
$export_object->set_mapping($options['mapping']);
|
|
|
|
|
|
|
|
$lookups = array(
|
2011-04-13 00:23:40 +02:00
|
|
|
'account_status' => array('A' => lang('Active'), '' => lang('Disabled'), 'D' => lang('Disabled')),
|
2011-04-12 17:38:27 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
// $_record is an array, that's what search() returns
|
2018-11-29 18:33:56 +01:00
|
|
|
foreach ($selection as $_record)
|
|
|
|
{
|
2011-04-12 17:38:27 +02:00
|
|
|
$record = new admin_egw_user_record($_record);
|
2018-11-29 18:33:56 +01:00
|
|
|
if($options['convert'])
|
|
|
|
{
|
2011-04-13 00:23:40 +02:00
|
|
|
$never_expires = ($record->account_expires == -1);
|
2011-04-12 17:38:27 +02:00
|
|
|
importexport_export_csv::convert($record, admin_egw_user_record::$types, 'admin', $lookups);
|
2011-04-13 00:23:40 +02:00
|
|
|
if($never_expires) $record->account_expires = 'never'; // Has to be 'never' for admin_cmd_edit_user to parse it
|
2018-11-29 18:33:56 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-12 17:38:27 +02:00
|
|
|
// Implode arrays, so they don't say 'Array'
|
2018-11-29 18:33:56 +01:00
|
|
|
foreach($record->get_record_array() as $key => $value)
|
|
|
|
{
|
2011-04-12 17:38:27 +02:00
|
|
|
if(is_array($value)) $record->$key = implode(',', $value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$export_object->export_record($record);
|
|
|
|
unset($record);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated name of plugin
|
|
|
|
*
|
|
|
|
* @return string name
|
|
|
|
*/
|
2018-11-29 18:33:56 +01:00
|
|
|
public static function get_name()
|
|
|
|
{
|
2011-04-12 17:38:27 +02:00
|
|
|
return lang('User CSV export');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated (user) description of plugin
|
|
|
|
*
|
|
|
|
* @return string descriprion
|
|
|
|
*/
|
2018-11-29 18:33:56 +01:00
|
|
|
public static function get_description()
|
|
|
|
{
|
2011-04-12 17:38:27 +02:00
|
|
|
return lang("Exports users into a CSV File. ");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns file suffix for exported file
|
|
|
|
*
|
|
|
|
* @return string suffix
|
|
|
|
*/
|
2018-11-29 18:33:56 +01:00
|
|
|
public static function get_filesuffix()
|
|
|
|
{
|
2011-04-12 17:38:27 +02:00
|
|
|
return 'csv';
|
|
|
|
}
|
|
|
|
|
2018-11-29 18:33:56 +01:00
|
|
|
public static function get_mimetype()
|
|
|
|
{
|
|
|
|
return 'text/csv';
|
|
|
|
}
|
2011-04-12 17:38:27 +02:00
|
|
|
|
|
|
|
/**
|
2018-11-29 18:33:56 +01:00
|
|
|
* Return array of settings for export dialog
|
|
|
|
*
|
|
|
|
* @param $definition Specific definition
|
2011-04-12 17:38:27 +02:00
|
|
|
*
|
2018-11-29 18:33:56 +01:00
|
|
|
* @return array (
|
|
|
|
* name => string,
|
|
|
|
* content => array,
|
|
|
|
* sel_options => array,
|
|
|
|
* readonlys => array,
|
|
|
|
* preserv => array,
|
|
|
|
* )
|
2011-04-12 17:38:27 +02:00
|
|
|
*/
|
2018-11-29 18:33:56 +01:00
|
|
|
public function get_options_etpl(importexport_definition &$definition = NULL)
|
|
|
|
{
|
2011-04-12 17:38:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns slectors of this plugin via xajax
|
|
|
|
*
|
|
|
|
*/
|
2018-11-29 18:33:56 +01:00
|
|
|
public function get_selectors_etpl()
|
|
|
|
{
|
2011-04-12 17:38:27 +02:00
|
|
|
return array(
|
|
|
|
'name' => 'admin.export_users_csv_selectors',
|
|
|
|
'preserv' => array('no_error_for_all'),
|
|
|
|
);
|
|
|
|
}
|
2016-05-04 21:34:30 +02:00
|
|
|
/**
|
|
|
|
* Get the class name for the egw_record to use while exporting
|
|
|
|
*
|
|
|
|
* @return string;
|
|
|
|
*/
|
|
|
|
public static function get_egw_record_class()
|
|
|
|
{
|
|
|
|
return 'admin_egw_user_record';
|
|
|
|
}
|
2011-04-12 17:38:27 +02:00
|
|
|
}
|