Revision 29269e99
Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt
SL/Controller/CsvImport.pm | ||
---|---|---|
5 | 5 |
use SL::DB::Buchungsgruppe; |
6 | 6 |
use SL::DB::CsvImportProfile; |
7 | 7 |
use SL::Helper::Flash; |
8 |
use SL::SessionFile; |
|
8 | 9 |
|
9 | 10 |
use List::MoreUtils qw(none); |
10 | 11 |
|
... | ... | |
12 | 13 |
|
13 | 14 |
use Rose::Object::MakeMethods::Generic |
14 | 15 |
( |
15 |
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) ], |
|
16 |
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) ],
|
|
16 | 17 |
); |
17 | 18 |
|
18 | 19 |
__PACKAGE__->run_before('check_auth'); |
... | ... | |
108 | 109 |
$self->$sub(($char_map{$type}->{$char} || [])->[0] || $char); |
109 | 110 |
} |
110 | 111 |
|
112 |
$self->file(SL::SessionFile->new($self->csv_file_name)); |
|
113 |
|
|
111 | 114 |
my $title = $self->type eq 'customers_vendors' ? $::locale->text('CSV import: customers and vendors') |
112 | 115 |
: $self->type eq 'addresses' ? $::locale->text('CSV import: shipping addresses') |
113 | 116 |
: $self->type eq 'contacts' ? $::locale->text('CSV import: contacts') |
... | ... | |
124 | 127 |
|
125 | 128 |
$self->profile_from_form; |
126 | 129 |
|
130 |
if ($::form->{file}) { |
|
131 |
my $file = SL::SessionFile->new($self->csv_file_name, "w"); |
|
132 |
$file->fh->print($::form->{file}); |
|
133 |
$file->fh->close; |
|
134 |
} |
|
135 |
|
|
136 |
my $file = SL::SessionFile->new($self->csv_file_name, "w"); |
|
137 |
if (!$file->fh) { |
|
138 |
flash('error', $::locale->text('No file has been uploaded yet.')); |
|
139 |
return $self->action_new; |
|
140 |
} |
|
141 |
|
|
127 | 142 |
# do the import thingy... |
128 | 143 |
$self->action_new; |
129 | 144 |
} |
... | ... | |
186 | 201 |
); |
187 | 202 |
} |
188 | 203 |
|
204 |
sub csv_file_name { |
|
205 |
my ($self) = @_; |
|
206 |
return "csv-import-" . $self->type . ".csv"; |
|
207 |
} |
|
208 |
|
|
189 | 209 |
1; |
templates/webpages/csv_import/form.html | ||
---|---|---|
5 | 5 |
|
6 | 6 |
[%- INCLUDE 'common/flash.html' %] |
7 | 7 |
|
8 |
<form method="post" action="controller.pl"> |
|
8 |
<form method="post" action="controller.pl" enctype="multipart/form-data">
|
|
9 | 9 |
[% L.hidden_tag('action', 'CsvImport/dispatch') %] |
10 | 10 |
[% L.hidden_tag('profile.type', SELF.profile.type) %] |
11 | 11 |
|
... | ... | |
125 | 125 |
[%- INCLUDE 'csv_import/_form_customers_vendors.html' %] |
126 | 126 |
[%- END %] |
127 | 127 |
|
128 |
<tr> |
|
129 |
<th align="right">[%- LxERP.t8('Import file') %]:</th> |
|
130 |
<td colspan="10">[% L.input_tag('file', '', type => 'file', accept => '*') %]</td> |
|
131 |
</tr> |
|
132 |
|
|
133 |
[%- IF SELF.file.exists %] |
|
134 |
<tr> |
|
135 |
<th align="right">[%- LxERP.t8('Existing file on server') %]:</th> |
|
136 |
<td colspan="10">[%- LxERP.t8('Uploaded on #1, size #2 kB', SELF.file.displayable_mtime, LxERP.format_amount(SELF.file.size / 1024, 2)) %]</td> |
|
137 |
</tr> |
|
138 |
[%- END %] |
|
139 |
|
|
128 | 140 |
</table> |
129 | 141 |
|
130 | 142 |
[% L.submit_tag('action_test', LxERP.t8('Gogogo')) %] |
Auch abrufbar als: Unified diff
Hochladen und Anzeigen von hochgeladenen Dateien implementiert