ffzg/recall_notices.pl: added --interval and --dedup
[koha.git] / tools / batch_record_modification.pl
index 89527fb..1a82c47 100755 (executable)
@@ -32,6 +32,7 @@ use C4::MarcModificationTemplates qw( GetModificationTemplateActions GetModifica
 
 use Koha::Biblios;
 use Koha::MetadataRecord::Authority;
+use Koha::Virtualshelves;
 
 my $input = new CGI;
 our $dbh = C4::Context->dbh;
@@ -68,6 +69,8 @@ if ( $completedJobID ) {
     exit;
 }
 
+$template->param( lists => scalar Koha::Virtualshelves->search([{ category => 1, owner => $loggedinuser }, { category => 2 }]) );
+
 my @templates = GetModificationTemplates( $mmtid );
 unless ( @templates ) {
     $op = 'error';
@@ -105,11 +108,19 @@ if ( $op eq 'form' ) {
         $recordtype = 'biblio';
     } elsif ( my $uploadfile = $input->param('uploadfile') ) {
         # A file of id is given
+        binmode $uploadfile, ':encoding(UTF-8)';
         while ( my $content = <$uploadfile> ) {
             next unless $content;
             $content =~ s/[\r\n]*$//;
             push @record_ids, $content if $content;
         }
+    } elsif ( my $shelf_number = $input->param('shelf_number') ) {
+        my $shelf = Koha::Virtualshelves->find($shelf_number);
+        my $contents = $shelf->get_contents;
+        while ( my $content = $contents->next ) {
+            my $biblionumber = $content->biblionumber;
+            push @record_ids, $biblionumber;
+        }
     } else {
         # The user enters manually the list of id
         push @record_ids, split( /\s\n/, $input->param('recordnumber_list') );
@@ -191,7 +202,7 @@ if ( $op eq 'form' ) {
 
             # Finally, modify the biblio
             my $error = eval {
-                my $record = GetMarcBiblio( $biblionumber );
+                my $record = GetMarcBiblio({ biblionumber => $biblionumber });
                 ModifyRecordWithTemplate( $mmtid, $record );
                 my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblionumber );
                 ModBiblio( $record, $biblionumber, $frameworkcode );