3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Digest::MD5 qw( md5_base64 md5_hex );
22 use JSON qw( to_json );
23 use List::MoreUtils qw( any each_array uniq );
24 use String::Random qw( random_string );
27 use C4::Auth qw( get_template_and_user );
28 use C4::Output qw( output_html_with_http_headers );
30 use C4::Letters qw( GetPreparedLetter EnqueueLetter SendQueuedMessages );
31 use C4::Form::MessagingPreferences;
34 use Koha::Patron::Consent;
35 use Koha::Patron::Modification;
36 use Koha::Patron::Modifications;
38 use Koha::DateUtils qw( dt_from_string );
41 use Koha::Patron::Attribute::Types;
42 use Koha::Patron::Attributes;
43 use Koha::Patron::Images;
44 use Koha::Patron::Categories;
45 use Koha::Policy::Patrons::Cardnumber;
46 use Koha::AuthorisedValues;
48 my $dbh = C4::Context->dbh;
50 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
52 template_name => "opac-memberentry.tt",
59 my $op = $cgi->param('op') || q{};
60 if ( $borrowernumber && ( $op eq 'cud-create' || $op eq 'new' ) ) {
61 print $cgi->redirect("/cgi-bin/koha/opac-main.pl");
66 if ($borrowernumber) {
74 my $PatronSelfRegistrationDefaultCategory = C4::Context->preference('PatronSelfRegistrationDefaultCategory');
75 my $defaultCategory = Koha::Patron::Categories->find($PatronSelfRegistrationDefaultCategory);
76 # Having a valid PatronSelfRegistrationDefaultCategory is mandatory
77 if ( !C4::Context->preference('PatronSelfRegistration') && !$borrowernumber
78 || ( ( $op eq 'new' || $op eq 'cud-create' ) && !$defaultCategory ) )
80 print $cgi->redirect("/cgi-bin/koha/opac-main.pl");
84 my $mandatory = GetMandatoryFields($op);
87 if ( $op eq 'cud-create' || $op eq 'new' ) {
88 my @PatronSelfRegistrationLibraryList = split '\|', C4::Context->preference('PatronSelfRegistrationLibraryList');
89 $params = { branchcode => { -in => \@PatronSelfRegistrationLibraryList } }
90 if @PatronSelfRegistrationLibraryList;
92 my $libraries = Koha::Libraries->search($params);
94 my ( $min, $max ) = Koha::Policy::Patrons::Cardnumber->get_valid_length();
97 minlength_cardnumber => $min,
98 maxlength_cardnumber => $max
102 my $translated_languages = C4::Languages::getTranslatedLanguages( 'opac', C4::Context->preference('template') );
106 hidden => GetHiddenFields( $mandatory, $op ),
107 mandatory => $mandatory,
108 libraries => $libraries,
109 OPACPatronDetails => C4::Context->preference('OPACPatronDetails'),
110 defaultCategory => $defaultCategory,
111 languages => $translated_languages,
114 my $attributes = ParsePatronAttributes($borrowernumber,$cgi);
115 my $conflicting_attribute = 0;
117 foreach my $attr (@$attributes) {
118 my $attribute = Koha::Patron::Attribute->new($attr);
119 if ( !$attribute->unique_ok ) {
120 my $attr_type = Koha::Patron::Attribute::Types->find($attr->{code});
122 extended_unique_id_failed_code => $attr->{code},
123 extended_unique_id_failed_value => $attr->{attribute},
124 extended_unique_id_failed_description => $attr_type->description,
126 $conflicting_attribute = 1;
130 if ( $op eq 'cud-create' ) {
132 my %borrower = ParseCgiForBorrower($cgi);
134 %borrower = DelEmptyFields(%borrower);
135 $borrower{categorycode} ||= $PatronSelfRegistrationDefaultCategory;
137 my @empty_mandatory_fields = (CheckMandatoryFields( \%borrower, $op ), CheckMandatoryAttributes( \%borrower, $attributes ) );
138 my $invalidformfields = CheckForInvalidFields(\%borrower);
139 delete $borrower{'password2'};
140 my $is_cardnumber_valid;
141 if ( !grep { $_ eq 'cardnumber' } @empty_mandatory_fields ) {
142 # No point in checking the cardnumber if it's missing and mandatory, it'll just generate a
143 # spurious length warning.
144 my $patron = Koha::Patrons->find($borrower{borrowernumber});
145 $is_cardnumber_valid = Koha::Policy::Patrons::Cardnumber->is_valid($borrower{cardnumber}, $patron);
146 unless ($is_cardnumber_valid) {
147 for my $m ( @{ $is_cardnumber_valid->messages } ) {
148 my $message = $m->message;
149 if ( $message eq 'already_exists' ) {
150 $template->param( cardnumber_already_exists => 1 );
151 } elsif ( $message eq 'invalid_length' ) {
152 $template->param( cardnumber_wrong_length => 1 );
158 if ( @empty_mandatory_fields || @$invalidformfields || !$is_cardnumber_valid || $conflicting_attribute ) {
161 empty_mandatory_fields => \@empty_mandatory_fields,
162 invalid_form_fields => $invalidformfields,
163 borrower => \%borrower
165 $template->param( patron_attribute_classes => GeneratePatronAttributesForm( undef, $attributes ) );
168 md5_base64( uc( $cgi->param('captcha') ) ) ne $cgi->param('captcha_digest') )
172 borrower => \%borrower
174 $template->param( patron_attribute_classes => GeneratePatronAttributesForm( undef, $attributes ) );
175 } elsif ( !$libraries->find($borrower{branchcode}) ) {
176 die "Branchcode not allowed"; # They hack the form
180 C4::Context->preference(
181 'PatronSelfRegistrationVerifyByEmail')
184 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
186 template_name => "opac-registration-email-sent.tt",
189 authnotrequired => 1,
192 $template->param( 'email' => $borrower{'email'} );
194 my $verification_token = md5_hex( time().{}.rand().{}.$$ );
195 while ( Koha::Patron::Modifications->search( { verification_token => $verification_token } )->count() ) {
196 $verification_token = md5_hex( time().{}.rand().{}.$$ );
199 $borrower{password} = Koha::AuthUtils::generate_password(Koha::Patron::Categories->find($borrower{categorycode})) unless $borrower{password};
200 $borrower{verification_token} = $verification_token;
202 $borrower{extended_attributes} = to_json($attributes);
203 Koha::Patron::Modification->new( \%borrower )->store();
205 #Send verification email
206 my $letter = C4::Letters::GetPreparedLetter(
208 letter_code => 'OPAC_REG_VERIFY',
209 lang => 'default', # Patron does not have a preferred language defined yet
211 borrower_modifications => $verification_token,
215 my $message_id = C4::Letters::EnqueueLetter(
218 message_transport_type => 'email',
219 to_address => $borrower{'email'},
221 C4::Context->preference('KohaAdminEmailAddress'),
224 C4::Letters::SendQueuedMessages( { message_id => $message_id } ) if $message_id;
227 $borrower{password} ||= Koha::AuthUtils::generate_password(Koha::Patron::Categories->find($borrower{categorycode}));
228 my $consent_dt = delete $borrower{gdpr_proc_consent};
231 $patron = Koha::Patron->new( \%borrower )->store;
232 Koha::Patron::Consent->new({ borrowernumber => $patron->borrowernumber, type => 'GDPR_PROCESSING', given_on => $consent_dt })->store if $patron && $consent_dt;
236 $template->param( error_type => $type, error_info => $info );
237 $template->param( borrower => \%borrower );
240 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
242 template_name => "opac-registration-confirmation.tt",
245 authnotrequired => 1,
250 $patron->extended_attributes->filter_by_branch_limitations->delete;
251 $patron->extended_attributes($attributes);
252 if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
253 C4::Form::MessagingPreferences::handle_form_action(
255 { borrowernumber => $patron->borrowernumber },
258 $PatronSelfRegistrationDefaultCategory
262 $template->param( password_cleartext => $patron->plain_text_password );
263 $template->param( borrower => $patron->unblessed );
265 $template->param( confirmed => 1 );
267 # If 'AutoEmailNewUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
268 if ( C4::Context->preference("AutoEmailNewUser") ) {
269 #look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead
270 my $emailaddr = $patron->notice_email_address;
271 # if we manage to find a valid email address, send notice
274 my $letter = GetPreparedLetter(
276 letter_code => 'WELCOME',
277 branchcode => $patron->branchcode,,
278 lang => $patron->lang || 'default',
280 'branches' => $patron->branchcode,
281 'borrowers' => $patron->borrowernumber,
286 my $message_id = EnqueueLetter(
289 borrowernumber => $patron->id,
290 to_address => $emailaddr,
291 message_transport_type => 'email'
294 SendQueuedMessages( { message_id => $message_id } ) if $message_id;
299 # Notify library of new patron registration
300 my $notify_library = C4::Context->preference('EmailPatronRegistrations');
301 if ($notify_library) {
302 $patron->notify_library_of_registration($notify_library);
307 PatronSelfRegistrationAdditionalInstructions =>
308 C4::Context->preference(
309 'PatronSelfRegistrationAdditionalInstructions')
314 elsif ( $op eq 'cud-update' ) {
316 my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
318 my %borrower = ParseCgiForBorrower($cgi);
319 $borrower{borrowernumber} = $borrowernumber;
321 my @empty_mandatory_fields = grep { $_ ne 'password' } # password is not required when editing personal details
322 ( CheckMandatoryFields( \%borrower, $op ), CheckMandatoryAttributes( \%borrower, $attributes ) );
323 my $invalidformfields = CheckForInvalidFields(\%borrower);
325 # Send back the data to the template
326 %borrower = ( %$borrower, %borrower );
328 if (@empty_mandatory_fields || @$invalidformfields) {
330 empty_mandatory_fields => \@empty_mandatory_fields,
331 invalid_form_fields => $invalidformfields,
332 borrower => \%borrower,
334 $template->param( patron_attribute_classes => GeneratePatronAttributesForm( $borrowernumber, $attributes ) );
336 $template->param( op => 'edit' );
339 my %borrower_changes = DelUnchangedFields( $borrowernumber, %borrower );
340 $borrower_changes{'changed_fields'} = join ',', keys %borrower_changes;
341 my $extended_attributes_changes = FilterUnchangedAttributes( $borrowernumber, $attributes );
343 if ( %borrower_changes || scalar @{$extended_attributes_changes} > 0 ) {
344 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
346 template_name => "opac-memberentry-update-submitted.tt",
349 authnotrequired => 1,
353 $borrower_changes{borrowernumber} = $borrowernumber;
354 $borrower_changes{extended_attributes} = to_json($extended_attributes_changes);
356 Koha::Patron::Modifications->search({ borrowernumber => $borrowernumber })->delete;
358 my $m = Koha::Patron::Modification->new( \%borrower_changes )->store();
359 #Automatically approve patron profile changes if set in syspref
361 if (C4::Context->preference('AutoApprovePatronProfileSettings')) {
362 # Need to get the object from database, otherwise it is not complete enough to allow deletion
363 # when approval has been performed.
364 my $tmp_m = Koha::Patron::Modifications->find({borrowernumber => $borrowernumber});
365 $tmp_m->approve() if $tmp_m;
368 my $patron = Koha::Patrons->find( $borrowernumber );
369 $template->param( borrower => $patron->unblessed );
372 my $patron = Koha::Patrons->find( $borrowernumber );
376 borrower => $patron->unblessed,
377 patron_attribute_classes => GeneratePatronAttributesForm( $borrowernumber, $attributes ),
382 elsif ( $op eq 'edit' ) { #Display logged in borrower's data
383 my $patron = Koha::Patrons->find( $borrowernumber );
384 my $borrower = $patron->unblessed;
387 borrower => $borrower,
388 hidden => GetHiddenFields( $mandatory, 'edit' ),
391 if (C4::Context->preference('OPACpatronimages')) {
392 $template->param( display_patron_image => 1 ) if $patron->image;
395 $template->param( patron_attribute_classes => GeneratePatronAttributesForm( $borrowernumber ) );
397 # Render self-registration page
398 $template->param( patron_attribute_classes => GeneratePatronAttributesForm() );
401 my $captcha = random_string("CCCCC");
402 my $patron_param = Koha::Patrons->find( $borrowernumber );
404 has_guarantor_flag => $patron_param->guarantor_relationships->guarantors->_resultset->count
409 captcha_digest => md5_base64($captcha),
410 patron => $patron_param
413 output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 };
415 sub GetHiddenFields {
416 my ( $mandatory, $op ) = @_;
419 my $BorrowerUnwantedField = $op eq 'edit' || $op eq 'cud-update' ?
420 C4::Context->preference( "PatronSelfModificationBorrowerUnwantedField" ) :
421 C4::Context->preference( "PatronSelfRegistrationBorrowerUnwantedField" );
423 my @fields = split( /\|/, $BorrowerUnwantedField || q|| );
426 #Don't hide mandatory fields
427 next if $mandatory->{$_};
428 $hidden_fields{$_} = 1;
431 return \%hidden_fields;
434 sub GetMandatoryFields {
437 my %mandatory_fields;
439 my $BorrowerMandatoryField = $op eq 'edit' || $op eq 'cud-update' ?
440 C4::Context->preference("PatronSelfModificationMandatoryField") :
441 C4::Context->preference("PatronSelfRegistrationBorrowerMandatoryField");
443 my @fields = split( /\|/, $BorrowerMandatoryField );
444 push @fields, 'gdpr_proc_consent' if C4::Context->preference('PrivacyPolicyConsent') && $op eq 'cud-create';
447 $mandatory_fields{$_} = 1;
450 if ( $op eq 'cud-create' || $op eq 'new' ) {
451 $mandatory_fields{'email'} = 1
452 if C4::Context->preference(
453 'PatronSelfRegistrationVerifyByEmail');
456 return \%mandatory_fields;
459 sub CheckMandatoryFields {
460 my ( $borrower, $op ) = @_;
462 my @empty_mandatory_fields;
464 my $mandatory_fields = GetMandatoryFields($op);
465 delete $mandatory_fields->{'cardnumber'};
467 foreach my $key ( keys %$mandatory_fields ) {
468 push( @empty_mandatory_fields, $key )
469 unless ( defined( $borrower->{$key} ) && $borrower->{$key} );
472 return @empty_mandatory_fields;
475 sub CheckMandatoryAttributes{
476 my ( $borrower, $attributes ) = @_;
478 my @empty_mandatory_fields;
480 for my $attribute (@$attributes ) {
481 my $attr = Koha::Patron::Attribute::Types->find($attribute->{code});
482 push @empty_mandatory_fields, $attribute->{code}
483 if $attr && $attr->mandatory && $attribute->{attribute} =~ m|^\s*$|;
486 return @empty_mandatory_fields;
489 sub CheckForInvalidFields {
490 my $borrower = shift;
492 if ($borrower->{'email'}) {
493 unless ( Koha::Email->is_valid($borrower->{email}) ) {
494 push(@invalidFields, "email");
495 } elsif ( C4::Context->preference("PatronSelfRegistrationEmailMustBeUnique") ) {
496 my $patrons_with_same_email = Koha::Patrons->search( # FIXME Should be search_limited?
498 email => $borrower->{email},
500 exists $borrower->{borrowernumber}
501 ? ( borrowernumber =>
502 { '!=' => $borrower->{borrowernumber} } )
507 if ( $patrons_with_same_email ) {
508 push @invalidFields, "duplicate_email";
510 } elsif ( C4::Context->preference("PatronSelfRegistrationConfirmEmail")
511 && $borrower->{'email'} ne $borrower->{'repeat_email'}
512 && !defined $borrower->{borrowernumber} ) {
513 push @invalidFields, "email_match";
515 # email passed all tests, so prevent attempting to store repeat_email
516 delete $borrower->{'repeat_email'};
518 if ($borrower->{'emailpro'}) {
519 push(@invalidFields, "emailpro") unless Koha::Email->is_valid($borrower->{'emailpro'});
521 if ($borrower->{'B_email'}) {
522 push(@invalidFields, "B_email") unless Koha::Email->is_valid($borrower->{'B_email'});
524 if ( defined $borrower->{'password'}
525 and $borrower->{'password'} ne $borrower->{'password2'} )
527 push( @invalidFields, "password_match" );
529 if ( $borrower->{'password'} ) {
530 my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $borrower->{password}, Koha::Patron::Categories->find($borrower->{categorycode}||C4::Context->preference('PatronSelfRegistrationDefaultCategory')) );
531 unless ( $is_valid ) {
532 push @invalidFields, 'password_too_short' if $error eq 'too_short';
533 push @invalidFields, 'password_too_weak' if $error eq 'too_weak';
534 push @invalidFields, 'password_has_whitespaces' if $error eq 'has_whitespaces';
538 return \@invalidFields;
541 sub ParseCgiForBorrower {
544 my $scrubber = C4::Scrubber->new();
547 foreach my $field ( $cgi->param ) {
548 if ( $field =~ '^borrower_' ) {
549 my ($key) = substr( $field, 9 );
550 if ( $field !~ '^borrower_password' ) {
551 $borrower{$key} = $scrubber->scrub( scalar $cgi->param($field) );
553 # Allow html characters for passwords
554 $borrower{$key} = $cgi->param($field);
559 # Replace checkbox 'agreed' by datetime in gdpr_proc_consent
560 $borrower{gdpr_proc_consent} = dt_from_string if $borrower{gdpr_proc_consent} && $borrower{gdpr_proc_consent} eq 'agreed';
562 delete $borrower{$_} for qw/borrowernumber date_renewed debarred debarredcomment flags privacy privacy_guarantor_fines privacy_guarantor_checkouts checkprevcheckout updated_on lastseen login_attempts overdrive_auth_token anonymized/; # See also members/memberentry.pl
563 delete $borrower{$_} for qw/dateenrolled dateexpiry borrowernotes opacnote sort1 sort2 sms_provider_id autorenew_checkouts gonenoaddress lost relationship/; # On OPAC only
564 delete $borrower{$_} for split( /\s*\|\s*/, C4::Context->preference('PatronSelfRegistrationBorrowerUnwantedField') || q{} );
569 sub DelUnchangedFields {
570 my ( $borrowernumber, %new_data ) = @_;
571 # get the mandatory fields so we can get the hidden fields
572 my $mandatory = GetMandatoryFields('edit');
573 my $patron = Koha::Patrons->find( $borrowernumber );
574 my $current_data = $patron->unblessed;
575 # get the hidden fields so we don't obliterate them should they have data patrons aren't allowed to modify
576 my $hidden_fields = GetHiddenFields($mandatory, 'edit');
579 foreach my $key ( keys %new_data ) {
580 next if defined($new_data{$key}) xor defined($current_data->{$key});
581 if ( !defined($new_data{$key}) || $current_data->{$key} eq $new_data{$key} || $hidden_fields->{$key} ) {
582 delete $new_data{$key};
592 foreach my $key ( keys %borrower ) {
593 delete $borrower{$key} unless $borrower{$key};
599 sub FilterUnchangedAttributes {
600 my ( $borrowernumber, $entered_attributes ) = @_;
602 my @patron_attributes = grep {$_->type->opac_editable ? $_ : ()} Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
604 my $patron_attribute_types;
605 foreach my $attr (@patron_attributes) {
606 $patron_attribute_types->{ $attr->code } += 1;
609 my $passed_attribute_types;
610 foreach my $attr (@{ $entered_attributes }) {
611 $passed_attribute_types->{ $attr->{ code } } += 1;
614 my @changed_attributes;
616 # Loop through the current patron attributes
617 foreach my $attribute_type ( keys %{ $patron_attribute_types } ) {
618 if ( $patron_attribute_types->{ $attribute_type } != $passed_attribute_types->{ $attribute_type } ) {
619 # count differs, overwrite all attributes for given type
620 foreach my $attr (@{ $entered_attributes }) {
621 push @changed_attributes, $attr
622 if $attr->{ code } eq $attribute_type;
625 # count matches, check values
627 foreach my $attr (grep { $_->code eq $attribute_type } @patron_attributes) {
629 unless any { $_->{ value } eq $attr->attribute } @{ $entered_attributes };
634 foreach my $attr (@{ $entered_attributes }) {
635 push @changed_attributes, $attr
636 if $attr->{ code } eq $attribute_type;
642 # Loop through passed attributes, looking for new ones
643 foreach my $attribute_type ( keys %{ $passed_attribute_types } ) {
644 if ( !defined $patron_attribute_types->{ $attribute_type } ) {
646 foreach my $attr (grep { $_->{code} eq $attribute_type } @{ $entered_attributes }) {
647 push @changed_attributes, $attr;
652 return \@changed_attributes;
655 sub GeneratePatronAttributesForm {
656 my ( $borrowernumber, $entered_attributes ) = @_;
658 # Get all attribute types and the values for this patron (if applicable)
659 my @types = grep { $_->opac_editable() or $_->opac_display } # FIXME filter using DBIC
660 Koha::Patron::Attribute::Types->search()->as_list();
661 if ( scalar(@types) == 0 ) {
665 my @displayable_attributes = grep { $_->type->opac_display ? $_ : () }
666 Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
668 my %attr_values = ();
670 # Build the attribute values list either from the passed values
671 # or taken from the patron itself
672 if ( defined $entered_attributes ) {
673 foreach my $attr (@$entered_attributes) {
674 push @{ $attr_values{ $attr->{code} } }, $attr->{value};
677 elsif ( defined $borrowernumber ) {
678 my @editable_attributes = grep { $_->type->opac_editable ? $_ : () } @displayable_attributes;
679 foreach my $attr (@editable_attributes) {
680 push @{ $attr_values{ $attr->code } }, $attr->attribute;
684 # Add the non-editable attributes (that don't come from the form)
685 foreach my $attr ( grep { !$_->type->opac_editable } @displayable_attributes ) {
686 push @{ $attr_values{ $attr->code } }, $attr->attribute;
689 # Find all existing classes
690 my @classes = sort( uniq( map { $_->class } @types ) );
693 foreach my $attr_type (@types) {
694 push @{ $items_by_class{ $attr_type->class() } }, {
696 # If editable, make sure there's at least one empty entry,
697 # to make the template's job easier
698 values => $attr_values{ $attr_type->code() } || ['']
700 unless !defined $attr_values{ $attr_type->code() }
701 and !$attr_type->opac_editable;
704 # Finally, build a list of containing classes
706 foreach my $class (@classes) {
707 next unless ( $items_by_class{$class} );
709 my $av = Koha::AuthorisedValues->search(
710 { category => 'PA_CLASS', authorised_value => $class } );
712 my $lib = $av->count ? $av->next->opac_description : $class;
717 items => $items_by_class{$class},
725 sub ParsePatronAttributes {
726 my ( $borrowernumber, $cgi ) = @_;
728 my @codes = $cgi->multi_param('patron_attribute_code');
729 my @values = $cgi->multi_param('patron_attribute_value');
731 my @editable_attribute_types
732 = map { $_->code } Koha::Patron::Attribute::Types->search({ opac_editable => 1 })->as_list;
734 my $ea = each_array( @codes, @values );
737 my $delete_candidates = {};
739 my $scrubber = C4::Scrubber->new();
740 while ( my ( $code, $value ) = $ea->() ) {
741 if ( any { $_ eq $code } @editable_attribute_types ) {
742 # It is an editable attribute
743 if ( !defined($value) or $value eq '' ) {
744 $delete_candidates->{$code} = 1
745 unless $delete_candidates->{$code};
749 push @attributes, { code => $code, attribute => $scrubber->scrub( $value ) };
751 # 'code' is no longer a delete candidate
752 delete $delete_candidates->{$code}
753 if defined $delete_candidates->{$code};
758 foreach my $code ( keys %{$delete_candidates} ) {
759 if ( not $borrowernumber # self-registration
760 || Koha::Patron::Attributes->search({
761 borrowernumber => $borrowernumber, code => $code })->count > 0 )
763 push @attributes, { code => $code, attribute => '' }
764 unless any { $_->{code} eq $code } @attributes;