View | Details | Raw Unified | Return to bug 15106
Collapse All | Expand All

(-)a/C4/Members.pm (-5 / +21 lines)
Lines 656-666 sub ModMember { Link Here
656
            $data{password} = hash_password($data{password});
656
            $data{password} = hash_password($data{password});
657
        }
657
        }
658
    }
658
    }
659
    my $old_categorycode = GetBorrowerCategorycode( $data{borrowernumber} );
660
659
661
    # get only the columns of a borrower
660
    # get only the columns of a borrower
662
    my $schema = Koha::Database->new()->schema;
661
    my @columns = @{GetBorrowerColumns()};
663
    my @columns = $schema->source('Borrower')->columns;
664
    my $new_borrower = { map { join(' ', @columns) =~ /$_/ ? ( $_ => $data{$_} ) : () } keys(%data) };
662
    my $new_borrower = { map { join(' ', @columns) =~ /$_/ ? ( $_ => $data{$_} ) : () } keys(%data) };
665
    delete $new_borrower->{flags};
663
    delete $new_borrower->{flags};
666
664
Lines 668-673 sub ModMember { Link Here
668
    $new_borrower->{dateenrolled} ||= undef if exists $new_borrower->{dateenrolled};
666
    $new_borrower->{dateenrolled} ||= undef if exists $new_borrower->{dateenrolled};
669
    $new_borrower->{dateexpiry}   ||= undef if exists $new_borrower->{dateexpiry};
667
    $new_borrower->{dateexpiry}   ||= undef if exists $new_borrower->{dateexpiry};
670
    $new_borrower->{debarred}     ||= undef if exists $new_borrower->{debarred};
668
    $new_borrower->{debarred}     ||= undef if exists $new_borrower->{debarred};
669
670
    my $schema  = Koha::Database->new()->schema;
671
    my $rs = $schema->resultset('Borrower')->search({
671
    my $rs = $schema->resultset('Borrower')->search({
672
        borrowernumber => $new_borrower->{borrowernumber},
672
        borrowernumber => $new_borrower->{borrowernumber},
673
     });
673
     });
Lines 683-689 sub ModMember { Link Here
683
        }
683
        }
684
684
685
        # If the patron changes to a category with enrollment fee, we add a fee
685
        # If the patron changes to a category with enrollment fee, we add a fee
686
        if ( $data{categorycode} and $data{categorycode} ne $old_categorycode ) {
686
        if ( $data{categorycode} and $data{categorycode} ne GetBorrowerCategoryCode($data{borrowernumber}) ) {
687
            if ( C4::Context->preference('FeeOnChangePatronCategory') ) {
687
            if ( C4::Context->preference('FeeOnChangePatronCategory') ) {
688
                AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
688
                AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
689
            }
689
            }
Lines 713-718 sub ModMember { Link Here
713
    return $execute_success;
713
    return $execute_success;
714
}
714
}
715
715
716
=head2 GetBorrowerColumns
717
718
    $columns_arrayref = &GetBorrowerColumns:
719
720
Returns all borrower table columns.
721
722
=cut
723
724
sub GetBorrowerColumns {
725
    my $schema  = Koha::Database->new()->schema;
726
    my @columns = $schema->source('Borrower')->columns;
727
    return \@columns;
728
}
729
716
=head2 AddMember
730
=head2 AddMember
717
731
718
  $borrowernumber = &AddMember(%borrower);
732
  $borrowernumber = &AddMember(%borrower);
Lines 1603-1614 Given the borrowernumber, the function returns the corresponding categorycode Link Here
1603
sub GetBorrowerCategorycode {
1617
sub GetBorrowerCategorycode {
1604
    my ( $borrowernumber ) = @_;
1618
    my ( $borrowernumber ) = @_;
1605
    my $dbh = C4::Context->dbh;
1619
    my $dbh = C4::Context->dbh;
1606
    my $sth = $dbh->prepare( qq{
1620
    my $sth = $dbh->prepare_cached( qq{
1607
        SELECT categorycode
1621
        SELECT categorycode
1608
        FROM borrowers
1622
        FROM borrowers
1609
        WHERE borrowernumber = ?
1623
        WHERE borrowernumber = ?
1610
    } );
1624
    } );
1611
    $sth->execute( $borrowernumber );
1625
    $sth->execute( $borrowernumber );
1626
    my $data = $sth->fetchrow;
1627
    $sth->finish;
1612
    return $sth->fetchrow;
1628
    return $sth->fetchrow;
1613
}
1629
}
1614
1630
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt (+3 lines)
Lines 372-377 Link Here
372
                    [% END %]
372
                    [% END %]
373
                [% END %]
373
                [% END %]
374
                [% IF ( op == 'show_results' ) %]
374
                [% IF ( op == 'show_results' ) %]
375
                <div>
376
                    <p> Successfully modified [% successes %] patrons. </p>
377
                </div>
375
                <p>
378
                <p>
376
                    <a href="/cgi-bin/koha/tools/modborrowers.pl" title="New batch patrons modification">New batch patron modification</a>
379
                    <a href="/cgi-bin/koha/tools/modborrowers.pl" title="New batch patrons modification">New batch patron modification</a>
377
                </p>
380
                </p>
(-)a/tools/modborrowers.pl (-53 / +60 lines)
Lines 27-33 Link Here
27
27
28
use Modern::Perl;
28
use Modern::Perl;
29
use CGI qw ( -utf8 );
29
use CGI qw ( -utf8 );
30
use C4::Auth;
30
use C4::Auth qw ( get_template_and_user );
31
use C4::Branch;
31
use C4::Branch;
32
use C4::Koha;
32
use C4::Koha;
33
use C4::Members;
33
use C4::Members;
Lines 261-269 if ( $op eq 'do' ) { Link Here
261
        $infos->{$field} = "" if grep { /^$field$/ } @disabled;
261
        $infos->{$field} = "" if grep { /^$field$/ } @disabled;
262
    }
262
    }
263
263
264
    my @attributes = $input->param('patron_attributes');
264
    my $successes = 0;
265
    my @attr_values = $input->param('patron_attributes_value');
266
267
    my @errors;
265
    my @errors;
268
    my @borrowernumbers = $input->param('borrowernumber');
266
    my @borrowernumbers = $input->param('borrowernumber');
269
    # For each borrower selected
267
    # For each borrower selected
Lines 277-343 if ( $op eq 'do' ) { Link Here
277
                $infos->{cardnumber} = $borrowerinfo->{cardnumber} || '';
275
                $infos->{cardnumber} = $borrowerinfo->{cardnumber} || '';
278
                push @errors, { error => "can_not_update", borrowernumber => $infos->{borrowernumber}, cardnumber => $infos->{cardnumber} };
276
                push @errors, { error => "can_not_update", borrowernumber => $infos->{borrowernumber}, cardnumber => $infos->{cardnumber} };
279
            }
277
            }
278
            else {
279
                $successes++;
280
            }
280
        }
281
        }
281
282
282
        #
283
        #
283
        my $borrower_categorycode = GetBorrowerCategorycode $borrowernumber;
284
        if (@disabled) {
284
        my $i=0;
285
            my @attributes = $input->param('patron_attributes');
285
        for ( @attributes ) {
286
            my @attr_values = $input->param('patron_attributes_value');
286
            my $attribute;
287
            my $borrower_categorycode = GetBorrowerCategorycode $borrowernumber;
287
            $attribute->{code} = $_;
288
            my $i=0;
288
            $attribute->{attribute} = $attr_values[$i];
289
            for ( @attributes ) {
289
            my $attr_type = C4::Members::AttributeTypes->fetch( $_ );
290
                my $attribute;
290
            # If this borrower is not in the category of this attribute, we don't want to modify this attribute
291
                $attribute->{code} = $_;
291
            ++$i and next if $attr_type->{category_code} and $attr_type->{category_code} ne $borrower_categorycode;
292
                $attribute->{attribute} = $attr_values[$i];
292
            my $valuename = "attr" . $i . "_value";
293
                my $attr_type = C4::Members::AttributeTypes->fetch( $_ );
293
            if ( grep { /^$valuename$/ } @disabled ) {
294
                # If this borrower is not in the category of this attribute, we don't want to modify this attribute
294
                # The attribute is disabled, we remove it for this borrower !
295
                ++$i and next if $attr_type->{category_code} and $attr_type->{category_code} ne $borrower_categorycode;
295
                eval {
296
                my $valuename = "attr" . $i . "_value";
296
                    C4::Members::Attributes::DeleteBorrowerAttribute( $borrowernumber, $attribute );
297
                if ( grep { /^$valuename$/ } @disabled ) {
297
                };
298
                    # The attribute is disabled, we remove it for this borrower !
298
                push @errors, { error => $@ } if $@;
299
                    eval {
299
            } else {
300
                        C4::Members::Attributes::DeleteBorrowerAttribute( $borrowernumber, $attribute );
300
                # Attribute's value is empty, we don't want to modify it
301
                    };
301
                ++$i and next if not $attribute->{attribute};
302
                    push @errors, { error => $@ } if $@;
302
303
                } else {
303
                eval {
304
                    # Attribute's value is empty, we don't want to modify it
304
                    C4::Members::Attributes::UpdateBorrowerAttribute( $borrowernumber, $attribute );
305
                    ++$i and next if not $attribute->{attribute};
305
                };
306
306
                push @errors, { error => $@ } if $@;
307
                    eval {
308
                        C4::Members::Attributes::UpdateBorrowerAttribute( $borrowernumber, $attribute );
309
                    };
310
                    push @errors, { error => $@ } if $@;
311
                }
312
                $i++;
307
            }
313
            }
308
            $i++;
309
        }
314
        }
310
    }
315
    }
311
    $op = "show_results"; # We have process modifications, the user want to view its
316
    $op = "show_results"; # We have process modifications, the user want to view its
312
317
313
    # Construct the results list
318
    # Construct a detailed list if there are fewer than 20 patrons
314
    my @borrowers;
319
    if (scalar @borrowernumbers < 20) {
315
    my $max_nb_attr = 0;
320
        my @borrowers;
316
    for my $borrowernumber ( @borrowernumbers ) {
321
        my $max_nb_attr = 0;
317
        my $borrower = GetBorrowerInfos( borrowernumber => $borrowernumber );
322
        for my $borrowernumber ( @borrowernumbers ) {
318
        if ( $borrower ) {
323
            my $borrower = GetBorrowerInfos( borrowernumber => $borrowernumber );
319
            $max_nb_attr = scalar( @{ $borrower->{patron_attributes} } )
324
            if ( $borrower ) {
320
                if scalar( @{ $borrower->{patron_attributes} } ) > $max_nb_attr;
325
                $max_nb_attr = scalar( @{ $borrower->{patron_attributes} } )
321
            push @borrowers, $borrower;
326
                    if scalar( @{ $borrower->{patron_attributes} } ) > $max_nb_attr;
327
                push @borrowers, $borrower;
328
            }
329
        }
330
        my @patron_attributes_option;
331
        for my $borrower ( @borrowers ) {
332
            push @patron_attributes_option, { value => "$_->{code}", lib => $_->{code} } for @{ $borrower->{patron_attributes} };
333
            my $length = scalar( @{ $borrower->{patron_attributes} } );
334
            push @{ $borrower->{patron_attributes} }, {} for ( $length .. $max_nb_attr - 1);
322
        }
335
        }
323
    }
324
    my @patron_attributes_option;
325
    for my $borrower ( @borrowers ) {
326
        push @patron_attributes_option, { value => "$_->{code}", lib => $_->{code} } for @{ $borrower->{patron_attributes} };
327
        my $length = scalar( @{ $borrower->{patron_attributes} } );
328
        push @{ $borrower->{patron_attributes} }, {} for ( $length .. $max_nb_attr - 1);
329
    }
330
336
331
    my @attributes_header = ();
337
        my @attributes_header = ();
332
    for ( 1 .. scalar( $max_nb_attr ) ) {
338
        for ( 1 .. scalar( $max_nb_attr ) ) {
333
        push @attributes_header, { attribute => "Attributes $_" };
339
            push @attributes_header, { attribute => "Attributes $_" };
334
    }
340
        }
335
341
336
    $template->param( borrowers => \@borrowers );
342
        $template->param( borrowers => \@borrowers );
337
    $template->param( attributes_header => \@attributes_header );
343
        $template->param( attributes_header => \@attributes_header );
344
    }
338
345
339
    $template->param( borrowers => \@borrowers );
346
    $template->param( successes => $successes );
340
    $template->param( errors => \@errors );
347
    $template->param( errors => \@errors );
348
341
} else {
349
} else {
342
350
343
    $template->param( patron_lists => [ GetPatronLists() ] );
351
    $template->param( patron_lists => [ GetPatronLists() ] );
344
- 

Return to bug 15106