Bug 30952: Show the search catalog form by default in cat-search.inc
[koha-ffzg.git] / tools / batch_record_modification.pl
index d65883a..1cbda22 100755 (executable)
@@ -22,14 +22,15 @@ use Modern::Perl;
 
 use CGI;
 use List::MoreUtils qw( uniq );
-use JSON qw( encode_json );
-use Try::Tiny;
+use Try::Tiny qw( catch try );
 
 use C4::Auth qw( get_template_and_user );
 use C4::Output qw( output_html_with_http_headers );
-use C4::AuthoritiesMarc qw( BuildSummary ModAuthority );
-use C4::Biblio qw( GetMarcBiblio ModBiblio );
-use C4::MarcModificationTemplates qw( GetModificationTemplateActions GetModificationTemplates );
+use C4::Auth qw( get_template_and_user );
+use C4::MarcModificationTemplates qw(
+    GetModificationTemplateActions
+    GetModificationTemplates
+);
 
 use Koha::Biblios;
 use Koha::BackgroundJob::BatchUpdateBiblio;
@@ -37,7 +38,7 @@ use Koha::BackgroundJob::BatchUpdateAuthority;
 use Koha::MetadataRecord::Authority;
 use Koha::Virtualshelves;
 
-my $input = new CGI;
+my $input = CGI->new;
 our $dbh = C4::Context->dbh;
 my $op = $input->param('op') // q|form|;
 my $recordtype = $input->param('recordtype') // 'biblio';
@@ -81,6 +82,12 @@ if ( $op eq 'form' ) {
     # Display the form
     $template->param(
         view => 'form',
+        lists => Koha::Virtualshelves->search(
+            [
+                { public => 0, owner => $loggedinuser },
+                { public => 1 }
+            ]
+        )
     );
 } elsif ( $op eq 'list' ) {
     # List all records to process
@@ -106,7 +113,7 @@ if ( $op eq 'form' ) {
         }
     } else {
         # The user enters manually the list of id
-        push @record_ids, split( /\s\n/, $input->param('recordnumber_list') );
+        push @record_ids, split( /\s\n/, scalar $input->param('recordnumber_list') );
     }
 
     for my $record_id ( uniq @record_ids ) {
@@ -150,9 +157,15 @@ if ( $op eq 'form' ) {
     my @record_ids = $input->multi_param('record_id');
 
     try {
+        my $patron = Koha::Patrons->find( $loggedinuser );
         my $params = {
-            mmtid       => $mmtid,
-            record_ids  => \@record_ids,
+            mmtid           => $mmtid,
+            record_ids      => \@record_ids,
+            overlay_context => {
+                source       => 'batchmod',
+                categorycode => $patron->categorycode,
+                userid       => $patron->userid
+            }
         };
 
         my $job_id =