|
Lines 29-42
use C4::Output;
Link Here
|
| 29 |
use C4::Members; |
29 |
use C4::Members; |
| 30 |
use C4::Members::Attributes qw( GetBorrowerAttributes ); |
30 |
use C4::Members::Attributes qw( GetBorrowerAttributes ); |
| 31 |
use C4::Form::MessagingPreferences; |
31 |
use C4::Form::MessagingPreferences; |
| 32 |
use Koha::Patrons; |
|
|
| 33 |
use Koha::Patron::Modification; |
| 34 |
use Koha::Patron::Modifications; |
| 35 |
use C4::Scrubber; |
32 |
use C4::Scrubber; |
| 36 |
use Email::Valid; |
33 |
use Email::Valid; |
| 37 |
use Koha::DateUtils; |
34 |
use Koha::DateUtils; |
| 38 |
use Koha::Libraries; |
35 |
use Koha::Libraries; |
|
|
36 |
use Koha::Patron::Attribute::Types; |
| 37 |
use Koha::Patron::Attributes; |
| 39 |
use Koha::Patron::Images; |
38 |
use Koha::Patron::Images; |
|
|
39 |
use Koha::Patron::Modification; |
| 40 |
use Koha::Patron::Modifications; |
| 41 |
use Koha::Patrons; |
| 40 |
use Koha::Token; |
42 |
use Koha::Token; |
| 41 |
|
43 |
|
| 42 |
my $cgi = new CGI; |
44 |
my $cgi = new CGI; |
|
Lines 246-252
elsif ( $action eq 'update' ) {
Link Here
|
| 246 |
secret => md5_base64( Encode::encode( 'UTF-8', C4::Context->config('pass') ) ), |
248 |
secret => md5_base64( Encode::encode( 'UTF-8', C4::Context->config('pass') ) ), |
| 247 |
}), |
249 |
}), |
| 248 |
); |
250 |
); |
| 249 |
$template->param( patron_attribute_classes => GeneratePatronAttributesForm( undef, $attributes ) ); |
251 |
$template->param( patron_attribute_classes => GeneratePatronAttributesForm( $borrowernumber, $attributes ) ); |
| 250 |
|
252 |
|
| 251 |
$template->param( action => 'edit' ); |
253 |
$template->param( action => 'edit' ); |
| 252 |
} |
254 |
} |
|
Lines 477-483
sub ExtendedAttributesMatch {
Link Here
|
| 477 |
|
479 |
|
| 478 |
my @patron_attributes_arr = GetBorrowerAttributes( $borrowernumber, 1 ); |
480 |
my @patron_attributes_arr = GetBorrowerAttributes( $borrowernumber, 1 ); |
| 479 |
my $patron_attributes = $patron_attributes_arr[0]; |
481 |
my $patron_attributes = $patron_attributes_arr[0]; |
| 480 |
|
|
|
| 481 |
if ( scalar @{$entered_attributes} != scalar @{$patron_attributes} ) { |
482 |
if ( scalar @{$entered_attributes} != scalar @{$patron_attributes} ) { |
| 482 |
return 1; |
483 |
return 1; |
| 483 |
} |
484 |
} |
|
Lines 493-543
sub ExtendedAttributesMatch {
Link Here
|
| 493 |
return 0; |
494 |
return 0; |
| 494 |
} |
495 |
} |
| 495 |
|
496 |
|
| 496 |
|
|
|
| 497 |
sub GeneratePatronAttributesForm { |
497 |
sub GeneratePatronAttributesForm { |
| 498 |
my ( $borrowernumber, $entered_attributes ) = @_; |
498 |
my ( $borrowernumber, $entered_attributes ) = @_; |
| 499 |
|
499 |
|
| 500 |
# Get all attribute types and the values for this patron (if applicable) |
500 |
# Get all attribute types and the values for this patron (if applicable) |
| 501 |
my @types = C4::Members::AttributeTypes::GetAttributeTypes(); |
501 |
my @types = grep { $_->opac_editable() or $_->opac_display } |
| 502 |
|
502 |
Koha::Patron::Attribute::Types->search()->as_list(); |
| 503 |
if (scalar(@types) == 0) { |
503 |
if ( scalar(@types) == 0 ) { |
| 504 |
return []; |
504 |
return []; |
| 505 |
} |
505 |
} |
| 506 |
|
506 |
|
| 507 |
my %attr_values = (); |
507 |
my @displayable_attributes = grep { $_->opac_display } |
|
|
508 |
Koha::Patron::Attributes->search( { borrowernumber => $borrowernumber } )->as_list; |
| 508 |
|
509 |
|
| 509 |
if ( $borrowernumber ) { |
510 |
my %attr_values = (); |
| 510 |
my $attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
|
|
| 511 |
|
511 |
|
| 512 |
# Remap the patron's attributes into a hash of arrayrefs per attribute (depends on |
512 |
# Build the attribute values list either from the passed values |
| 513 |
# autovivification) |
513 |
# or taken from the patron itself |
| 514 |
foreach my $attr (@$attributes) { |
514 |
if ( defined $entered_attributes ) { |
| 515 |
push @{ $attr_values{ $attr->{code} } }, $attr; |
515 |
foreach my $attr (@$entered_attributes) { |
|
|
516 |
push @{ $attr_values{ $attr->{code} } }, $attr->{value}; |
| 516 |
} |
517 |
} |
| 517 |
} |
518 |
} |
| 518 |
|
519 |
elsif ( defined $borrowernumber ) { |
| 519 |
if ( $entered_attributes ) { |
520 |
my @editable_attributes = grep { $_->opac_editable } @displayable_attributes; |
| 520 |
foreach my $attr (@$entered_attributes) { |
521 |
foreach my $attr (@editable_attributes) { |
| 521 |
push @{ $attr_values{ $attr->{code} } }, $attr; |
522 |
push @{ $attr_values{ $attr->code } }, $attr->attribute; |
| 522 |
} |
523 |
} |
| 523 |
} |
524 |
} |
| 524 |
|
525 |
|
|
|
526 |
# Add the non-editable attributes (that don't come from the form) |
| 527 |
foreach my $attr ( grep { !$_->opac_editable } @displayable_attributes ) { |
| 528 |
push @{ $attr_values{ $attr->code } }, $attr->attribute; |
| 529 |
} |
| 530 |
|
| 525 |
# Find all existing classes |
531 |
# Find all existing classes |
| 526 |
my @classes = uniq( map { $_->{class} } @types ); |
532 |
my @classes = sort( uniq( map { $_->class } @types ) ); |
| 527 |
@classes = sort @classes; |
|
|
| 528 |
my %items_by_class; |
533 |
my %items_by_class; |
| 529 |
|
534 |
|
| 530 |
foreach my $attr_type_desc (@types) { |
535 |
foreach my $attr_type (@types) { |
| 531 |
my $attr_type = C4::Members::AttributeTypes->fetch( $attr_type_desc->{code} ); |
|
|
| 532 |
# Make sure this attribute should be displayed in the OPAC |
| 533 |
next unless ( $attr_type->opac_display() ); |
| 534 |
# Then, make sure it either has values or is editable |
| 535 |
next unless ( $attr_values{ $attr_type->code() } || $attr_type->opac_editable() ); |
| 536 |
|
| 537 |
push @{ $items_by_class{ $attr_type->class() } }, { |
536 |
push @{ $items_by_class{ $attr_type->class() } }, { |
| 538 |
type => $attr_type, |
537 |
type => $attr_type, |
| 539 |
# If editable, make sure there's at least one empty entry, to make the template's job easier |
538 |
# If editable, make sure there's at least one empty entry, |
| 540 |
values => $attr_values{ $attr_type->code() } || [{}] |
539 |
# to make the template's job easier |
|
|
540 |
values => $attr_values{ $attr_type->code() } || [''] |
| 541 |
}; |
541 |
}; |
| 542 |
} |
542 |
} |
| 543 |
|
543 |
|
|
Lines 546-559
sub GeneratePatronAttributesForm {
Link Here
|
| 546 |
foreach my $class (@classes) { |
546 |
foreach my $class (@classes) { |
| 547 |
next unless ( $items_by_class{$class} ); |
547 |
next unless ( $items_by_class{$class} ); |
| 548 |
|
548 |
|
| 549 |
my $av = Koha::AuthorisedValues->search({ category => 'PA_CLASS', authorised_value => $class }); |
549 |
my $av = Koha::AuthorisedValues->search( |
|
|
550 |
{ category => 'PA_CLASS', authorised_value => $class } ); |
| 551 |
|
| 550 |
my $lib = $av->count ? $av->next->opac_description : $class; |
552 |
my $lib = $av->count ? $av->next->opac_description : $class; |
| 551 |
|
553 |
|
| 552 |
push @class_loop, { |
554 |
push @class_loop, |
|
|
555 |
{ |
| 553 |
class => $class, |
556 |
class => $class, |
| 554 |
items => $items_by_class{$class}, |
557 |
items => $items_by_class{$class}, |
| 555 |
lib => $lib, |
558 |
lib => $lib, |
| 556 |
}; |
559 |
}; |
| 557 |
} |
560 |
} |
| 558 |
|
561 |
|
| 559 |
return \@class_loop; |
562 |
return \@class_loop; |
|
Lines 567-585
sub ParsePatronAttributes {
Link Here
|
| 567 |
|
570 |
|
| 568 |
my $ea = each_array( @codes, @values ); |
571 |
my $ea = each_array( @codes, @values ); |
| 569 |
my @attributes; |
572 |
my @attributes; |
| 570 |
my %dups = (); |
573 |
|
|
|
574 |
my $delete_candidates = {}; |
| 571 |
|
575 |
|
| 572 |
while ( my ( $code, $value ) = $ea->() ) { |
576 |
while ( my ( $code, $value ) = $ea->() ) { |
| 573 |
# Don't skip if the patron already has attributes with $code, because |
577 |
if ( !defined($value) or $value eq '' ) { |
| 574 |
# it means we are being requested to remove the attributes. |
578 |
$delete_candidates->{$code} = 1 |
| 575 |
next |
579 |
unless $delete_candidates->{$code}; |
| 576 |
unless defined($value) and $value ne '' |
580 |
} else { |
| 577 |
or Koha::Patron::Attributes->search( |
581 |
# we've got a value |
| 578 |
{ borrowernumber => $borrowernumber, code => $code } )->count > 0; |
582 |
push @attributes, { code => $code, value => $value }; |
| 579 |
next if exists $dups{$code}->{$value}; |
583 |
# 'code' is no longer a delete candidate |
| 580 |
$dups{$code}->{$value} = 1; |
584 |
delete $delete_candidates->{$code}; |
| 581 |
|
585 |
} |
| 582 |
push @attributes, { code => $code, value => $value }; |
586 |
} |
|
|
587 |
|
| 588 |
foreach my $code ( keys %{ $delete_candidates } ) { |
| 589 |
push @attributes, { code => $code, value => '' }; |
| 583 |
} |
590 |
} |
| 584 |
|
591 |
|
| 585 |
return \@attributes; |
592 |
return \@attributes; |
| 586 |
- |
|
|