Bug 32794: Expand tests for access method in XLST files
[srvgit] / tools / batchMod.pl
index e24db19..6c252ff 100755 (executable)
@@ -31,7 +31,6 @@ use List::MoreUtils qw( uniq );
 use Encode qw( encode_utf8 );
 
 use Koha::Database;
-use Koha::DateUtils qw( dt_from_string );
 use Koha::Exception;
 use Koha::Biblios;
 use Koha::Items;
@@ -53,6 +52,7 @@ my $del_records  = $input->param('del_records');
 my $src          = $input->param('src');
 my $use_default_values = $input->param('use_default_values');
 my $exclude_from_local_holds_priority = $input->param('exclude_from_local_holds_priority');
+my $mark_items_returned = $input->param('mark_items_returned');
 
 my $template_name;
 my $template_flag;
@@ -75,7 +75,8 @@ my ($template, $loggedinuser, $cookie)
 $template->param( searchid => scalar $input->param('searchid'), );
 
 # Does the user have a restricted item edition permission?
-my $uid = $loggedinuser ? Koha::Patrons->find( $loggedinuser )->userid : undef;
+my $patron = Koha::Patrons->find( $loggedinuser );
+my $uid = $loggedinuser ? $patron->userid : undef;
 my $restrictededition = $uid ? haspermission($uid,  {'tools' => 'items_batchmod_restricted'}) : undef;
 # In case user is a superlibrarian, edition is not restricted
 $restrictededition = 0 if ($restrictededition != 0 && C4::Context->IsSuperLibrarian());
@@ -171,6 +172,11 @@ if ( $op eq "action" ) {
               )
             ? $exclude_from_local_holds_priority
             : undef,
+            mark_items_returned => (
+                defined $mark_items_returned
+                  && $mark_items_returned ne ""
+                )
+            ? $mark_items_returned : undef,
 
         };
         try {
@@ -218,13 +224,13 @@ if ($op eq "show"){
             @contentlist = grep /\S/, ( map { split /[$split_chars]/ } @contentlist );
             @contentlist = uniq @contentlist;
             # Note: adding lc for case insensitivity
-            my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => \@contentlist }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed };
+            my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => { -in => \@contentlist } }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed };
             @itemnumbers = map { exists $itemdata{lc $_} ? $itemdata{lc $_} : () } @contentlist;
             @notfoundbarcodes = grep { !exists $itemdata{lc $_} } @contentlist;
         }
         elsif ( $filecontent eq 'itemid_file') {
             @contentlist = uniq @contentlist;
-            my %itemdata = map { $_->{itemnumber} => 1 } @{ Koha::Items->search({ itemnumber => \@contentlist }, { columns => [ 'itemnumber' ] } )->unblessed };
+            my %itemdata = map { $_->{itemnumber} => 1 } @{ Koha::Items->search({ itemnumber => { -in => \@contentlist } }, { columns => [ 'itemnumber' ] } )->unblessed };
             @itemnumbers = grep { exists $itemdata{$_} } @contentlist;
             @notfounditemnumbers = grep { !exists $itemdata{$_} } @contentlist;
         }
@@ -240,7 +246,7 @@ if ($op eq "show"){
             @barcodelist = map { barcodedecode( $_ ) } @barcodelist;
 
             # Note: adding lc for case insensitivity
-            my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => \@barcodelist }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed };
+            my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => { -in => \@barcodelist } }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed };
             @itemnumbers = map { exists $itemdata{lc $_} ? $itemdata{lc $_} : () } @barcodelist;
             @notfoundbarcodes = grep { !exists $itemdata{lc $_} } @barcodelist;
         }
@@ -266,7 +272,7 @@ if ($op eq "show"){
     # Getting list of subfields to keep when restricted batchmod edit is enabled
     my @subfields_to_allow = $restrictededition ? split ' ', C4::Context->preference('SubfieldsToAllowForRestrictedBatchmod') : ();
 
-    my $subfields = Koha::UI::Form::Builder::Item->new->edit_form(
+    my $subfields = Koha::UI::Form::Builder::Item->new->edit_form( # NOTE: We are not passing a biblionumber intentionally !
         {
             restricted_editition => $restrictededition,
             (
@@ -293,7 +299,7 @@ if ($op eq "show"){
 if ( $display_items ) {
     my $items_table =
       Koha::UI::Table::Builder::Items->new( { itemnumbers => \@itemnumbers } )
-      ->build_table;
+      ->build_table( { patron => $patron } );;
     $template->param(
         items        => $items_table->{items},
         item_header_loop => $items_table->{headers},