use C4::Output;
use C4::Members;
use C4::Form::MessagingPreferences;
-use Koha::Borrower::Modifications;
+use Koha::Patrons;
+use Koha::Patron::Modifications;
use C4::Branch qw(GetBranchesLoop);
use C4::Scrubber;
use Email::Valid;
}
my $mandatory = GetMandatoryFields($action);
-my $hidden = GetHiddenFields($mandatory);
$template->param(
action => $action,
- hidden => $hidden,
+ hidden => GetHiddenFields( $mandatory, 'registration' ),
mandatory => $mandatory,
member_titles => GetTitles() || undef,
branches => GetBranchesLoop(),
my @empty_mandatory_fields = CheckMandatoryFields( \%borrower, $action );
my $invalidformfields = CheckForInvalidFields(\%borrower);
+ delete $borrower{'password2'};
+ my $cardnumber_error_code;
+ if ( !grep { $_ eq 'cardnumber' } @empty_mandatory_fields ) {
+ # No point in checking the cardnumber if it's missing and mandatory, it'll just generate a
+ # spurious length warning.
+ $cardnumber_error_code = checkcardnumber( $borrower{cardnumber}, $borrower{borrowernumber} );
+ }
+
+ if ( @empty_mandatory_fields || @$invalidformfields || $cardnumber_error_code ) {
+ if ( $cardnumber_error_code == 1 ) {
+ $template->param( cardnumber_already_exists => 1 );
+ } elsif ( $cardnumber_error_code == 2 ) {
+ $template->param( cardnumber_wrong_length => 1 );
+ }
- if (@empty_mandatory_fields || @$invalidformfields) {
$template->param(
empty_mandatory_fields => \@empty_mandatory_fields,
invalid_form_fields => $invalidformfields,
my $verification_token = md5_hex( \%borrower );
$borrower{'password'} = random_string("..........");
- Koha::Borrower::Modifications->new(
+ Koha::Patron::Modifications->new(
verification_token => $verification_token )
->AddModifications(\%borrower);
);
my $m =
- Koha::Borrower::Modifications->new(
+ Koha::Patron::Modifications->new(
borrowernumber => $borrowernumber );
$m->DelModifications;
}
$template->param(
- borrower => $borrower, );
+ borrower => $borrower,
+ guarantor => scalar Koha::Patrons->find($borrowernumber)->guarantor(),
+ hidden => GetHiddenFields( $mandatory, 'modification' ),
+ );
if (C4::Context->preference('OPACpatronimages')) {
my ($image, $dberror) = GetPatronImage($borrower->{borrowernumber});
output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 };
sub GetHiddenFields {
- my ($mandatory) = @_;
+ my ( $mandatory, $action ) = @_;
my %hidden_fields;
- my $BorrowerUnwantedField =
- C4::Context->preference("PatronSelfRegistrationBorrowerUnwantedField");
+ my $BorrowerUnwantedField = $action eq 'modification' ?
+ C4::Context->preference( "PatronSelfModificationBorrowerUnwantedField" ) :
+ C4::Context->preference( "PatronSelfRegistrationBorrowerUnwantedField" );
- my @fields = split( /\|/, $BorrowerUnwantedField );
+ my @fields = split( /\|/, $BorrowerUnwantedField || q|| );
foreach (@fields) {
next unless m/\w/o;
#Don't hide mandatory fields
}
sub CheckForInvalidFields {
+ my $minpw = C4::Context->preference('minPasswordLength');
my $borrower = shift;
my @invalidFields;
if ($borrower->{'email'}) {
if ($borrower->{'B_email'}) {
push(@invalidFields, "B_email") if (!Email::Valid->address($borrower->{'B_email'}));
}
+ if ( $borrower->{'password'} ne $borrower->{'password2'} ){
+ push(@invalidFields, "password_match");
+ }
+ if ( $borrower->{'password'} && $minpw && (length($borrower->{'password'}) < $minpw) ) {
+ push(@invalidFields, "password_invalid");
+ }
+ if ( $borrower->{'password'} ) {
+ push(@invalidFields, "password_spaces") if ($borrower->{'password'} =~ /^\s/ or $borrower->{'password'} =~ /\s$/);
+ }
+
return \@invalidFields;
}
my $dob_dt;
$dob_dt = eval { dt_from_string( $borrower{'dateofbirth'} ); }
- if ( defined( $borrower{'dateofbirth'} ) );
+ if ( $borrower{'dateofbirth'} );
- $borrower{'dateofbirth'} = output_pref ( { dt => $dob_dt, dateonly => 1, dateformat => 'iso' })
- if ( $dob_dt );
+ if ( $dob_dt ) {
+ $borrower{'dateofbirth'} = output_pref ( { dt => $dob_dt, dateonly => 1, dateformat => 'iso' } );
+ }
+ else {
+ # Trigger validation
+ $borrower{'dateofbirth'} = undef;
+ }
return %borrower;
}