- Fix broken encodings by using export_csv's fputcsv

- Include set charset in HTTP header
This commit is contained in:
Nathan Gray 2011-12-08 17:27:16 +00:00
parent 7b2fd55d83
commit d4cda9a91a
2 changed files with 14 additions and 8 deletions

View File

@ -174,7 +174,7 @@ class importexport_export_csv implements importexport_iface_export_record
} }
$mapping = ! empty( $this->mapping ) ? $this->mapping : array_keys ( $this->record ); $mapping = ! empty( $this->mapping ) ? $this->mapping : array_keys ( $this->record );
$mapping = $this->translation->convert( $mapping, $this->translation->charset(), $this->csv_charset ); $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 // Check for limit
@ -196,7 +196,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++; $this->num_of_records++;
} }
@ -372,7 +372,7 @@ class importexport_export_csv implements importexport_iface_export_record
/** /**
* The php build in fputcsv function is buggy, so we need an own one :-( * 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 resource $filePointer
* @param array $dataArray * @param array $dataArray

View File

@ -271,6 +271,7 @@ class importexport_export_ui {
if (! $charset = $definition->plugin_options['charset']) { if (! $charset = $definition->plugin_options['charset']) {
$charset = $GLOBALS['egw']->translation->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 = new $definition->plugin;
$plugin_object->export( $file, $definition ); $plugin_object->export( $file, $definition );
@ -280,6 +281,8 @@ class importexport_export_ui {
// save prefs, but do NOT invalid the cache (unnecessary) // save prefs, but do NOT invalid the cache (unnecessary)
$GLOBALS['egw']->preferences->save_repository(false,'user',false); $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') { if($_content['export'] == 'pressed') {
fclose($file); fclose($file);
@ -306,10 +309,9 @@ class importexport_export_ui {
fclose($file); fclose($file);
unlink($tmpfname); unlink($tmpfname);
// NOTE: $definition->plugin_options['charset'] may not be set, // Convert back to system charset for display
// but it's the best guess atm.
$preview = $GLOBALS['egw']->translation->convert( $preview, $preview = $GLOBALS['egw']->translation->convert( $preview,
$definition->plugin_options['charset'], $charset,
$GLOBALS['egw']->translation->charset() $GLOBALS['egw']->translation->charset()
); );
@ -483,9 +485,13 @@ class importexport_export_ui {
// Turn off all output buffering // Turn off all output buffering
while (@ob_end_clean()); 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'); $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); fpassthru($file);
unlink($tmpfname); unlink($tmpfname);