From c99e804d8d8bdf65959af2cc0ed3c94996e14026 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Wed, 2 Mar 2011 17:08:43 +0000 Subject: [PATCH] Add 'All custom fields' field option, that will cause all custom fields to be exported --- .../inc/class.importexport_export_csv.inc.php | 10 +++++++++- ...mportexport_wizard_basic_export_csv.inc.php | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/importexport/inc/class.importexport_export_csv.inc.php b/importexport/inc/class.importexport_export_csv.inc.php index 7f82f34a1a..adecf0049f 100644 --- a/importexport/inc/class.importexport_export_csv.inc.php +++ b/importexport/inc/class.importexport_export_csv.inc.php @@ -112,10 +112,18 @@ class importexport_export_csv implements importexport_iface_export_record * * @param array $_mapping egw_field_name => csv_field_name */ - public function set_mapping( array $_mapping) { + public function set_mapping( array &$_mapping) { if ($this->num_of_records > 0) { throw new Exception('Error: Field mapping can\'t be set during ongoing export!'); } + if($_mapping['all_custom_fields']) { + // Field value is the appname, so we can pull the fields + $custom = config::get_customfields($_mapping['all_custom_fields']); + unset($_mapping['all_custom_fields']); + foreach($custom as $field => $info) { + $_mapping['#'.$field] = $this->csv_options['begin_with_fieldnames'] == 'label' ? $info['label'] : $field; + } + } $this->mapping = $_mapping; } diff --git a/importexport/inc/class.importexport_wizard_basic_export_csv.inc.php b/importexport/inc/class.importexport_wizard_basic_export_csv.inc.php index f796765a6a..35d6bf3307 100644 --- a/importexport/inc/class.importexport_wizard_basic_export_csv.inc.php +++ b/importexport/inc/class.importexport_wizard_basic_export_csv.inc.php @@ -60,7 +60,7 @@ class importexport_wizard_basic_export_csv 'wizard_step40' => lang('Choose seperator and charset'), ); list($appname, $part2) = explode('_', get_class($this)); - if(!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name + if(!$GLOBALS['egw_info']['apps'][$appname]) $appname .= '_'.$part2; // Handle apps with _ in the name translation::add_app($appname); } @@ -74,6 +74,16 @@ class importexport_wizard_basic_export_csv if ($content['step'] == 'wizard_step30') { $content['mapping'] = array_combine($content['fields']['export'], $content['fields']['export']); + if($content['mapping']['all_custom_fields']) { + // Need the appname during actual export, to fetch the fields + $parts = explode('_', get_class($this)); + $appname = $parts[0]; + foreach($parts as $name_part) { + if($GLOBALS['egw_info']['apps'][$appname]) break; + $appname .= '_'.$name_part; // Handle apps with _ in the name + } + $content['mapping']['all_custom_fields'] = $appname; + } unset($content['mapping']['']); unset($content['fields']); switch (array_search('pressed', $content['button'])) @@ -93,11 +103,14 @@ class importexport_wizard_basic_export_csv { $content['msg'] = $this->steps['wizard_step30']; $content['step'] = 'wizard_step30'; + $this->export_fields += array('all_custom_fields' => 'All custom fields'); $sel_options['field'] = $this->export_fields; $preserv = $content; unset ($preserv['button']); + unset ($preserv['fields']); $content['fields'] = array(''); if(!$content['mapping']) $content['mapping'] = $content['plugin_options']['mapping']; + $row = 1; foreach($this->export_fields as $field => $name) { $content['fields'][] = array( @@ -131,7 +144,8 @@ class importexport_wizard_basic_export_csv if ($content['step'] == 'wizard_step40') { if($content['begin_with_fieldnames'] == 'label') { foreach($content['mapping'] as $field => &$label) { - $label = $this->export_fields[$field]; + // Check first, to avoid clearing any pseudo-columns (ex: All custom fields) + $label = $this->export_fields[$field] ? $this->export_fields[$field] : $label; } } switch (array_search('pressed', $content['button']))