@@ -, +, @@ - Go to Tools -> Batch patron modification. - You should see three tabs: "By card number," "By borrowernumber," and "By patron list." - Test each option for batch patron modifications: - By card number file - By card number list - By borrowernumber file - By borrowernumber list - By patron list - In each case the correct batch should be submitted, and modifications should finish correctly.. - There should be an "order of operations" for card numbers and borrowernumbers: - If a file is uploaded AND a list of numbers is entered, the list of numbers should be used. - Batches should only get submitted from the active tab. - If you upload a file or enter card numbers in one tab and then switch to another tab and submit numbers from there, the original tab's batches should be ignored. --- .../prog/en/modules/tools/modborrowers.tt | 138 ++++++++++++++++----- tools/modborrowers.pl | 59 ++++++--- 2 files changed, 143 insertions(+), 54 deletions(-) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt @@ -36,45 +36,93 @@ [% IF ( op == 'show_form' ) %]

Batch patron modification

-
-
- Use a file -
    -
  1. -
-
- - [% IF patron_lists %] -
- Or use a patron list -
    + + +
    +
    • - - + By card number
    • -
-
- [% END %] - -
- Or list cardnumbers one by one -
  1. - - + By borrowernumber
  2. -
+ [% IF patron_lists %] +
  • + By patron list +
  • + [% END %] + +
    +
    + Use a file of card numbers +
      +
    1. + +
      File must contain one card number per line.
      +
    2. +
    +
    +
    + Or list card numbers one by one +
      +
    1. + + +
    2. +
    +
    +
    + + Cancel
    - +
    +
    +
    + Use a file of borrowernumbers +
      +
    1. + +
      File must contain one borrowernumber per line.
      +
    2. +
    +
    +
    + List borrowernumbers one by one +
      +
    1. + + +
    2. +
    +
    +
    + + Cancel +
    +
    + [% IF patron_lists %] +
    +
    + Use a patron list +
      +
    1. + + +
    2. +
    +
    Cancel
    +
    + [% END %] + [% END %] @@ -82,7 +130,7 @@ [% op = 'noshow' # Change op to prevent display in code below %]

    Batch patrons modification

    -

    No patron card numbers given.

    +

    No patron card numbers or borrowernumbers given.

    @@ -96,10 +144,19 @@

    Batch patrons results

    [% END %] [% IF ( notfoundcardnumbers ) %] -

    Warning, the following cardnumbers were not found:

    + [% IF ( useborrowernumbers ) -%] +

    Warning, the following borrowernumbers were not found:

    + [% ELSE -%] +

    Warning, the following card numbers were not found:

    + [% END %] + - + [% IF ( useborrowernumbers ) -%] + + [% ELSE -%] + + [% END %] [% FOREACH notfoundcardnumber IN notfoundcardnumbers %] @@ -117,7 +174,7 @@ [% FOREACH error IN errors %] [% IF ( error.error == 'can_not_update' ) %]
  • Can not update patron. - [% IF ( error.cardnumber ) %] Cardnumber: [% error.cardnumber | html %] [% END %] + [% IF ( error.cardnumber ) %] Card number: [% error.cardnumber | html %] [% END %] (Borrowernumber: [% error.borrowernumber | html %])
  • [% ELSE %] @@ -387,6 +444,8 @@ }); return false; }); + [% ELSE %] + $("#batch_patron_options").tabs(); [% END %] var values = new Array(); @@ -421,6 +480,17 @@ e.preventDefault(); del_attributes(this); }); + $("#patron_batchmod_form").on("submit", function(){ + /* Reset form fields on inactive tabs */ + var tab = $(this).find('.ui-tabs-active:first a').attr('href'); + if ( tab == '#usecardnumber' ) { + $("#borrowernumberuploadfile, #patron_list_id, #borrowernumberlist").val(""); + } else if ( tab == '#useborrowernumber' ) { + $("#cardnumberuploadfile, #cardnumberlist, #patron_list_id").val(""); + } else { // uselist + $("#borrowernumberuploadfile, #cardnumberuploadfile, #borrowernumberlist, #cardnumberlist").val(""); + } + }); }); function updateAttrValues (select_attr) { --- a/tools/modborrowers.pl +++ a/tools/modborrowers.pl @@ -57,35 +57,53 @@ my $dbh = C4::Context->dbh; # Show borrower informations if ( $op eq 'show' ) { - my $filefh = $input->upload('uploadfile'); - my $filecontent = $input->param('filecontent'); - my $patron_list_id = $input->param('patron_list_id'); my @borrowers; - my @cardnumbers; + my @patronidnumbers; my @notfoundcardnumbers; + my $useborrowernumbers = 0; # Get cardnumbers from a file or the input area - if ($filefh) { - while ( my $content = <$filefh> ) { - $content =~ s/[\r\n]*$//g; - push @cardnumbers, $content if $content; + if( my $cardnumberlist = $input->param('cardnumberlist') ){ + # User submitted a list of card numbers + push @patronidnumbers, split( /\s\n/, $cardnumberlist ); + } elsif ( my $cardnumberuploadfile = $input->param('cardnumberuploadfile') ){ + # User uploaded a file of card numbers + binmode $cardnumberuploadfile, ':encoding(UTF-8)'; + while ( my $content = <$cardnumberuploadfile> ) { + next unless $content; + $content =~ s/[\r\n]*$//; + push @patronidnumbers, $content if $content; } - } elsif ( $patron_list_id ) { + } elsif ( my $borrowernumberlist = $input->param('borrowernumberlist') ){ + # User submitted a list of borrowernumbers + $useborrowernumbers = 1; + push @patronidnumbers, split( /\s\n/, $borrowernumberlist ); + } elsif ( my $borrowernumberuploadfile = $input->param('borrowernumberuploadfile') ){ + # User uploaded a file of borrowernumbers + $useborrowernumbers = 1; + binmode $borrowernumberuploadfile, ':encoding(UTF-8)'; + while ( my $content = <$borrowernumberuploadfile> ) { + next unless $content; + $content =~ s/[\r\n]*$//; + push @patronidnumbers, $content if $content; + } + } elsif ( my $patron_list_id = $input->param('patron_list_id') ){ + # User selected a patron list my ($list) = GetPatronLists( { patron_list_id => $patron_list_id } ); - - @cardnumbers = + @patronidnumbers = $list->patron_list_patrons()->search_related('borrowernumber') ->get_column('cardnumber')->all(); - - } else { - if ( my $list = $input->param('cardnumberlist') ) { - push @cardnumbers, split( /\s\n/, $list ); - } } my $max_nb_attr = 0; - for my $cardnumber ( @cardnumbers ) { - my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } ); + + for my $patronidnumber ( @patronidnumbers ) { + my $patron; + if( $useborrowernumbers == 1 ){ + $patron = Koha::Patrons->find( { borrowernumber => $patronidnumber } ); + } else { + $patron = Koha::Patrons->find( { cardnumber => $patronidnumber } ); + } if ( $patron ) { if ( $logged_in_user->can_see_patron_infos( $patron ) ) { my $borrower = $patron->unblessed; @@ -95,10 +113,10 @@ if ( $op eq 'show' ) { $max_nb_attr = $borrower->{patron_attributes_count} if $borrower->{patron_attributes_count} > $max_nb_attr; push @borrowers, $borrower; } else { - push @notfoundcardnumbers, $cardnumber; + push @notfoundcardnumbers, $patronidnumber; } } else { - push @notfoundcardnumbers, $cardnumber; + push @notfoundcardnumbers, $patronidnumber; } } @@ -150,6 +168,7 @@ if ( $op eq 'show' ) { @notfoundcardnumbers = map { { cardnumber => $_ } } @notfoundcardnumbers; $template->param( notfoundcardnumbers => \@notfoundcardnumbers ) if @notfoundcardnumbers; + $template->param( useborrowernumbers => $useborrowernumbers ); # Construct drop-down list values my $branches = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed; --
    Cardnumbers not found
    Borrowernumbers not found
    Card numbers not found