Lines 40-45
use Koha::Patron::Debarments qw( AddDebarment DelDebarment );
Link Here
|
40 |
use Koha::Patrons; |
40 |
use Koha::Patrons; |
41 |
use List::MoreUtils qw(uniq); |
41 |
use List::MoreUtils qw(uniq); |
42 |
use Koha::Patron::Messages; |
42 |
use Koha::Patron::Messages; |
|
|
43 |
use Try::Tiny; |
43 |
|
44 |
|
44 |
my $input = CGI->new; |
45 |
my $input = CGI->new; |
45 |
my $op = $input->param('op') || 'show_form'; |
46 |
my $op = $input->param('op') || 'show_form'; |
Lines 428-433
if ( $op eq 'cud-do' ) {
Link Here
|
428 |
$attributes->{$code}->{disabled} = grep { $_ eq sprintf( "attr%s_value", $i++ ) } @disabled; |
429 |
$attributes->{$code}->{disabled} = grep { $_ eq sprintf( "attr%s_value", $i++ ) } @disabled; |
429 |
} |
430 |
} |
430 |
|
431 |
|
|
|
432 |
my @extended_attributes = map { { code => $_->code, attribute => $_->attribute } } |
433 |
$patron->extended_attributes->filter_by_branch_limitations->as_list; |
434 |
|
431 |
for my $code ( keys %$attributes ) { |
435 |
for my $code ( keys %$attributes ) { |
432 |
my $attr_type = Koha::Patron::Attribute::Types->find($code); |
436 |
my $attr_type = Koha::Patron::Attribute::Types->find($code); |
433 |
|
437 |
|
Lines 436-460
if ( $op eq 'cud-do' ) {
Link Here
|
436 |
# If this borrower is not in the category of this attribute, we don't want to modify this attribute |
440 |
# If this borrower is not in the category of this attribute, we don't want to modify this attribute |
437 |
next if $attr_type->category_code and $attr_type->category_code ne $patron->categorycode; |
441 |
next if $attr_type->category_code and $attr_type->category_code ne $patron->categorycode; |
438 |
|
442 |
|
439 |
if ( $attributes->{$code}->{disabled} ) { |
443 |
# Remove any current values of same type |
|
|
444 |
@extended_attributes = grep { $_->{code} ne $code } @extended_attributes; |
440 |
|
445 |
|
441 |
# The attribute is disabled, we remove it for this borrower ! |
446 |
# The attribute is disabled, we remove it for this borrower ! |
442 |
eval { |
447 |
if ( !$attributes->{$code}->{disabled} ) { |
443 |
$patron->extended_attributes->search( { 'me.code' => $code } ) |
448 |
push @extended_attributes, { code => $code, attribute => $_} |
444 |
->filter_by_branch_limitations->delete; |
449 |
for @{ $attributes->{$code}->{values} }; |
445 |
}; |
|
|
446 |
push @errors, { error => $@ } if $@; |
447 |
} else { |
448 |
eval { |
449 |
$patron->extended_attributes->search( { 'me.code' => $code } ) |
450 |
->filter_by_branch_limitations->delete; |
451 |
$patron->add_extended_attribute( { code => $code, attribute => $_ } ) |
452 |
for @{ $attributes->{$code}->{values} }; |
453 |
}; |
454 |
push @errors, { error => $@ } if $@; |
455 |
} |
450 |
} |
|
|
451 |
|
456 |
} |
452 |
} |
457 |
|
453 |
|
|
|
454 |
try { |
455 |
$patron->extended_attributes(\@extended_attributes); |
456 |
} catch { |
457 |
my $message = blessed $_ ? $_->full_message() : $_; |
458 |
push @errors, { error => $message }; |
459 |
}; |
460 |
|
458 |
# Handle patron messages |
461 |
# Handle patron messages |
459 |
my $message = $input->param('message'); |
462 |
my $message = $input->param('message'); |
460 |
my $branchcode = C4::Context::mybranch; |
463 |
my $branchcode = C4::Context::mybranch; |
461 |
- |
|
|