From bf9632b14a0d9122ad75bcde229fcf85b23718dc Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Wed, 14 Dec 2011 16:33:54 +0000 Subject: [PATCH] Keep original field names when export definition is created from import definition --- .../class.importexport_definitions_bo.inc.php | 3 ++ .../inc/class.importexport_export_csv.inc.php | 31 ++++++++++--------- ...portexport_wizard_basic_export_csv.inc.php | 13 +++++++- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/importexport/inc/class.importexport_definitions_bo.inc.php b/importexport/inc/class.importexport_definitions_bo.inc.php index 3e66c99c79..b451d2fb75 100644 --- a/importexport/inc/class.importexport_definitions_bo.inc.php +++ b/importexport/inc/class.importexport_definitions_bo.inc.php @@ -294,6 +294,9 @@ class importexport_definitions_bo { // Try to use heading from import file, if possible $e_options['mapping'][$field] = $i_options['csv_fields'][$col_num] ? $i_options['csv_fields'][$col_num] : $field; } + // Keep field names + $e_options['no_header_translation'] = true; + $export->plugin_options = $e_options; // Permissions diff --git a/importexport/inc/class.importexport_export_csv.inc.php b/importexport/inc/class.importexport_export_csv.inc.php index cb05657d15..3c67c2da03 100644 --- a/importexport/inc/class.importexport_export_csv.inc.php +++ b/importexport/inc/class.importexport_export_csv.inc.php @@ -155,20 +155,23 @@ class importexport_export_csv implements importexport_iface_export_record if(!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name // Get translations from wizard, if possible - $backtrace = debug_backtrace(); - $plugin = $backtrace[1]['class']; - $wizard_name = $appname . '_wizard_' . str_replace($appname . '_', '', $plugin); - try { - $wizard = new $wizard_name; - $fields = $wizard->get_export_fields(); - foreach($this->mapping as $field => &$label) - { - if($fields[$field]) $label = $fields[$field]; - } - } catch (Exception $e) { - translation::add_app($appname); - foreach($this->mapping as $field => &$label) { - $label = lang($label); + if(!$this->csv_options['no_header_translation']) + { + $backtrace = debug_backtrace(); + $plugin = $backtrace[1]['class']; + $wizard_name = $appname . '_wizard_' . str_replace($appname . '_', '', $plugin); + try { + $wizard = new $wizard_name; + $fields = $wizard->get_export_fields(); + foreach($this->mapping as $field => &$label) + { + if($fields[$field]) $label = $fields[$field]; + } + } catch (Exception $e) { + translation::add_app($appname); + foreach($this->mapping as $field => &$label) { + $label = lang($label); + } } } } 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 b15c402bc9..f18f5ed9f3 100644 --- a/importexport/inc/class.importexport_wizard_basic_export_csv.inc.php +++ b/importexport/inc/class.importexport_wizard_basic_export_csv.inc.php @@ -73,7 +73,18 @@ class importexport_wizard_basic_export_csv // return from step30 if ($content['step'] == 'wizard_step30') { - $content['mapping'] = array_combine($content['fields']['export'], $content['fields']['export']); + foreach($content['fields']['export'] as $field_name) + { + // Preserve original field names, where available + if($content['plugin_options']['no_header_translation'] && $content['plugin_options']['mapping'][$field_name]) + { + $content['mapping'][$field_name] = $content['plugin_options']['mapping'][$field_name]; + } + else + { + $content['mapping'][$field_name] = $field_name; + } + } if($content['mapping']['all_custom_fields']) { // Need the appname during actual export, to fetch the fields $parts = explode('_', get_class($this));