From a947d9eb6f9c0667670551ec651cf9c42cf4a5a1 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 28 Sep 2010 21:08:54 +0000 Subject: [PATCH] Backport 32359 - Add a feature to try to auto-detect the field mapping --- ...portexport_wizard_basic_import_csv.inc.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/importexport/inc/class.importexport_wizard_basic_import_csv.inc.php b/importexport/inc/class.importexport_wizard_basic_import_csv.inc.php index 92150dcc39..1d245ebff3 100644 --- a/importexport/inc/class.importexport_wizard_basic_import_csv.inc.php +++ b/importexport/inc/class.importexport_wizard_basic_import_csv.inc.php @@ -127,6 +127,30 @@ class importexport_wizard_basic_import_csv if (($handle = fopen($GLOBALS['egw']->session->appsession('csvfile'), "rb")) !== FALSE) { $data = fgetcsv($handle, 8000, $content['fieldsep']); $content['csv_fields'] = translation::convert($data,$content['charset']); + + // Try to match automatically + $english = array(); + foreach($content['csv_fields'] as $index => $field) { + foreach($this->mapping_fields as $key => $field_name) { + if(strcasecmp($field, $field_name) == 0) { + $content['field_mapping'][$index] = $key; + continue; + } + // Check english also + if($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != 'en' && !isset($english[$field_name])) { + $msg_id = translation::get_message_id($field_name, $content['application']); + } + if($msg_id) { + $english[$field_name] = translation::read('en', $content['application'], $msg_id); + } else { + $english[$field_name] = false; + } + if($english[$field_name] && strcasecmp($field, $english[$field_name]) == 0) { + $content['field_mapping'][$index] = $key; + continue; + } + } + } } elseif($content['plugin_options']['csv_fields']) { $content['csv_fields'] = $content['plugin_options']['csv_fields']; }