my $mandatory = GetMandatoryFields($action);
my @libraries = Koha::Libraries->search;
-if ( my @libraries_to_display = split '\|', C4::Context->preference('PatronSelfRegistrationLibraryList') ) {
- @libraries = map { my $b = $_; my $branchcode = $_->branchcode; grep { $_ eq $branchcode } @libraries_to_display ? $b : () } @libraries;
+if ( $action eq 'new'
+ && ( my @libraries_to_display = split '\|', C4::Context->preference('PatronSelfRegistrationLibraryList') )
+) {
+ @libraries = map {
+ my $b = $_;
+ my $branchcode = $_->branchcode;
+ ( grep { $_ eq $branchcode } @libraries_to_display ) ? $b : ()
+ } @libraries;
}
my ( $min, $max ) = C4::Members::get_cardnumber_length();
if ( defined $min ) {
my $attribute = Koha::Patron::Attribute->new($attr);
eval {$attribute->check_unique_id};
if ( $@ ) {
- my $attr_info = C4::Members::AttributeTypes->fetch($attr->{code});
+ my $attr_type = Koha::Patron::Attribute::Types->find($attr->{code});
$template->param(
extended_unique_id_failed_code => $attr->{code},
extended_unique_id_failed_value => $attr->{attribute},
- extended_unique_id_failed_description => $attr_info->description()
+ extended_unique_id_failed_description => $attr_type->description,
);
$conflicting_attribute = 1;
}
%borrower = DelEmptyFields(%borrower);
- my @empty_mandatory_fields = CheckMandatoryFields( \%borrower, $action );
+ my @empty_mandatory_fields = (CheckMandatoryFields( \%borrower, $action ), CheckMandatoryAttributes( \%borrower, $attributes ) );
my $invalidformfields = CheckForInvalidFields(\%borrower);
delete $borrower{'password2'};
my $cardnumber_error_code;
$borrower{borrowernumber} = $borrowernumber;
my @empty_mandatory_fields =
- CheckMandatoryFields( \%borrower, $action );
+ ( CheckMandatoryFields( \%borrower, $action ), CheckMandatoryAttributes( \%borrower, $attributes ) );
my $invalidformfields = CheckForInvalidFields(\%borrower);
# Send back the data to the template
return @empty_mandatory_fields;
}
+sub CheckMandatoryAttributes{
+ my ( $borrower, $attributes ) = @_;
+
+ my @empty_mandatory_fields;
+
+ for my $attribute (@$attributes ) {
+ my $attr = Koha::Patron::Attribute::Types->find($attribute->{code});
+ push @empty_mandatory_fields, $attribute->{code}
+ if $attr && $attr->mandatory && $attribute->{attribute} =~ m|^\s*$|;
+ }
+
+ return @empty_mandatory_fields;
+}
+
sub CheckForInvalidFields {
my $borrower = shift;
my @invalidFields;
if ( $patrons_with_same_email ) {
push @invalidFields, "duplicate_email";
}
+ } elsif ( C4::Context->preference("PatronSelfRegistrationConfirmEmail")
+ && $borrower->{'email'} ne $borrower->{'repeat_email'}
+ && !defined $borrower->{borrowernumber} ) {
+ push @invalidFields, "email_match";
}
+ # email passed all tests, so prevent attempting to store repeat_email
+ delete $borrower->{'repeat_email'};
}
if ($borrower->{'emailpro'}) {
push(@invalidFields, "emailpro") if (!Email::Valid->address($borrower->{'emailpro'}));
}
}
- my $dob_dt;
- $dob_dt = eval { dt_from_string( $borrower{'dateofbirth'} ); }
- if ( $borrower{'dateofbirth'} );
+ if ( defined $borrower{'dateofbirth'} ) {
+ my $dob_dt;
+ $dob_dt = eval { dt_from_string( $borrower{'dateofbirth'} ); }
+ if ( $borrower{'dateofbirth'} );
- if ( $dob_dt ) {
- $borrower{'dateofbirth'} = output_pref ( { dt => $dob_dt, dateonly => 1, dateformat => 'iso' } );
- }
- else {
- # Trigger validation
- $borrower{'dateofbirth'} = undef;
+ if ( $dob_dt ) {
+ $borrower{'dateofbirth'} = output_pref( { dt => $dob_dt, dateonly => 1, dateformat => 'iso' } );
+ }
+ else {
+ # Trigger validation
+ $borrower{'dateofbirth'} = undef;
+ }
}
# Replace checkbox 'agreed' by datetime in gdpr_proc_consent
}
foreach my $code ( keys %{$delete_candidates} ) {
- if ( Koha::Patron::Attributes->search({
+ if ( not $borrowernumber # self-registration
+ || Koha::Patron::Attributes->search({
borrowernumber => $borrowernumber, code => $code })->count > 0 )
{
push @attributes, { code => $code, attribute => '' }