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 );
26 use C4::Auth qw( get_template_and_user );
27 use C4::Output qw( output_html_with_http_headers );
29 use C4::Letters qw( GetPreparedLetter EnqueueLetter SendQueuedMessages );
30 use C4::Members qw( checkcardnumber );
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 output_pref );
41 use Koha::Patron::Attribute::Types;
42 use Koha::Patron::Attributes;
43 use Koha::Patron::Images;
44 use Koha::Patron::Modification;
45 use Koha::Patron::Modifications;
46 use Koha::Patron::Categories;
48 use Koha::AuthorisedValues;
50 my $dbh = C4::Context->dbh;
52 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
54 template_name => "opac-memberentry.tt",
61 unless ( C4::Context->preference('PatronSelfRegistration') || $borrowernumber )
63 print $cgi->redirect("/cgi-bin/koha/opac-main.pl");
67 my $action = $cgi->param('action') || q{};
68 if ( $borrowernumber && ( $action eq 'create' || $action eq 'new' ) ) {
69 print $cgi->redirect("/cgi-bin/koha/opac-main.pl");
73 if ( $action eq q{} ) {
74 if ($borrowernumber) {
82 my $mandatory = GetMandatoryFields($action);
85 if ( $action eq 'create' || $action eq 'new' ) {
86 my @PatronSelfRegistrationLibraryList = split '\|', C4::Context->preference('PatronSelfRegistrationLibraryList');
87 $params = { branchcode => { -in => \@PatronSelfRegistrationLibraryList } }
88 if @PatronSelfRegistrationLibraryList;
90 my $libraries = Koha::Libraries->search($params);
92 my ( $min, $max ) = C4::Members::get_cardnumber_length();
95 minlength_cardnumber => $min,
96 maxlength_cardnumber => $max
100 my $defaultCategory = Koha::Patron::Categories->find(C4::Context->preference('PatronSelfRegistrationDefaultCategory'));
104 hidden => GetHiddenFields( $mandatory, $action ),
105 mandatory => $mandatory,
106 libraries => $libraries,
107 OPACPatronDetails => C4::Context->preference('OPACPatronDetails'),
108 defaultCategory => $defaultCategory,
111 my $attributes = ParsePatronAttributes($borrowernumber,$cgi);
112 my $conflicting_attribute = 0;
114 foreach my $attr (@$attributes) {
115 my $attribute = Koha::Patron::Attribute->new($attr);
116 if ( !$attribute->unique_ok ) {
117 my $attr_type = Koha::Patron::Attribute::Types->find($attr->{code});
119 extended_unique_id_failed_code => $attr->{code},
120 extended_unique_id_failed_value => $attr->{attribute},
121 extended_unique_id_failed_description => $attr_type->description,
123 $conflicting_attribute = 1;
127 if ( $action eq 'create' ) {
129 my %borrower = ParseCgiForBorrower($cgi);
131 %borrower = DelEmptyFields(%borrower);
132 $borrower{categorycode} ||= C4::Context->preference('PatronSelfRegistrationDefaultCategory');
134 my @empty_mandatory_fields = (CheckMandatoryFields( \%borrower, $action ), CheckMandatoryAttributes( \%borrower, $attributes ) );
135 my $invalidformfields = CheckForInvalidFields(\%borrower);
136 delete $borrower{'password2'};
137 my $cardnumber_error_code;
138 if ( !grep { $_ eq 'cardnumber' } @empty_mandatory_fields ) {
139 # No point in checking the cardnumber if it's missing and mandatory, it'll just generate a
140 # spurious length warning.
141 $cardnumber_error_code = checkcardnumber( $borrower{cardnumber}, $borrower{borrowernumber} );
144 if ( @empty_mandatory_fields || @$invalidformfields || $cardnumber_error_code || $conflicting_attribute ) {
145 if ( $cardnumber_error_code == 1 ) {
146 $template->param( cardnumber_already_exists => 1 );
147 } elsif ( $cardnumber_error_code == 2 ) {
148 $template->param( cardnumber_wrong_length => 1 );
152 empty_mandatory_fields => \@empty_mandatory_fields,
153 invalid_form_fields => $invalidformfields,
154 borrower => \%borrower
156 $template->param( patron_attribute_classes => GeneratePatronAttributesForm( undef, $attributes ) );
159 md5_base64( uc( $cgi->param('captcha') ) ) ne $cgi->param('captcha_digest') )
163 borrower => \%borrower
165 $template->param( patron_attribute_classes => GeneratePatronAttributesForm( undef, $attributes ) );
166 } elsif ( !$libraries->find($borrower{branchcode}) ) {
167 die "Branchcode not allowed"; # They hack the form
171 C4::Context->preference(
172 'PatronSelfRegistrationVerifyByEmail')
175 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
177 template_name => "opac-registration-email-sent.tt",
180 authnotrequired => 1,
183 $template->param( 'email' => $borrower{'email'} );
185 my $verification_token = md5_hex( time().{}.rand().{}.$$ );
186 while ( Koha::Patron::Modifications->search( { verification_token => $verification_token } )->count() ) {
187 $verification_token = md5_hex( time().{}.rand().{}.$$ );
190 $borrower{password} = Koha::AuthUtils::generate_password(Koha::Patron::Categories->find($borrower{categorycode})) unless $borrower{password};
191 $borrower{verification_token} = $verification_token;
193 Koha::Patron::Modification->new( \%borrower )->store();
195 #Send verification email
196 my $letter = C4::Letters::GetPreparedLetter(
198 letter_code => 'OPAC_REG_VERIFY',
199 lang => 'default', # Patron does not have a preferred language defined yet
201 borrower_modifications => $verification_token,
205 my $message_id = C4::Letters::EnqueueLetter(
208 message_transport_type => 'email',
209 to_address => $borrower{'email'},
211 C4::Context->preference('KohaAdminEmailAddress'),
214 C4::Letters::SendQueuedMessages({ message_id => $message_id });
217 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
219 template_name => "opac-registration-confirmation.tt",
222 authnotrequired => 1,
226 $borrower{password} ||= Koha::AuthUtils::generate_password(Koha::Patron::Categories->find($borrower{categorycode}));
227 my $consent_dt = delete $borrower{gdpr_proc_consent};
228 my $patron = Koha::Patron->new( \%borrower )->store;
229 Koha::Patron::Consent->new({ borrowernumber => $patron->borrowernumber, type => 'GDPR_PROCESSING', given_on => $consent_dt })->store if $consent_dt;
231 $patron->extended_attributes->filter_by_branch_limitations->delete;
232 $patron->extended_attributes($attributes);
233 if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
234 C4::Form::MessagingPreferences::handle_form_action(
236 { borrowernumber => $patron->borrowernumber },
239 C4::Context->preference('PatronSelfRegistrationDefaultCategory')
243 $template->param( password_cleartext => $patron->plain_text_password );
244 $template->param( borrower => $patron->unblessed );
246 # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
247 if ( C4::Context->preference("AutoEmailOpacUser") ) {
248 #look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead
249 my $emailaddr = $patron->notice_email_address;
250 # if we manage to find a valid email address, send notice
253 my $letter = GetPreparedLetter(
255 letter_code => 'ACCTDETAILS',
256 branchcode => $patron->branchcode,,
257 lang => $patron->lang || 'default',
259 'branches' => $patron->branchcode,
260 'borrowers' => $patron->borrowernumber,
265 my $message_id = EnqueueLetter(
268 borrowernumber => $patron->id,
269 to_address => $emailaddr,
270 message_transport_type => 'email'
273 SendQueuedMessages({ message_id => $message_id });
278 # FIXME Handle possible errors here
281 PatronSelfRegistrationAdditionalInstructions =>
282 C4::Context->preference(
283 'PatronSelfRegistrationAdditionalInstructions')
288 elsif ( $action eq 'update' ) {
290 my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
291 die "Wrong CSRF token"
292 unless Koha::Token->new->check_csrf({
293 session_id => scalar $cgi->cookie('CGISESSID'),
294 token => scalar $cgi->param('csrf_token'),
297 my %borrower = ParseCgiForBorrower($cgi);
298 $borrower{borrowernumber} = $borrowernumber;
300 my @empty_mandatory_fields = grep { $_ ne 'password' } # password is not required when editing personal details
301 ( CheckMandatoryFields( \%borrower, $action ), CheckMandatoryAttributes( \%borrower, $attributes ) );
302 my $invalidformfields = CheckForInvalidFields(\%borrower);
304 # Send back the data to the template
305 %borrower = ( %$borrower, %borrower );
307 if (@empty_mandatory_fields || @$invalidformfields) {
309 empty_mandatory_fields => \@empty_mandatory_fields,
310 invalid_form_fields => $invalidformfields,
311 borrower => \%borrower,
312 csrf_token => Koha::Token->new->generate_csrf({
313 session_id => scalar $cgi->cookie('CGISESSID'),
316 $template->param( patron_attribute_classes => GeneratePatronAttributesForm( $borrowernumber, $attributes ) );
318 $template->param( action => 'edit' );
321 my %borrower_changes = DelUnchangedFields( $borrowernumber, %borrower );
322 $borrower_changes{'changed_fields'} = join ',', keys %borrower_changes;
323 my $extended_attributes_changes = FilterUnchangedAttributes( $borrowernumber, $attributes );
325 if ( %borrower_changes || scalar @{$extended_attributes_changes} > 0 ) {
326 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
328 template_name => "opac-memberentry-update-submitted.tt",
331 authnotrequired => 1,
335 $borrower_changes{borrowernumber} = $borrowernumber;
336 $borrower_changes{extended_attributes} = to_json($extended_attributes_changes);
338 Koha::Patron::Modifications->search({ borrowernumber => $borrowernumber })->delete;
340 my $m = Koha::Patron::Modification->new( \%borrower_changes )->store();
341 #Automatically approve patron profile changes if set in syspref
343 if (C4::Context->preference('AutoApprovePatronProfileSettings')) {
344 # Need to get the object from database, otherwise it is not complete enough to allow deletion
345 # when approval has been performed.
346 my $tmp_m = Koha::Patron::Modifications->find({borrowernumber => $borrowernumber});
347 $tmp_m->approve() if $tmp_m;
350 my $patron = Koha::Patrons->find( $borrowernumber );
351 $template->param( borrower => $patron->unblessed );
354 my $patron = Koha::Patrons->find( $borrowernumber );
358 borrower => $patron->unblessed,
359 patron_attribute_classes => GeneratePatronAttributesForm( $borrowernumber, $attributes ),
360 csrf_token => Koha::Token->new->generate_csrf({
361 session_id => scalar $cgi->cookie('CGISESSID'),
367 elsif ( $action eq 'edit' ) { #Display logged in borrower's data
368 my $patron = Koha::Patrons->find( $borrowernumber );
369 my $borrower = $patron->unblessed;
372 borrower => $borrower,
373 hidden => GetHiddenFields( $mandatory, 'edit' ),
374 csrf_token => Koha::Token->new->generate_csrf({
375 session_id => scalar $cgi->cookie('CGISESSID'),
379 if (C4::Context->preference('OPACpatronimages')) {
380 $template->param( display_patron_image => 1 ) if $patron->image;
383 $template->param( patron_attribute_classes => GeneratePatronAttributesForm( $borrowernumber ) );
385 # Render self-registration page
386 $template->param( patron_attribute_classes => GeneratePatronAttributesForm() );
389 my $captcha = random_string("CCCCC");
390 my $patron_param = Koha::Patrons->find( $borrowernumber );
392 has_guarantor_flag => $patron_param->guarantor_relationships->guarantors->_resultset->count
397 captcha_digest => md5_base64($captcha),
398 patron => $patron_param
401 output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 };
403 sub GetHiddenFields {
404 my ( $mandatory, $action ) = @_;
407 my $BorrowerUnwantedField = $action eq 'edit' || $action eq 'update' ?
408 C4::Context->preference( "PatronSelfModificationBorrowerUnwantedField" ) :
409 C4::Context->preference( "PatronSelfRegistrationBorrowerUnwantedField" );
411 my @fields = split( /\|/, $BorrowerUnwantedField || q|| );
414 #Don't hide mandatory fields
415 next if $mandatory->{$_};
416 $hidden_fields{$_} = 1;
419 return \%hidden_fields;
422 sub GetMandatoryFields {
425 my %mandatory_fields;
427 my $BorrowerMandatoryField = $action eq 'edit' || $action eq 'update' ?
428 C4::Context->preference("PatronSelfModificationMandatoryField") :
429 C4::Context->preference("PatronSelfRegistrationBorrowerMandatoryField");
431 my @fields = split( /\|/, $BorrowerMandatoryField );
432 push @fields, 'gdpr_proc_consent' if C4::Context->preference('GDPR_Policy') && $action eq 'create';
435 $mandatory_fields{$_} = 1;
438 if ( $action eq 'create' || $action eq 'new' ) {
439 $mandatory_fields{'email'} = 1
440 if C4::Context->preference(
441 'PatronSelfRegistrationVerifyByEmail');
444 return \%mandatory_fields;
447 sub CheckMandatoryFields {
448 my ( $borrower, $action ) = @_;
450 my @empty_mandatory_fields;
452 my $mandatory_fields = GetMandatoryFields($action);
453 delete $mandatory_fields->{'cardnumber'};
455 foreach my $key ( keys %$mandatory_fields ) {
456 push( @empty_mandatory_fields, $key )
457 unless ( defined( $borrower->{$key} ) && $borrower->{$key} );
460 return @empty_mandatory_fields;
463 sub CheckMandatoryAttributes{
464 my ( $borrower, $attributes ) = @_;
466 my @empty_mandatory_fields;
468 for my $attribute (@$attributes ) {
469 my $attr = Koha::Patron::Attribute::Types->find($attribute->{code});
470 push @empty_mandatory_fields, $attribute->{code}
471 if $attr && $attr->mandatory && $attribute->{attribute} =~ m|^\s*$|;
474 return @empty_mandatory_fields;
477 sub CheckForInvalidFields {
478 my $borrower = shift;
480 if ($borrower->{'email'}) {
481 unless ( Koha::Email->is_valid($borrower->{email}) ) {
482 push(@invalidFields, "email");
483 } elsif ( C4::Context->preference("PatronSelfRegistrationEmailMustBeUnique") ) {
484 my $patrons_with_same_email = Koha::Patrons->search( # FIXME Should be search_limited?
486 email => $borrower->{email},
488 exists $borrower->{borrowernumber}
489 ? ( borrowernumber =>
490 { '!=' => $borrower->{borrowernumber} } )
495 if ( $patrons_with_same_email ) {
496 push @invalidFields, "duplicate_email";
498 } elsif ( C4::Context->preference("PatronSelfRegistrationConfirmEmail")
499 && $borrower->{'email'} ne $borrower->{'repeat_email'}
500 && !defined $borrower->{borrowernumber} ) {
501 push @invalidFields, "email_match";
503 # email passed all tests, so prevent attempting to store repeat_email
504 delete $borrower->{'repeat_email'};
506 if ($borrower->{'emailpro'}) {
507 push(@invalidFields, "emailpro") unless Koha::Email->is_valid($borrower->{'emailpro'});
509 if ($borrower->{'B_email'}) {
510 push(@invalidFields, "B_email") unless Koha::Email->is_valid($borrower->{'B_email'});
512 if ( defined $borrower->{'password'}
513 and $borrower->{'password'} ne $borrower->{'password2'} )
515 push( @invalidFields, "password_match" );
517 if ( $borrower->{'password'} ) {
518 my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $borrower->{password}, Koha::Patron::Categories->find($borrower->{categorycode}||C4::Context->preference('PatronSelfRegistrationDefaultCategory')) );
519 unless ( $is_valid ) {
520 push @invalidFields, 'password_too_short' if $error eq 'too_short';
521 push @invalidFields, 'password_too_weak' if $error eq 'too_weak';
522 push @invalidFields, 'password_has_whitespaces' if $error eq 'has_whitespaces';
526 return \@invalidFields;
529 sub ParseCgiForBorrower {
532 my $scrubber = C4::Scrubber->new();
535 foreach my $field ( $cgi->param ) {
536 if ( $field =~ '^borrower_' ) {
537 my ($key) = substr( $field, 9 );
538 if ( $field !~ '^borrower_password' ) {
539 $borrower{$key} = $scrubber->scrub( scalar $cgi->param($field) );
541 # Allow html characters for passwords
542 $borrower{$key} = $cgi->param($field);
547 if ( defined $borrower{'dateofbirth'} ) {
549 $dob_dt = eval { dt_from_string( $borrower{'dateofbirth'} ); }
550 if ( $borrower{'dateofbirth'} );
553 $borrower{'dateofbirth'} = output_pref( { dt => $dob_dt, dateonly => 1, dateformat => 'iso' } );
557 $borrower{'dateofbirth'} = undef;
561 # Replace checkbox 'agreed' by datetime in gdpr_proc_consent
562 $borrower{gdpr_proc_consent} = dt_from_string if $borrower{gdpr_proc_consent} && $borrower{gdpr_proc_consent} eq 'agreed';
564 delete $borrower{$_} for qw/borrowernumber date_renewed debarred debarredcomment flags privacy privacy_guarantor_fines privacy_guarantor_checkouts checkprevcheckout updated_on lastseen lang login_attempts overdrive_auth_token anonymized/; # See also members/memberentry.pl
565 delete $borrower{$_} for qw/dateenrolled dateexpiry borrowernotes opacnote sort1 sort2 sms_provider_id autorenew_checkouts gonenoaddress lost relationship/; # On OPAC only
566 delete $borrower{$_} for split( /\s*\|\s*/, C4::Context->preference('PatronSelfRegistrationBorrowerUnwantedField') || q{} );
571 sub DelUnchangedFields {
572 my ( $borrowernumber, %new_data ) = @_;
573 # get the mandatory fields so we can get the hidden fields
574 my $mandatory = GetMandatoryFields('edit');
575 my $patron = Koha::Patrons->find( $borrowernumber );
576 my $current_data = $patron->unblessed;
577 # get the hidden fields so we don't obliterate them should they have data patrons aren't allowed to modify
578 my $hidden_fields = GetHiddenFields($mandatory, 'edit');
581 foreach my $key ( keys %new_data ) {
582 next if defined($new_data{$key}) xor defined($current_data->{$key});
583 if ( !defined($new_data{$key}) || $current_data->{$key} eq $new_data{$key} || $hidden_fields->{$key} ) {
584 delete $new_data{$key};
594 foreach my $key ( keys %borrower ) {
595 delete $borrower{$key} unless $borrower{$key};
601 sub FilterUnchangedAttributes {
602 my ( $borrowernumber, $entered_attributes ) = @_;
604 my @patron_attributes = grep {$_->type->opac_editable ? $_ : ()} Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
606 my $patron_attribute_types;
607 foreach my $attr (@patron_attributes) {
608 $patron_attribute_types->{ $attr->code } += 1;
611 my $passed_attribute_types;
612 foreach my $attr (@{ $entered_attributes }) {
613 $passed_attribute_types->{ $attr->{ code } } += 1;
616 my @changed_attributes;
618 # Loop through the current patron attributes
619 foreach my $attribute_type ( keys %{ $patron_attribute_types } ) {
620 if ( $patron_attribute_types->{ $attribute_type } != $passed_attribute_types->{ $attribute_type } ) {
621 # count differs, overwrite all attributes for given type
622 foreach my $attr (@{ $entered_attributes }) {
623 push @changed_attributes, $attr
624 if $attr->{ code } eq $attribute_type;
627 # count matches, check values
629 foreach my $attr (grep { $_->code eq $attribute_type } @patron_attributes) {
631 unless any { $_->{ value } eq $attr->attribute } @{ $entered_attributes };
636 foreach my $attr (@{ $entered_attributes }) {
637 push @changed_attributes, $attr
638 if $attr->{ code } eq $attribute_type;
644 # Loop through passed attributes, looking for new ones
645 foreach my $attribute_type ( keys %{ $passed_attribute_types } ) {
646 if ( !defined $patron_attribute_types->{ $attribute_type } ) {
648 foreach my $attr (grep { $_->{code} eq $attribute_type } @{ $entered_attributes }) {
649 push @changed_attributes, $attr;
654 return \@changed_attributes;
657 sub GeneratePatronAttributesForm {
658 my ( $borrowernumber, $entered_attributes ) = @_;
660 # Get all attribute types and the values for this patron (if applicable)
661 my @types = grep { $_->opac_editable() or $_->opac_display } # FIXME filter using DBIC
662 Koha::Patron::Attribute::Types->search()->as_list();
663 if ( scalar(@types) == 0 ) {
667 my @displayable_attributes = grep { $_->type->opac_display ? $_ : () }
668 Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
670 my %attr_values = ();
672 # Build the attribute values list either from the passed values
673 # or taken from the patron itself
674 if ( defined $entered_attributes ) {
675 foreach my $attr (@$entered_attributes) {
676 push @{ $attr_values{ $attr->{code} } }, $attr->{value};
679 elsif ( defined $borrowernumber ) {
680 my @editable_attributes = grep { $_->type->opac_editable ? $_ : () } @displayable_attributes;
681 foreach my $attr (@editable_attributes) {
682 push @{ $attr_values{ $attr->code } }, $attr->attribute;
686 # Add the non-editable attributes (that don't come from the form)
687 foreach my $attr ( grep { !$_->type->opac_editable } @displayable_attributes ) {
688 push @{ $attr_values{ $attr->code } }, $attr->attribute;
691 # Find all existing classes
692 my @classes = sort( uniq( map { $_->class } @types ) );
695 foreach my $attr_type (@types) {
696 push @{ $items_by_class{ $attr_type->class() } }, {
698 # If editable, make sure there's at least one empty entry,
699 # to make the template's job easier
700 values => $attr_values{ $attr_type->code() } || ['']
702 unless !defined $attr_values{ $attr_type->code() }
703 and !$attr_type->opac_editable;
706 # Finally, build a list of containing classes
708 foreach my $class (@classes) {
709 next unless ( $items_by_class{$class} );
711 my $av = Koha::AuthorisedValues->search(
712 { category => 'PA_CLASS', authorised_value => $class } );
714 my $lib = $av->count ? $av->next->opac_description : $class;
719 items => $items_by_class{$class},
727 sub ParsePatronAttributes {
728 my ( $borrowernumber, $cgi ) = @_;
730 my @codes = $cgi->multi_param('patron_attribute_code');
731 my @values = $cgi->multi_param('patron_attribute_value');
733 my @editable_attribute_types
734 = map { $_->code } Koha::Patron::Attribute::Types->search({ opac_editable => 1 })->as_list;
736 my $ea = each_array( @codes, @values );
739 my $delete_candidates = {};
741 while ( my ( $code, $value ) = $ea->() ) {
742 if ( any { $_ eq $code } @editable_attribute_types ) {
743 # It is an editable attribute
744 if ( !defined($value) or $value eq '' ) {
745 $delete_candidates->{$code} = 1
746 unless $delete_candidates->{$code};
750 push @attributes, { code => $code, attribute => $value };
752 # 'code' is no longer a delete candidate
753 delete $delete_candidates->{$code}
754 if defined $delete_candidates->{$code};
759 foreach my $code ( keys %{$delete_candidates} ) {
760 if ( not $borrowernumber # self-registration
761 || Koha::Patron::Attributes->search({
762 borrowernumber => $borrowernumber, code => $code })->count > 0 )
764 push @attributes, { code => $code, attribute => '' }
765 unless any { $_->{code} eq $code } @attributes;