From b47452c08cf46133bf96ac6fd10dd8e208b57f49 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Mon, 19 Aug 2019 19:24:16 +1200 Subject: [PATCH] Bug 23291: Retrieve all patrons with given SMS number, and change inputs This patch now handles situations where more than one patron has a given SMS number. The inputs are now more concise as radio buttons are now present for users to indicate whether the file they are uploading or the list of numbers they are entering are cardnumbers or SMS numbers. Test plan same as first patch, although take into account slight changes to inputs. Also test an SMS number that more than one patron has and check that all patrons with that number are displayed. Sponsored-by: Brimbank Library, Australia Authored-by: Alex Buckley and Hayley Mapley (Catalyst IT) Signed-off-by: George Williams --- .../prog/en/modules/tools/modborrowers.tt | 30 +++------- tools/modborrowers.pl | 67 ++++++++++++---------- 2 files changed, 47 insertions(+), 50 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt index affdae92480..2aedf378eea 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt @@ -29,16 +29,11 @@

Batch patron modification

- Use a file of cardnumbers + Use a file of cardnumbers or SMS numbers
    -
  1. -
-
- -
- Use a file of SMS numbers -
    -
  1. +
  2. +
  3. +
@@ -60,21 +55,14 @@ [% END %]
- Or list cardnumbers one by one + Or list cardnumbers or SMS numbers one by one
    -
  1. - - -
  2. -
-
+
  • +
  • -
    - Or list SMS numbers one by one -
    1. - - + +
    diff --git a/tools/modborrowers.pl b/tools/modborrowers.pl index 4c280b86f03..9ab9ce5a717 100755 --- a/tools/modborrowers.pl +++ b/tools/modborrowers.pl @@ -57,25 +57,27 @@ my $dbh = C4::Context->dbh; # Show borrower informations if ( $op eq 'show' ) { - my $cardnumberfilefh = $input->upload('uploadcardnumberfile'); - my $smsnumberfilefh = $input->upload('uploadsmsnumberfile'); - my $filecontent = $input->param('filecontent'); + my $filefh = $input->upload('uploadfile'); + my $filecontent = $input->param('fileoption'); my $patron_list_id = $input->param('patron_list_id'); + my $manual_list_option = $input->param('manual_list_option'); my @borrowers; my @cardnumbers; my @smsnumbers; my ( @notfoundcardnumbers, @notfoundsmsnumbers ); - # Get cardnumbers from a file or the input area - if ( $cardnumberfilefh ) { - while ( my $content = <$cardnumberfilefh> ) { - $content =~ s/[\r\n]*$//g; - push @cardnumbers, $content if $content; - } - } elsif ( $smsnumberfilefh ) { - while ( my $content = <$smsnumberfilefh> ) { - $content =~ s/[\r\n]*$//g; - push @smsnumbers, $content if $content; + # Get cardnumbers or SMS numbers from a file, a list, or the input area + if ($filefh) { + if ($filecontent eq 'cardnumber') { # If cardnumber radio button selected, then push file content to @cardnumbers + while ( my $content = <$filefh> ) { + $content =~ s/[\r\n]*$//g; + push @cardnumbers, $content if $content; + } + } elsif ($filecontent eq 'sms') { # If SMS radio button selected, then push file content to @smsnumbers + while ( my $content = <$filefh> ) { + $content =~ s/[\r\n]*$//g; + push @smsnumbers, $content if $content; + } } } elsif ( $patron_list_id ) { my ($list) = GetPatronLists( { patron_list_id => $patron_list_id } ); @@ -86,11 +88,16 @@ if ( $op eq 'show' ) { @smsnumbers = $list->patron_list_patrons()->search_related('borrowernumber') ->get_column('smsalertnumber')->all(); - } else { - if ( my $cardnumberlist = $input->param('cardnumberlist') ) { - push @cardnumbers, split( /\s\n/, $cardnumberlist ); - } elsif ( my $smsnumberlist = $input->param('smsnumberlist') ) { - push @smsnumbers, split( /\s\n/, $smsnumberlist ); + } else { # If numbers are in the textarea, check the radio button and push into appropriate array + + my $list = $input->param('list'); + + if ( $manual_list_option eq 'cardnumber' ) { # If cardnumber radio button selected then push textarea content to @cardnumbers + push @cardnumbers, split( /\s\n/, $list ); + + } elsif ( $manual_list_option eq 'sms' ) { # If sms number radio button selected then push textarea content to @smsnumbers + push @smsnumbers, split( /\s\n/, $list ); + } } @@ -113,20 +120,22 @@ if ( $op eq 'show' ) { } } else { for my $smsnumber (@smsnumbers ) { - my $patron = Koha::Patrons->find( { smsalertnumber => $smsnumber } ); - if ( $patron ) { - if ( $logged_in_user->can_see_patron_infos( $patron ) ) { - my $borrower = $patron->unblessed; - my $attributes = $patron->extended_attributes; - $borrower->{patron_attributes} = $attributes->as_list; - $borrower->{patron_attributes_count} = $attributes->count; - $max_nb_attr = $borrower->{patron_attributes_count} if $borrower->{patron_attributes_count} > $max_nb_attr; - push @borrowers, $patron; + my @patrons = Koha::Patrons->search( { smsalertnumber => $smsnumber } ); + foreach my $patron (@patrons) { + if ( $patron ) { + if ( $logged_in_user->can_see_patron_infos( $patron ) ) { + my $borrower = $patron->unblessed; + my $attributes = $patron->extended_attributes; + $borrower->{patron_attributes} = $attributes->as_list; + $borrower->{patron_attributes_count} = $attributes->count; + $max_nb_attr = $borrower->{patron_attributes_count} if $borrower->{patron_attributes_count} > $max_nb_attr; + push @borrowers, $patron; + } else { + push @notfoundsmsnumbers, $smsnumber; + } } else { push @notfoundsmsnumbers, $smsnumber; } - } else { - push @notfoundsmsnumbers, $smsnumber; } } } -- 2.11.0