From a4171b76754f16ccddfa762f4d211c6ad57561a0 Mon Sep 17 00:00:00 2001 From: Junichi Satoh Date: Mon, 23 Nov 2015 10:43:21 +0900 Subject: [PATCH] Fixed wrong encodings in exported csv file with multi-byte characters. --- pandora_console/include/graphs/export_data.php | 15 +++++++++++++-- .../include/graphs/flot/pandora.flot.js | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/graphs/export_data.php b/pandora_console/include/graphs/export_data.php index cd3a021701..b9887600b6 100644 --- a/pandora_console/include/graphs/export_data.php +++ b/pandora_console/include/graphs/export_data.php @@ -21,6 +21,13 @@ require_once ("../../include/functions.php"); global $config; +$user_language = get_user_language($config['id_user']); +$l10n = NULL; +if (file_exists ('../languages/' . $user_language . '.mo')) { + $l10n = new gettext_reader (new CachedFileReader ('../languages/'.$user_language.'.mo')); + $l10n->load_tables(); +} + // Get data $type = (string) get_parameter('type', 'csv'); @@ -51,7 +58,11 @@ $output_csv = function ($data, $filename) { // CSV Output header ('Content-Type: text/csv; charset=UTF-8'); header ('Content-Disposition: attachment; filename="'.$filename.'.csv"'); - + + // BOM + if (!$excel_encoding) + print pack('C*',0xEF,0xBB,0xBF); + // Header // Item / data @@ -64,7 +75,7 @@ $output_csv = function ($data, $filename) { foreach ($items['data'] as $item) { $item = str_replace("--> ".__('Selected'),'',$item); $line = implode($separator, $item); - + if ($excel_encoding) echo mb_convert_encoding($line, 'UTF-16LE', 'UTF-8') . "\n"; else diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 2dbdd188b6..7335d1f07f 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -1443,7 +1443,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, $excelInput .prop('name', 'excel_encoding') .prop('type', 'text') - .prop('value', false); + .prop('value', 0); $form .prop('method', 'POST')