From e75e1125984fd5a0aea9a30618f2d2cbf5c5c140 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 16 Oct 2012 18:44:33 +0000 Subject: [PATCH] Allow plugins to suggest download file names --- .../inc/class.importexport_export_csv.inc.php | 22 ++++++++++++------- .../inc/class.importexport_export_ui.inc.php | 19 +++++++++++++--- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/importexport/inc/class.importexport_export_csv.inc.php b/importexport/inc/class.importexport_export_csv.inc.php index e77a628517..474ab78324 100644 --- a/importexport/inc/class.importexport_export_csv.inc.php +++ b/importexport/inc/class.importexport_export_csv.inc.php @@ -29,10 +29,15 @@ class importexport_export_csv implements importexport_iface_export_record */ protected $conversion = array(); + /** + * @var Current record being processed + */ + public $record; + /** * @var array holding the current record */ - protected $record = array(); + protected $record_array = array(); /** * @var translation holds (charset) translation object @@ -145,7 +150,8 @@ class importexport_export_csv implements importexport_iface_export_record * @return bool */ public function export_record( importexport_iface_egw_record $_record ) { - $this->record = $_record->get_record_array(); + $this->record = $_record; + $this->record_array = $_record->get_record_array(); // begin with fieldnames ? if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] ) { @@ -175,7 +181,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_array ); self::fputcsv( $this->handle ,$mapping ,$this->csv_options['delimiter'], $this->csv_options['enclosure'] ); } @@ -186,19 +192,19 @@ class importexport_export_csv implements importexport_iface_export_record // do conversions if ( !empty( $this->conversion )) { - $this->record = importexport_helper_functions::conversion( $this->record, $this->conversion ); + $this->record_array = importexport_helper_functions::conversion( $this->record_array, $this->conversion ); } // do fieldmapping if ( !empty( $this->mapping ) ) { - $record_data = $this->record; - $this->record = array(); + $record_data = $this->record_array; + $this->record_array = array(); foreach ($this->mapping as $egw_field => $csv_field) { - $this->record[$csv_field] = $record_data[$egw_field]; + $this->record_array[$csv_field] = $record_data[$egw_field]; } } - self::fputcsv( $this->handle, $this->record, $this->csv_options['delimiter'], $this->csv_options['enclosure'] ); + self::fputcsv( $this->handle, $this->record_array, $this->csv_options['delimiter'], $this->csv_options['enclosure'] ); $this->num_of_records++; } diff --git a/importexport/inc/class.importexport_export_ui.inc.php b/importexport/inc/class.importexport_export_ui.inc.php index f8ff570c3c..afc6bc40a1 100644 --- a/importexport/inc/class.importexport_export_ui.inc.php +++ b/importexport/inc/class.importexport_export_ui.inc.php @@ -277,7 +277,7 @@ class importexport_export_ui { } if($charset == 'user') $charset = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; $plugin_object = new $definition->plugin; - $plugin_object->export( $file, $definition ); + $result = $plugin_object->export( $file, $definition ); // Keep settings $keep = array_diff_key($_content, array_flip(array('appname', 'definition', 'plugin', 'preview', 'export', $tabs))); @@ -292,7 +292,20 @@ class importexport_export_ui { fclose($file); $filename = pathinfo($tmpfname, PATHINFO_FILENAME); $response->addScript("xajax_eT_wrapper();"); - $response->addScript("opener.location.href='". $GLOBALS['egw']->link('/index.php','menuaction=importexport.importexport_export_ui.download&_filename='. $filename.'&_appname='. $definition->application). "&_suffix=". $plugin_object->get_filesuffix(). "&_type=".$plugin_object->get_mimetype() ."';"); + $link_query = array( + 'menuaction' => 'importexport.importexport_export_ui.download', + '_filename' => $filename, + '_appname' => $definition->application, + '_suffix' => $plugin_object->get_filesuffix(), + '_type' => $plugin_object->get_mimetype() + ); + + // Allow plugins to suggest a file name - return false if they have no suggestion + if(method_exists($plugin_object, 'get_filename') && $plugin_filename = $plugin_object->get_filename()) + { + $link_query['filename'] = $plugin_filename; + } + $response->addScript("opener.location.href='". $GLOBALS['egw']->link('/index.php',$link_query)."'"); $response->addScript('window.setTimeout("window.close();", 100);'); return $response->getXML(); } @@ -484,7 +497,7 @@ class importexport_export_ui { if (!is_readable($tmpfname)) die(); $appname = $_GET['_appname']; - $nicefname = 'egw_export_'.$appname.'-'.date('Y-m-d'); + $nicefname = $_GET['filename'] ? $_GET['filename'] : 'egw_export_'.$appname.'-'.date('Y-m-d'); // Turn off all output buffering while (@ob_end_clean());