From fc8bb745d75dffd014421f45702efb3b9ebe71b3 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 23 Apr 2013 20:04:51 +0000 Subject: [PATCH] Improve handling of headers, checking translations and message_id --- .../inc/class.importexport_export_csv.inc.php | 2 + .../inc/class.importexport_import_ui.inc.php | 43 ++++++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/importexport/inc/class.importexport_export_csv.inc.php b/importexport/inc/class.importexport_export_csv.inc.php index 6c758275cf..e11f2ad255 100644 --- a/importexport/inc/class.importexport_export_csv.inc.php +++ b/importexport/inc/class.importexport_export_csv.inc.php @@ -172,6 +172,8 @@ class importexport_export_csv implements importexport_iface_export_record foreach($this->mapping as $field => &$label) { if($fields[$field]) $label = $fields[$field]; + // Make sure no * + if(substr($label,-1) == '*') $label = substr($label,0,-1); } } catch (Exception $e) { translation::add_app($appname); diff --git a/importexport/inc/class.importexport_import_ui.inc.php b/importexport/inc/class.importexport_import_ui.inc.php index 04a7399003..94a8152543 100644 --- a/importexport/inc/class.importexport_import_ui.inc.php +++ b/importexport/inc/class.importexport_import_ui.inc.php @@ -361,15 +361,44 @@ // Skipped column in definition continue; } - // Check column headers, taking into account different translations - elseif($index < count($options['csv_fields']) && strtoupper($options['csv_fields'][$index]) != strtoupper($header) && strtoupper(lang($options['csv_fields'][$index])) != strtoupper($header) && strtoupper($options['csv_fields'][$index]) != strtoupper(lang($header))) + else if ($index > count($options['csv_fields'])) { - // Problem - $message[] = lang("Column mismatch: %1 should be %2, not %3", - $index,$options['csv_fields'][$index], $header); - // But can still continue - // $ok = false; + // File has extra columns - already warned, above + break; } + + // Check for matching headers + if($options['csv_fields'][$index] == $header) + { + // Simple match + continue; + } + // Check column headers, taking into account different translations - make sure no * + $lang_defn = mb_strtoupper(translation::translate($options['csv_fields'][$index],false,'')); + $lang_file = mb_strtoupper(translation::translate($header,false,'')); + + if($lang_defn == $lang_file || + $lang_defn == mb_strtoupper($header) || + $lang_file == mb_strtoupper($options['csv_fields'][$index]) + ) + { + continue; + } + + // Try to go back to translation message ID for a match + $file_message_id = translation::get_message_id($header, $definition->application); + $defn_message_id = translation::get_message_id($options['csv_fields'][$index], $definition->application); + + if($file_message_id && $defn_message_id && $file_message_id == $defn_message_id) + { + continue; + } + + // Problem + $message[] = lang("Column mismatch: %1 should be %2, not %3", + $index,$options['csv_fields'][$index], $header); + // But can still continue + // $ok = false; } if(!$ok || count($message) != $message_count) {