Bug 28524: Escape 'rank' in cat_issues_top.pl
[srvgit] / tools / export.pl
index 0165cf1..588f1b9 100755 (executable)
@@ -32,14 +32,19 @@ use Koha::Exporter::Record;
 use Koha::ItemTypes;
 use Koha::Libraries;
 
-my $query = new CGI;
+my $query = CGI->new;
 
 my $dont_export_items = $query->param("dont_export_item") || 0;
 my $record_type       = $query->param("record_type");
 my $op                = $query->param("op") || '';
 my $output_format     = $query->param("format") || $query->param("output_format") || 'iso2709';
 my $backupdir         = C4::Context->config('backupdir');
-my $filename          = $query->param("filename") || ( $output_format eq 'csv' ? 'koha.csv' : 'koha.mrc' );
+my $filename;
+if ( $record_type eq 'auths' ) {
+    $filename = $query->param("filename_auth") || ( $output_format eq 'xml' ? 'koha.xml' : 'koha.mrc' );
+} else {
+    $filename = $query->param("filename") || ( $output_format eq 'csv' ? 'koha.csv' : 'koha.mrc' );
+}
 $filename =~ s/(\r|\n)//;
 
 my $dbh = C4::Context->dbh;
@@ -61,9 +66,7 @@ my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
         template_name   => "tools/export.tt",
         query           => $query,
         type            => "intranet",
-        authnotrequired => 0,
         flagsrequired   => { tools => 'export_catalog' },
-        debug           => 1,
     }
 );
 
@@ -74,8 +77,8 @@ if ( $op eq 'export' ) {
     my $filename = $query->param('id_list_file');
     if ( $filename ) {
         my $mimetype = $query->uploadInfo($filename)->{'Content-Type'};
-        my @valid_mimetypes = qw( application/octet-stream text/csv text/plain );
-        unless ( grep { /^$mimetype$/ } @valid_mimetypes ) {
+        my @valid_mimetypes = qw( application/octet-stream text/csv text/plain application/vnd.ms-excel );
+        unless ( grep { $_ eq $mimetype } @valid_mimetypes ) {
             push @messages, { type => 'alert', code => 'invalid_mimetype' };
             $op = '';
         }
@@ -87,13 +90,10 @@ if ( $op eq "export" ) {
     my $export_remove_fields = $query->param("export_remove_fields") || q||;
     my @biblionumbers      = $query->multi_param("biblionumbers");
     my @itemnumbers        = $query->multi_param("itemnumbers");
-    my $strip_nonlocal_items =  $query->param('strip_nonlocal_items');
-    my @sql_params;
-    my $sql_query;
+    my $strip_items_not_from_libraries =  $query->param('strip_items_not_from_libraries');
 
-    my $libraries = $strip_nonlocal_items
-        ? [ Koha::Libraries->find(C4::Context->userenv->{branch})->unblessed ]
-        : Koha::Libraries->search_filtered->unblessed;
+    my $libraries = Koha::Libraries->search_filtered->unblessed;
+    my $only_export_items_for_branches = $strip_items_not_from_libraries ? \@branch : undef;
     my @branchcodes;
     for my $branchcode ( @branch ) {
         if ( grep { $_->{branchcode} eq $branchcode } @$libraries ) {
@@ -209,6 +209,7 @@ if ( $op eq "export" ) {
                 dont_export_fields => $export_remove_fields,
                 csv_profile_id     => $csv_profile_id,
                 export_items       => (not $dont_export_items),
+                only_export_items_for_branches => $only_export_items_for_branches,
             }
         );
     }
@@ -300,7 +301,7 @@ else {
         itemtypes                => $itemtypes,
         authority_types          => $authority_types,
         export_remove_fields     => C4::Context->preference("ExportRemoveFields"),
-        csv_profiles             => [ Koha::CsvProfiles->search({ type => 'marc' }) ],
+        csv_profiles             => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ],
         messages                 => \@messages,
     );