|
Lines 333-345
if ( $op eq 'cud-create' ) {
Link Here
|
| 333 |
|
333 |
|
| 334 |
$template->param( op => 'edit' ); |
334 |
$template->param( op => 'edit' ); |
| 335 |
} else { |
335 |
} else { |
|
|
336 |
my $patron = Koha::Patrons->find($borrowernumber); |
| 336 |
|
337 |
|
| 337 |
# If preferred name is not included but firstname is then set preferred_name to firstname |
338 |
# If preferred name is not included but firstname is then set preferred_name to firstname |
| 338 |
$borrower{preferred_name} = $borrower{firstname} |
339 |
$borrower{preferred_name} = $borrower{firstname} |
| 339 |
if defined $borrower{firstname} && !defined $borrower{preferred_name}; |
340 |
if defined $borrower{firstname} && !defined $borrower{preferred_name}; |
| 340 |
my %borrower_changes = DelUnchangedFields( $borrowernumber, %borrower ); |
341 |
my %borrower_changes = DelUnchangedFields( $borrowernumber, %borrower ); |
| 341 |
$borrower_changes{'changed_fields'} = join ',', keys %borrower_changes; |
342 |
$borrower_changes{'changed_fields'} = join ',', keys %borrower_changes; |
| 342 |
my $extended_attributes_changes = FilterUnchangedAttributes( $borrowernumber, $attributes ); |
343 |
my $extended_attributes_changes = $patron->identify_updated_extended_attributes($attributes); |
| 343 |
|
344 |
|
| 344 |
if ( $borrower_changes{'changed_fields'} || scalar @{$extended_attributes_changes} > 0 ) { |
345 |
if ( $borrower_changes{'changed_fields'} || scalar @{$extended_attributes_changes} > 0 ) { |
| 345 |
( $template, $borrowernumber, $cookie ) = get_template_and_user( |
346 |
( $template, $borrowernumber, $cookie ) = get_template_and_user( |
|
Lines 354-360
if ( $op eq 'cud-create' ) {
Link Here
|
| 354 |
$borrower_changes{borrowernumber} = $borrowernumber; |
355 |
$borrower_changes{borrowernumber} = $borrowernumber; |
| 355 |
$borrower_changes{extended_attributes} = to_json($extended_attributes_changes); |
356 |
$borrower_changes{extended_attributes} = to_json($extended_attributes_changes); |
| 356 |
|
357 |
|
| 357 |
my $patron = Koha::Patrons->find($borrowernumber); |
|
|
| 358 |
$patron->request_modification( \%borrower_changes ); |
358 |
$patron->request_modification( \%borrower_changes ); |
| 359 |
$template->param( borrower => $patron->unblessed ); |
359 |
$template->param( borrower => $patron->unblessed ); |
| 360 |
} else { |
360 |
} else { |
|
Lines 628-694
sub DelEmptyFields {
Link Here
|
| 628 |
return %borrower; |
628 |
return %borrower; |
| 629 |
} |
629 |
} |
| 630 |
|
630 |
|
| 631 |
sub FilterUnchangedAttributes { |
|
|
| 632 |
my ( $borrowernumber, $entered_attributes ) = @_; |
| 633 |
|
| 634 |
my @patron_attributes = grep { $_->type->opac_editable ? $_ : () } |
| 635 |
Koha::Patron::Attributes->search( { borrowernumber => $borrowernumber } )->as_list; |
| 636 |
|
| 637 |
my $patron_attribute_types; |
| 638 |
foreach my $attr (@patron_attributes) { |
| 639 |
$patron_attribute_types->{ $attr->code } += 1; |
| 640 |
} |
| 641 |
|
| 642 |
my $passed_attribute_types; |
| 643 |
foreach my $attr ( @{$entered_attributes} ) { |
| 644 |
$passed_attribute_types->{ $attr->{code} } += 1; |
| 645 |
} |
| 646 |
|
| 647 |
my @changed_attributes; |
| 648 |
|
| 649 |
# Loop through the current patron attributes |
| 650 |
foreach my $attribute_type ( keys %{$patron_attribute_types} ) { |
| 651 |
if ( ( $patron_attribute_types->{$attribute_type} // q{} ) ne |
| 652 |
( $passed_attribute_types->{$attribute_type} // q{} ) ) |
| 653 |
{ |
| 654 |
# count differs, overwrite all attributes for given type |
| 655 |
foreach my $attr ( @{$entered_attributes} ) { |
| 656 |
push @changed_attributes, $attr |
| 657 |
if $attr->{code} eq $attribute_type; |
| 658 |
} |
| 659 |
} else { |
| 660 |
|
| 661 |
# count matches, check values |
| 662 |
my $changes = 0; |
| 663 |
foreach my $attr ( grep { $_->code eq $attribute_type } @patron_attributes ) { |
| 664 |
$changes = 1 |
| 665 |
unless any { $_->{value} eq $attr->attribute } @{$entered_attributes}; |
| 666 |
last if $changes; |
| 667 |
} |
| 668 |
|
| 669 |
if ($changes) { |
| 670 |
foreach my $attr ( @{$entered_attributes} ) { |
| 671 |
push @changed_attributes, $attr |
| 672 |
if $attr->{code} eq $attribute_type; |
| 673 |
} |
| 674 |
} |
| 675 |
} |
| 676 |
} |
| 677 |
|
| 678 |
# Loop through passed attributes, looking for new ones |
| 679 |
foreach my $attribute_type ( keys %{$passed_attribute_types} ) { |
| 680 |
if ( !defined $patron_attribute_types->{$attribute_type} ) { |
| 681 |
|
| 682 |
# YAY, new stuff |
| 683 |
foreach my $attr ( grep { $_->{code} eq $attribute_type } @{$entered_attributes} ) { |
| 684 |
push @changed_attributes, $attr; |
| 685 |
} |
| 686 |
} |
| 687 |
} |
| 688 |
|
| 689 |
return \@changed_attributes; |
| 690 |
} |
| 691 |
|
| 692 |
sub GeneratePatronAttributesForm { |
631 |
sub GeneratePatronAttributesForm { |
| 693 |
my ( $borrowernumber, $entered_attributes ) = @_; |
632 |
my ( $borrowernumber, $entered_attributes ) = @_; |
| 694 |
|
633 |
|