mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-03 12:39:25 +01:00
Allow plugins to suggest download file names
This commit is contained in:
parent
23a97f6ab8
commit
e75e112598
@ -29,10 +29,15 @@ class importexport_export_csv implements importexport_iface_export_record
|
|||||||
*/
|
*/
|
||||||
protected $conversion = array();
|
protected $conversion = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Current record being processed
|
||||||
|
*/
|
||||||
|
public $record;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array holding the current record
|
* @var array holding the current record
|
||||||
*/
|
*/
|
||||||
protected $record = array();
|
protected $record_array = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var translation holds (charset) translation object
|
* @var translation holds (charset) translation object
|
||||||
@ -145,7 +150,8 @@ class importexport_export_csv implements importexport_iface_export_record
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function export_record( importexport_iface_egw_record $_record ) {
|
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 ?
|
// begin with fieldnames ?
|
||||||
if ($this->num_of_records == 0 && $this->csv_options['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'] );
|
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
|
// do conversions
|
||||||
if ( !empty( $this->conversion )) {
|
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
|
// do fieldmapping
|
||||||
if ( !empty( $this->mapping ) ) {
|
if ( !empty( $this->mapping ) ) {
|
||||||
$record_data = $this->record;
|
$record_data = $this->record_array;
|
||||||
$this->record = array();
|
$this->record_array = array();
|
||||||
foreach ($this->mapping as $egw_field => $csv_field) {
|
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++;
|
$this->num_of_records++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ class importexport_export_ui {
|
|||||||
}
|
}
|
||||||
if($charset == 'user') $charset = $GLOBALS['egw_info']['user']['preferences']['common']['csv_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 );
|
$result = $plugin_object->export( $file, $definition );
|
||||||
|
|
||||||
// Keep settings
|
// Keep settings
|
||||||
$keep = array_diff_key($_content, array_flip(array('appname', 'definition', 'plugin', 'preview', 'export', $tabs)));
|
$keep = array_diff_key($_content, array_flip(array('appname', 'definition', 'plugin', 'preview', 'export', $tabs)));
|
||||||
@ -292,7 +292,20 @@ class importexport_export_ui {
|
|||||||
fclose($file);
|
fclose($file);
|
||||||
$filename = pathinfo($tmpfname, PATHINFO_FILENAME);
|
$filename = pathinfo($tmpfname, PATHINFO_FILENAME);
|
||||||
$response->addScript("xajax_eT_wrapper();");
|
$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);');
|
$response->addScript('window.setTimeout("window.close();", 100);');
|
||||||
return $response->getXML();
|
return $response->getXML();
|
||||||
}
|
}
|
||||||
@ -484,7 +497,7 @@ class importexport_export_ui {
|
|||||||
if (!is_readable($tmpfname)) die();
|
if (!is_readable($tmpfname)) die();
|
||||||
|
|
||||||
$appname = $_GET['_appname'];
|
$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
|
// Turn off all output buffering
|
||||||
while (@ob_end_clean());
|
while (@ob_end_clean());
|
||||||
|
Loading…
Reference in New Issue
Block a user