From 29269e9981bc1fd95b32052790688e83a01204df Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 24 Feb 2011 16:45:01 +0100 Subject: [PATCH] Hochladen und Anzeigen von hochgeladenen Dateien implementiert --- SL/Controller/CsvImport.pm | 22 +++++++++++++++++++++- templates/webpages/csv_import/form.html | 14 +++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index d11747ad5..03b9b4006 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -5,6 +5,7 @@ use strict; use SL::DB::Buchungsgruppe; use SL::DB::CsvImportProfile; use SL::Helper::Flash; +use SL::SessionFile; use List::MoreUtils qw(none); @@ -12,7 +13,7 @@ use parent qw(SL::Controller::Base); use Rose::Object::MakeMethods::Generic ( - scalar => [ qw(type profile all_profiles all_charsets sep_char all_sep_chars quote_char all_quote_chars escape_char all_escape_chars all_buchungsgruppen) ], + scalar => [ qw(type profile file all_profiles all_charsets sep_char all_sep_chars quote_char all_quote_chars escape_char all_escape_chars all_buchungsgruppen) ], ); __PACKAGE__->run_before('check_auth'); @@ -108,6 +109,8 @@ sub render_inputs { $self->$sub(($char_map{$type}->{$char} || [])->[0] || $char); } + $self->file(SL::SessionFile->new($self->csv_file_name)); + my $title = $self->type eq 'customers_vendors' ? $::locale->text('CSV import: customers and vendors') : $self->type eq 'addresses' ? $::locale->text('CSV import: shipping addresses') : $self->type eq 'contacts' ? $::locale->text('CSV import: contacts') @@ -124,6 +127,18 @@ sub test_and_import { $self->profile_from_form; + if ($::form->{file}) { + my $file = SL::SessionFile->new($self->csv_file_name, "w"); + $file->fh->print($::form->{file}); + $file->fh->close; + } + + my $file = SL::SessionFile->new($self->csv_file_name, "w"); + if (!$file->fh) { + flash('error', $::locale->text('No file has been uploaded yet.')); + return $self->action_new; + } + # do the import thingy... $self->action_new; } @@ -186,4 +201,9 @@ sub char_map { ); } +sub csv_file_name { + my ($self) = @_; + return "csv-import-" . $self->type . ".csv"; +} + 1; diff --git a/templates/webpages/csv_import/form.html b/templates/webpages/csv_import/form.html index 32e91dbd1..56e307255 100644 --- a/templates/webpages/csv_import/form.html +++ b/templates/webpages/csv_import/form.html @@ -5,7 +5,7 @@ [%- INCLUDE 'common/flash.html' %] -
+ [% L.hidden_tag('action', 'CsvImport/dispatch') %] [% L.hidden_tag('profile.type', SELF.profile.type) %] @@ -125,6 +125,18 @@ [%- INCLUDE 'csv_import/_form_customers_vendors.html' %] [%- END %] + + [%- LxERP.t8('Import file') %]: + [% L.input_tag('file', '', type => 'file', accept => '*') %] + + + [%- IF SELF.file.exists %] + + [%- LxERP.t8('Existing file on server') %]: + [%- LxERP.t8('Uploaded on #1, size #2 kB', SELF.file.displayable_mtime, LxERP.format_amount(SELF.file.size / 1024, 2)) %] + + [%- END %] + [% L.submit_tag('action_test', LxERP.t8('Gogogo')) %] -- 2.20.1