Add export plugins for users and groups

This commit is contained in:
Nathan Gray 2011-04-12 15:38:27 +00:00
parent 2e4c048e9e
commit 64e2ada353
8 changed files with 604 additions and 1 deletions

View File

@ -0,0 +1,153 @@
<?php
/**
* eGroupWare - Admin - importexport
*
* @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$
*/
/**
* class admin_egw_group_record
* Record class needed for export
*/
class admin_egw_group_record implements importexport_iface_egw_record
{
private $identifier = '';
private $group = array();
// Used in conversions
static $types = array(
'select-account' => array('account_members'),
'select' => array('account_status'),
);
/**
* constructor
* reads record from backend if identifier is given.
*
* @param string $_identifier
*/
public function __construct( $_identifier='' ) {
if(is_array($_identifier)) {
$this->identifier = $_identifier['account_id'];
} else {
$this->identifier = $_identifier;
}
$this->set_record($GLOBALS['egw']->accounts->read($this->identifier));
}
/**
* magic method to set attributes of record
*
* @param string $_attribute_name
*/
public function __get($_attribute_name) {
return $this->group[$_attribute_name];
}
/**
* magig method to set attributes of record
*
* @param string $_attribute_name
* @param data $data
*/
public function __set($_attribute_name, $data) {
$this->group[$_attribute_name] = $data;
}
/**
* converts this object to array.
* @abstract We need such a function cause PHP5
* dosn't allow objects do define it's own casts :-(
* once PHP can deal with object casts we will change to them!
*
* @return array complete record as associative array
*/
public function get_record_array() {
return $this->group;
}
/**
* gets title of record
*
*@return string title
*/
public function get_title() {
return common::grab_owner_name($this->identifier);
}
/**
* sets complete record from associative array
*
* @todo add some checks
* @return void
*/
public function set_record(array $_record){
$this->group = $_record;
$this->group['account_members'] = $GLOBALS['egw']->accounts->members($this->group['account_id'],true);
}
/**
* gets identifier of this record
*
* @return string identifier of current record
*/
public function get_identifier() {
return $this->identifier;
}
/**
* saves record into backend
*
* @return string identifier
*/
public function save ( $_dst_identifier ) {
}
/**
* copies current record to record identified by $_dst_identifier
*
* @param string $_dst_identifier
* @return string dst_identifier
*/
public function copy ( $_dst_identifier ) {
}
/**
* moves current record to record identified by $_dst_identifier
* $this will become moved record
*
* @param string $_dst_identifier
* @return string dst_identifier
*/
public function move ( $_dst_identifier ) {
}
/**
* delets current record from backend
*
*/
public function delete () {
}
/**
* destructor
*
*/
public function __destruct() {
unset ($this->group);
}
} // end of egw_timesheet_record

View File

@ -0,0 +1,153 @@
<?php
/**
* eGroupWare - Admin - importexport
*
* @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$
*/
/**
* class admin_egw_user_record
* Record class needed for export
*/
class admin_egw_user_record implements importexport_iface_egw_record
{
private $identifier = '';
private $user = array();
// Used in conversions
static $types = array(
'date-time' => array('account_lastlogin', 'account_lastpwd_change', 'account_expires'),
'select-account' => array('account_primary_group'),
'select' => array('account_status'),
);
/**
* constructor
* reads record from backend if identifier is given.
*
* @param string $_identifier
*/
public function __construct( $_identifier='' ) {
if(is_array($_identifier)) {
$this->identifier = $_identifier['account_id'];
} else {
$this->identifier = $_identifier;
}
$this->set_record($GLOBALS['egw']->accounts->read($this->identifier));
}
/**
* magic method to set attributes of record
*
* @param string $_attribute_name
*/
public function __get($_attribute_name) {
return $this->user[$_attribute_name];
}
/**
* magig method to set attributes of record
*
* @param string $_attribute_name
* @param data $data
*/
public function __set($_attribute_name, $data) {
$this->user[$_attribute_name] = $data;
}
/**
* converts this object to array.
* @abstract We need such a function cause PHP5
* dosn't allow objects do define it's own casts :-(
* once PHP can deal with object casts we will change to them!
*
* @return array complete record as associative array
*/
public function get_record_array() {
return $this->user;
}
/**
* gets title of record
*
*@return string title
*/
public function get_title() {
return common::grab_owner_name($this->identifier);
}
/**
* sets complete record from associative array
*
* @todo add some checks
* @return void
*/
public function set_record(array $_record){
$this->user = $_record;
}
/**
* gets identifier of this record
*
* @return string identifier of current record
*/
public function get_identifier() {
return $this->identifier;
}
/**
* saves record into backend
*
* @return string identifier
*/
public function save ( $_dst_identifier ) {
}
/**
* copies current record to record identified by $_dst_identifier
*
* @param string $_dst_identifier
* @return string dst_identifier
*/
public function copy ( $_dst_identifier ) {
}
/**
* moves current record to record identified by $_dst_identifier
* $this will become moved record
*
* @param string $_dst_identifier
* @return string dst_identifier
*/
public function move ( $_dst_identifier ) {
}
/**
* delets current record from backend
*
*/
public function delete () {
}
/**
* destructor
*
*/
public function __destruct() {
unset ($this->user);
}
} // end of egw_timesheet_record

View File

@ -0,0 +1,108 @@
<?php
/**
* eGroupWare - Export plugin for groups
*
* @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
*/
class admin_export_groups_csv implements importexport_iface_export_plugin {
/**
* Exports records as defined in $_definition
*
* @param egw_record $_definition
*/
public function export( $_stream, importexport_definition $_definition) {
$options = $_definition->plugin_options;
$selection = array();
$query = array(
'type' => 'groups',
);
$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(
'account_status' => array('A' => lang('Enabled'), '' => lang('Disabled'), 'D' => lang('Disabled')),
);
// $_record is an array, that's what search() returns
foreach ($selection as $_record) {
$record = new admin_egw_group_record($_record);
if($options['convert']) {
importexport_export_csv::convert($record, admin_egw_group_record::$types, 'admin', $lookups);
} else {
// Implode arrays, so they don't say 'Array'
foreach($record->get_record_array() as $key => $value) {
if(is_array($value)) $record->$key = implode(',', $value);
}
}
$export_object->export_record($record);
unset($record);
}
}
/**
* returns translated name of plugin
*
* @return string name
*/
public static function get_name() {
return lang('Group CSV export');
}
/**
* returns translated (user) description of plugin
*
* @return string descriprion
*/
public static function get_description() {
return lang("Exports groups into a CSV File. ");
}
/**
* returns file suffix for exported file
*
* @return string suffix
*/
public static function get_filesuffix() {
return 'csv';
}
public static function get_mimetype() {
return 'text/csv';
}
/**
* return html for options.
* this way the plugin has all opportunities for options tab
*
* @return string html
*/
public function get_options_etpl() {
return false;
}
/**
* returns slectors of this plugin via xajax
*
*/
public function get_selectors_etpl() {
return array(
'preserv' => array('no_error_for_no_selection'),
);
}
}

View File

@ -0,0 +1,112 @@
<?php
/**
* eGroupWare - Export plugin for users
*
* @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
*/
class admin_export_users_csv implements importexport_iface_export_plugin {
/**
* Exports records as defined in $_definition
*
* @param egw_record $_definition
*/
public function export( $_stream, importexport_definition $_definition) {
$options = $_definition->plugin_options;
$selection = array();
$query = array(
'type' => 'accounts',
);
if($options['selection']['group_id']) {
$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(
'account_status' => array('A' => lang('Enabled'), '' => lang('Disabled'), 'D' => lang('Disabled')),
);
// $_record is an array, that's what search() returns
foreach ($selection as $_record) {
$record = new admin_egw_user_record($_record);
if($options['convert']) {
importexport_export_csv::convert($record, admin_egw_user_record::$types, 'admin', $lookups);
} else {
// Implode arrays, so they don't say 'Array'
foreach($record->get_record_array() as $key => $value) {
if(is_array($value)) $record->$key = implode(',', $value);
}
}
$export_object->export_record($record);
unset($record);
}
}
/**
* returns translated name of plugin
*
* @return string name
*/
public static function get_name() {
return lang('User CSV export');
}
/**
* returns translated (user) description of plugin
*
* @return string descriprion
*/
public static function get_description() {
return lang("Exports users into a CSV File. ");
}
/**
* returns file suffix for exported file
*
* @return string suffix
*/
public static function get_filesuffix() {
return 'csv';
}
public static function get_mimetype() {
return 'text/csv';
}
/**
* return html for options.
* this way the plugin has all opportunities for options tab
*
* @return string html
*/
public function get_options_etpl() {
return false;
}
/**
* returns slectors of this plugin via xajax
*
*/
public function get_selectors_etpl() {
return array(
'name' => 'admin.export_users_csv_selectors',
'preserv' => array('no_error_for_all'),
);
}
}

View File

@ -0,0 +1,32 @@
<?php
/**
* eGroupWare - Wizard for Groups CSV export
*
* @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
* @version $Id$
*/
class admin_wizard_export_groups_csv extends importexport_wizard_basic_export_csv
{
public function __construct() {
parent::__construct();
// Field mapping
$this->export_fields = array(
'account_id' => lang('Account ID'),
'account_lid' => lang('Group Name'),
'account_members' => lang('Members'),
);
// Custom fields - not really used in admin...
unset($this->export_fields['customfields']);
$custom = config::get_customfields('admin', true);
foreach($custom as $name => $data) {
$this->export_fields['#'.$name] = $data['label'];
}
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* eGroupWare - Wizard for User CSV export
*
* @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
* @version $Id$
*/
class admin_wizard_export_users_csv extends importexport_wizard_basic_export_csv
{
public function __construct() {
parent::__construct();
// Field mapping
$this->export_fields = array(
'account_id' => lang('Account ID'),
'account_lid' => lang('LoginID'),
'account_firstname' => lang('First Name'),
'account_lastname' => lang('Last Name'),
'account_email' => lang('email'),
'account_passwd' => lang('Password'),
'account_active' => lang('Account active'),
'account_primary_group' => lang('primary Group'),
'account_groups' => lang('Groups'),
'account_expires' => lang('Expires'),
'anonymous' => lang('Anonymous User (not shown in list sessions)'),
'changepassword' => lang('Can change password'),
'mustchangepassword' => lang('Must change password upon next login'),
);
// Custom fields - not really used in admin...
unset($this->export_fields['customfields']);
$custom = config::get_customfields('admin', true);
foreach($custom as $name => $data) {
$this->export_fields['#'.$name] = $data['label'];
}
}
}

View File

@ -25,6 +25,7 @@ class admin_wizard_import_users_csv extends importexport_wizard_basic_import_csv
// Field mapping
$this->mapping_fields = array(
'account_id' => lang('Account ID'),
'account_lid' => lang('LoginID'),
'account_firstname' => lang('First Name'),
'account_lastname' => lang('Last Name'),

View File

@ -2,7 +2,7 @@
/**
* eGroupWare - eTemplates for Application admin
* http://www.egroupware.org
* generated by soetemplate::dump4setup() 2011-04-05 16:58
* generated by soetemplate::dump4setup() 2011-04-12 09:22
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package admin
@ -53,6 +53,8 @@ $templ_data[] = array('name' => 'admin.customfields.fields','template' => '','la
$templ_data[] = array('name' => 'admin.customfields.types','template' => '','lang' => '','group' => '0','version' => '1.2','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:2:{i:0;a:4:{s:1:"D";s:15:",@non_deletable";s:1:"E";s:8:",@no_add";s:1:"F";s:8:",@no_add";s:2:"h1";s:15:",@no_edit_types";}i:1;a:6:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:4:"name";s:8:"app-name";}s:1:"B";a:2:{s:4:"type";s:5:"label";s:5:"label";s:7:"- type";}s:1:"C";a:4:{s:4:"type";s:6:"select";s:4:"name";s:5:"types";s:8:"onchange";s:1:"1";s:7:"no_lang";s:1:"1";}s:1:"D";a:4:{s:4:"type";s:6:"button";s:5:"label";s:6:"Delete";s:4:"name";s:6:"delete";s:7:"onclick";s:110:"return confirm(\'WARNING: You are about to delete this type. Entries of this type won\\\'t be accessable then.\');";}s:1:"E";a:3:{s:4:"type";s:4:"text";s:4:"name";s:4:"name";s:4:"blur";s:8:"new name";}s:1:"F";a:3:{s:4:"type";s:6:"button";s:5:"label";s:6:"Create";s:4:"name";s:6:"create";}}}s:4:"rows";i:1;s:4:"cols";i:6;}}','size' => '','style' => '','modified' => '1139823458',);
$templ_data[] = array('name' => 'admin.export_users_csv_selectors','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:2:{i:0;a:0:{}i:1;a:1:{s:1:"A";a:4:{s:4:"type";s:14:"select-account";s:4:"size";s:10:"All,groups";s:5:"label";s:5:"Group";s:4:"name";s:8:"group_id";}}}s:4:"rows";i:1;s:4:"cols";i:1;s:4:"name";s:9:"selection";s:7:"options";a:0:{}}}','size' => '','style' => '','modified' => '1302620448',);
$templ_data[] = array('name' => 'admin.passwordreset','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:7:{i:0;a:2:{s:2:"h1";s:6:",!@msg";s:2:"c5";s:4:",top";}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:13:"all,redItalic";s:4:"name";s:3:"msg";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:2;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:12:"Select users";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:3;a:2:{s:1:"A";a:3:{s:4:"type";s:14:"select-account";s:4:"size";s:2:"15";s:4:"name";s:5:"users";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:4;a:2:{s:1:"A";a:8:{s:4:"type";s:8:"groupbox";s:4:"size";s:1:"5";s:5:"label";s:7:"Actions";i:1;a:3:{s:4:"type";s:8:"checkbox";s:5:"label";s:21:"Set a random password";s:4:"name";s:9:"random_pw";}i:2;a:5:{s:4:"type";s:11:"select-bool";s:4:"size";s:15:"Leave unchanged";s:5:"label";s:36:"Must change password upon next login";s:4:"name";s:18:"mustchangepassword";s:8:"onchange";s:85:"if (this.value==\'1\') document.getElementById(form::name(\'changepassword\')).value=\'1\';";}i:3;a:5:{s:4:"type";s:11:"select-bool";s:4:"size";s:15:"Leave unchanged";s:5:"label";s:19:"Can change password";s:4:"name";s:14:"changepassword";s:8:"onchange";s:136:"var mustchange=document.getElementById(form::name(\'mustchangepassword\')); if (this.value==\'0\' && mustchange.value) mustchange.value=\'0\';";}i:4;a:4:{s:4:"type";s:4:"hbox";s:4:"size";s:6:"2,,0,0";i:1;a:4:{s:4:"type";s:6:"select";s:4:"size";s:15:"Leave unchanged";s:4:"name";s:4:"hash";s:5:"label";s:23:"Change password hash to";}i:2;a:5:{s:4:"type";s:4:"text";s:5:"label";s:12:"Current hash";s:4:"name";s:12:"current_hash";s:4:"span";s:14:",leftPad5 gray";s:8:"readonly";s:1:"1";}}i:5;a:3:{s:4:"type";s:8:"checkbox";s:5:"label";s:20:"Notify user by email";s:4:"name";s:6:"notify";}}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:5;a:2:{s:1:"A";a:5:{s:4:"type";s:8:"groupbox";s:4:"size";s:1:"2";s:5:"label";s:17:"Notification mail";i:1;a:4:{s:4:"type";s:4:"text";s:4:"size";s:2:"64";s:4:"name";s:7:"subject";s:4:"blur";s:7:"Subject";}i:2;a:3:{s:4:"type";s:8:"textarea";s:4:"size";s:5:"15,64";s:4:"name";s:4:"body";}}s:1:"B";a:4:{s:4:"type";s:4:"vbox";s:4:"size";s:1:"2";i:1;a:3:{s:4:"type";s:5:"label";s:4:"span";s:5:",gray";s:5:"label";s:22:"Available placeholders";}i:2;a:6:{s:4:"type";s:4:"grid";s:4:"span";s:5:",gray";s:4:"name";s:12:"replacements";s:4:"data";a:2:{i:0;a:0:{}i:1;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:4:"name";s:12:"${row}[name]";}s:1:"B";a:2:{s:4:"type";s:5:"label";s:4:"name";s:13:"${row}[label]";}}}s:4:"rows";i:1;s:4:"cols";i:2;}}}i:6;a:2:{s:1:"A";a:3:{s:4:"type";s:6:"button";s:5:"label";s:5:"Start";s:4:"name";s:5:"start";}s:1:"B";a:3:{s:4:"type";s:6:"button";s:5:"label";s:12:"Download CSV";s:4:"name";s:12:"download_csv";}}}s:4:"rows";i:6;s:4:"cols";i:2;}}','size' => '','style' => '','modified' => '1301655701',);
$templ_data[] = array('name' => 'admin.remotes','template' => '','lang' => '','group' => '0','version' => '1.5.001','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:5:{i:0;a:3:{s:2:"h2";s:9:",!@remote";s:2:"h1";s:6:",!@msg";s:2:"h3";s:2:",1";}i:1;a:1:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:13:"all,redItalic";s:4:"name";s:3:"msg";}}i:2;a:1:{s:1:"A";a:4:{s:4:"type";s:8:"template";s:4:"size";s:6:"remote";s:4:"span";s:10:"all,border";s:4:"name";s:18:"admin.remotes.edit";}}i:3;a:1:{s:1:"A";a:3:{s:4:"type";s:8:"template";s:5:"align";s:5:"right";s:4:"name";s:26:"admin.remotes.header_right";}}i:4;a:1:{s:1:"A";a:3:{s:4:"type";s:9:"nextmatch";s:4:"name";s:2:"nm";s:4:"size";s:18:"admin.remotes.rows";}}}s:4:"rows";i:4;s:4:"cols";i:1;s:4:"size";s:4:"100%";s:7:"options";a:1:{i:0;s:4:"100%";}}}','size' => '100%','style' => '.border { border: black solid 2px; }','modified' => '1195926693',);