From e272848444d375e7e9aeb4fa3e083c466d7f9543 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Fri, 9 Dec 2011 21:08:48 +0000 Subject: [PATCH] - Fix broken encodings by using export_csv's fputcsv - Include set charset in HTTP header --- .../inc/class.importexport_export_csv.inc.php | 6 +++--- .../inc/class.importexport_export_ui.inc.php | 16 +++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/importexport/inc/class.importexport_export_csv.inc.php b/importexport/inc/class.importexport_export_csv.inc.php index 008d017127..f1a9eb62a5 100644 --- a/importexport/inc/class.importexport_export_csv.inc.php +++ b/importexport/inc/class.importexport_export_csv.inc.php @@ -160,7 +160,7 @@ class importexport_export_csv implements importexport_iface_export_record } $mapping = ! empty( $this->mapping ) ? $this->mapping : array_keys ( $this->record ); $mapping = $this->translation->convert( $mapping, $this->translation->charset(), $this->csv_charset ); - fputcsv( $this->handle ,$mapping ,$this->csv_options['delimiter'], $this->csv_options['enclosure'] ); + self::fputcsv( $this->handle ,$mapping ,$this->csv_options['delimiter'], $this->csv_options['enclosure'] ); } // Check for limit @@ -182,7 +182,7 @@ class importexport_export_csv implements importexport_iface_export_record } } - fputcsv( $this->handle, $this->record, $this->csv_options['delimiter'], $this->csv_options['enclosure'] ); + self::fputcsv( $this->handle, $this->record, $this->csv_options['delimiter'], $this->csv_options['enclosure'] ); $this->num_of_records++; } @@ -358,7 +358,7 @@ class importexport_export_csv implements importexport_iface_export_record /** * The php build in fputcsv function is buggy, so we need an own one :-( - * Buggy how? + * It ignores encoding, and outputs in UTF-8 / system charset * * @param resource $filePointer * @param array $dataArray diff --git a/importexport/inc/class.importexport_export_ui.inc.php b/importexport/inc/class.importexport_export_ui.inc.php index 6f6c176a46..3d9e8c7c2c 100644 --- a/importexport/inc/class.importexport_export_ui.inc.php +++ b/importexport/inc/class.importexport_export_ui.inc.php @@ -271,6 +271,7 @@ class importexport_export_ui { if (! $charset = $definition->plugin_options['charset']) { $charset = $GLOBALS['egw']->translation->charset(); } + if($charset == 'user') $charset = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; $plugin_object = new $definition->plugin; $plugin_object->export( $file, $definition ); @@ -280,6 +281,8 @@ class importexport_export_ui { // save prefs, but do NOT invalid the cache (unnecessary) $GLOBALS['egw']->preferences->save_repository(false,'user',false); + // Store charset to use in header + egw_cache::setSession('importexport', $tmpfname, $charset, 100); if($_content['export'] == 'pressed') { fclose($file); @@ -306,10 +309,9 @@ class importexport_export_ui { fclose($file); unlink($tmpfname); - // NOTE: $definition->plugin_options['charset'] may not be set, - // but it's the best guess atm. + // Convert back to system charset for display $preview = $GLOBALS['egw']->translation->convert( $preview, - $definition->plugin_options['charset'], + $charset, $GLOBALS['egw']->translation->charset() ); @@ -483,9 +485,13 @@ class importexport_export_ui { // Turn off all output buffering while (@ob_end_clean()); - header('Content-type: ' . $_GET['_type'] ? $_GET['_type'] : 'application/text'); - header('Content-Disposition: attachment; filename="'.$nicefname.'.'.$_GET['_suffix'].'"'); $file = fopen($tmpfname,'rb'); + + // Get charset + $charset = egw_cache::getSession('importexport', $tmpfname); + + header('Content-type: ' . ($_GET['_type'] ? $_GET['_type'] : 'application/text') . ($charset ? '; charset='.$charset : '')); + header('Content-Disposition: attachment; filename="'.$nicefname.'.'.$_GET['_suffix'].'"'); fpassthru($file); unlink($tmpfname);