Lines 312-318
if ( ( defined $newdata{'userid'} && $newdata{'userid'} eq '' ) || $check_Borrow
Link Here
|
312 |
} |
312 |
} |
313 |
|
313 |
|
314 |
$debug and warn join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry); |
314 |
$debug and warn join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry); |
315 |
my $extended_patron_attributes = (); |
315 |
my $extended_patron_attributes; |
316 |
if ($op eq 'save' || $op eq 'insert'){ |
316 |
if ($op eq 'save' || $op eq 'insert'){ |
317 |
|
317 |
|
318 |
output_and_exit( $input, $cookie, $template, 'wrong_csrf_token' ) |
318 |
output_and_exit( $input, $cookie, $template, 'wrong_csrf_token' ) |
Lines 398-416
if ($op eq 'save' || $op eq 'insert'){
Link Here
|
398 |
push (@errors, "ERROR_bad_email_alternative") if (!Email::Valid->address($emailalt)); |
398 |
push (@errors, "ERROR_bad_email_alternative") if (!Email::Valid->address($emailalt)); |
399 |
} |
399 |
} |
400 |
|
400 |
|
401 |
if (C4::Context->preference('ExtendedPatronAttributes')) { |
401 |
if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) { |
402 |
$extended_patron_attributes = parse_extended_patron_attributes($input); |
402 |
$extended_patron_attributes = parse_extended_patron_attributes($input); |
403 |
foreach my $attr (@$extended_patron_attributes) { |
403 |
for my $attr ( @$extended_patron_attributes ) { |
404 |
unless (C4::Members::Attributes::CheckUniqueness($attr->{code}, $attr->{value}, $borrowernumber)) { |
404 |
$attr->{borrowernumber} = $borrowernumber if $borrowernumber; |
405 |
my $attr_info = C4::Members::AttributeTypes->fetch($attr->{code}); |
405 |
my $attribute = Koha::Patron::Attribute->new($attr); |
406 |
push @errors, "ERROR_extended_unique_id_failed"; |
406 |
eval {$attribute->check_unique_id}; |
407 |
$template->param( |
407 |
if ( $@ ) { |
408 |
ERROR_extended_unique_id_failed_code => $attr->{code}, |
408 |
push @errors, "ERROR_extended_unique_id_failed"; |
409 |
ERROR_extended_unique_id_failed_value => $attr->{value}, |
409 |
my $attr_info = C4::Members::AttributeTypes->fetch($attr->{code}); |
410 |
ERROR_extended_unique_id_failed_description => $attr_info->description() |
410 |
$template->param( |
411 |
); |
411 |
ERROR_extended_unique_id_failed_code => $attr->{code}, |
412 |
} |
412 |
ERROR_extended_unique_id_failed_value => $attr->{attribute}, |
413 |
} |
413 |
ERROR_extended_unique_id_failed_description => $attr_info->description() |
|
|
414 |
); |
415 |
} |
416 |
} |
414 |
} |
417 |
} |
415 |
} |
418 |
} |
416 |
|
419 |
|
Lines 479-488
if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
Link Here
|
479 |
} |
482 |
} |
480 |
} |
483 |
} |
481 |
|
484 |
|
482 |
if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) { |
|
|
483 |
$patron->extended_attributes->filter_by_branch_limitations->delete; |
484 |
$patron->extended_attributes($extended_patron_attributes); |
485 |
} |
486 |
if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) { |
485 |
if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) { |
487 |
C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template, 1, $newdata{'categorycode'}); |
486 |
C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template, 1, $newdata{'categorycode'}); |
488 |
} |
487 |
} |
Lines 550-564
if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
Link Here
|
550 |
} |
549 |
} |
551 |
|
550 |
|
552 |
add_guarantors( $patron, $input ); |
551 |
add_guarantors( $patron, $input ); |
553 |
if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) { |
|
|
554 |
$patron->extended_attributes->filter_by_branch_limitations->delete; |
555 |
$patron->extended_attributes($extended_patron_attributes); |
556 |
} |
557 |
if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) { |
552 |
if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) { |
558 |
C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template); |
553 |
C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template); |
559 |
} |
554 |
} |
560 |
} |
555 |
} |
561 |
|
556 |
|
|
|
557 |
if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) { |
558 |
$patron->extended_attributes->filter_by_branch_limitations->delete; |
559 |
$patron->extended_attributes($extended_patron_attributes); |
560 |
} |
561 |
|
562 |
if ( $destination eq 'circ' and not C4::Auth::haspermission( C4::Context->userenv->{id}, { circulate => 'circulate_remaining_permissions' } ) ) { |
562 |
if ( $destination eq 'circ' and not C4::Auth::haspermission( C4::Context->userenv->{id}, { circulate => 'circulate_remaining_permissions' } ) ) { |
563 |
# If we want to redirect to circulation.pl and need to check if the logged in user has the necessary permission |
563 |
# If we want to redirect to circulation.pl and need to check if the logged in user has the necessary permission |
564 |
$destination = 'not_circ'; |
564 |
$destination = 'not_circ'; |
Lines 832-838
if ( C4::Context->preference('TranslateNotices') ) {
Link Here
|
832 |
|
832 |
|
833 |
output_html_with_http_headers $input, $cookie, $template->output; |
833 |
output_html_with_http_headers $input, $cookie, $template->output; |
834 |
|
834 |
|
835 |
sub parse_extended_patron_attributes { |
835 |
sub parse_extended_patron_attributes { |
836 |
my ($input) = @_; |
836 |
my ($input) = @_; |
837 |
my @patron_attr = grep { /^patron_attr_\d+$/ } $input->multi_param(); |
837 |
my @patron_attr = grep { /^patron_attr_\d+$/ } $input->multi_param(); |
838 |
|
838 |
|
Lines 844-850
sub parse_extended_patron_attributes {
Link Here
|
844 |
my $code = $input->param("${key}_code"); |
844 |
my $code = $input->param("${key}_code"); |
845 |
next if exists $dups{$code}->{$value}; |
845 |
next if exists $dups{$code}->{$value}; |
846 |
$dups{$code}->{$value} = 1; |
846 |
$dups{$code}->{$value} = 1; |
847 |
push @attr, { code => $code, value => $value }; |
847 |
push @attr, { code => $code, attribute => $value }; |
848 |
} |
848 |
} |
849 |
return \@attr; |
849 |
return \@attr; |
850 |
} |
850 |
} |
Lines 859-873
sub patron_attributes_form {
Link Here
|
859 |
$template->param(no_patron_attribute_types => 1); |
859 |
$template->param(no_patron_attribute_types => 1); |
860 |
return; |
860 |
return; |
861 |
} |
861 |
} |
862 |
my $patron = Koha::Patrons->find($borrowernumber); # Already fetched but outside of this sub |
862 |
my @attributes; |
863 |
my @attributes = $patron->extended_attributes->as_list; # FIXME Must be improved! |
863 |
if ( $borrowernumber ) { |
864 |
my @classes = uniq( map {$_->type->class} @attributes ); |
864 |
my $patron = Koha::Patrons->find($borrowernumber); # Already fetched but outside of this sub |
865 |
@classes = sort @classes; |
865 |
@attributes = $patron->extended_attributes->as_list; # FIXME Must be improved! |
|
|
866 |
} |
866 |
|
867 |
|
867 |
# map patron's attributes into a more convenient structure |
868 |
# map patron's attributes into a more convenient structure |
868 |
my %attr_hash = (); |
869 |
my %attr_hash = (); |
869 |
foreach my $attr (@attributes) { |
870 |
foreach my $attr (@attributes) { |
870 |
push @{ $attr_hash{$attr->{code}} }, $attr; |
871 |
push @{ $attr_hash{$attr->code} }, $attr; |
871 |
} |
872 |
} |
872 |
|
873 |
|
873 |
my @attribute_loop = (); |
874 |
my @attribute_loop = (); |
Lines 886-896
sub patron_attributes_form {
Link Here
|
886 |
if (exists $attr_hash{$attr_type->code()}) { |
887 |
if (exists $attr_hash{$attr_type->code()}) { |
887 |
foreach my $attr (@{ $attr_hash{$attr_type->code()} }) { |
888 |
foreach my $attr (@{ $attr_hash{$attr_type->code()} }) { |
888 |
my $newentry = { %$entry }; |
889 |
my $newentry = { %$entry }; |
889 |
$newentry->{value} = $attr->{value}; |
890 |
$newentry->{value} = $attr->attribute; |
890 |
$newentry->{use_dropdown} = 0; |
891 |
$newentry->{use_dropdown} = 0; |
891 |
if ($attr_type->authorised_value_category()) { |
892 |
if ($attr_type->authorised_value_category()) { |
892 |
$newentry->{use_dropdown} = 1; |
893 |
$newentry->{use_dropdown} = 1; |
893 |
$newentry->{auth_val_loop} = GetAuthorisedValues($attr_type->authorised_value_category(), $attr->{value}); |
894 |
$newentry->{auth_val_loop} = GetAuthorisedValues($attr_type->authorised_value_category(), $attr->attribute); |
894 |
} |
895 |
} |
895 |
$i++; |
896 |
$i++; |
896 |
undef $newentry->{value} if ($attr_type->unique_id() && $op eq 'duplicate'); |
897 |
undef $newentry->{value} if ($attr_type->unique_id() && $op eq 'duplicate'); |