From 0b285d9b1ba3c165711692d5743237250e3dd1ca Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 14 Feb 2017 10:52:14 +0100 Subject: [PATCH] Bug 18087: Handle invalid filetypes If an invalid file is used as biblionumber list, we should display a message. Test plan: 1/ Use csv, plain text files => Should work 2/ Use invalid files (binary files like pdf, doc*, xsl*, etc.) => Should not work and see a warning message. --- koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt | 9 +++++++++ tools/export.pl | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt index 470c588..cfa252c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt @@ -47,6 +47,15 @@ $(document).ready(function() {
+[% FOR m IN messages %] +
+ [% SWITCH m.code %] + [% CASE 'invalid_mimetype' %]The file used does not have a valid format. Only csv and txt are allowed. + [% CASE %][% m.code %] + [% END %] +
+[% END %] +
  • Export bibliographic records
  • diff --git a/tools/export.pl b/tools/export.pl index b1ce09c..411a84d 100755 --- a/tools/export.pl +++ b/tools/export.pl @@ -69,6 +69,18 @@ my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( my @branch = $query->multi_param("branch"); +my @messages; +if ( $op eq 'export' ) { + my $filename = $query->param('id_list_file'); + my $mimetype = $query->uploadInfo($filename)->{'Content-Type'}; + my @valid_mimetypes = qw( application/octet-stream text/csv text/plain ); + warn $mimetype; + unless ( grep { /^$mimetype$/ } @valid_mimetypes ) { + push @messages, { type => 'alert', code => 'invalid_mimetype' }; + $op = ''; + } +} + if ( $op eq "export" ) { my $export_remove_fields = $query->param("export_remove_fields") || q||; @@ -302,6 +314,7 @@ else { authority_types => $authority_types, export_remove_fields => C4::Context->preference("ExportRemoveFields"), csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ], + messages => \@messages, ); output_html_with_http_headers $query, $cookie, $template->output; -- 2.9.3