Fixed wrong encodings in exported csv file with multi-byte characters.

This commit is contained in:
Junichi Satoh 2015-11-23 10:43:21 +09:00
parent 6a28bcb9fb
commit a4171b7675
2 changed files with 14 additions and 3 deletions

View File

@ -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

View File

@ -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')