Bug 5549 : Make Koha::Calendar testable
[koha.git] / members / memberentry.pl
index c047873..d53f7f1 100755 (executable)
@@ -100,6 +100,13 @@ my @field_check=split(/\|/,$check_BorrowerMandatoryField);
 foreach (@field_check) {
        $template->param( "mandatory$_" => 1);    
 }
+# function to designate unwanted fields
+my $check_BorrowerUnwantedField=C4::Context->preference("BorrowerUnwantedField");
+@field_check=split(/\|/,$check_BorrowerUnwantedField);
+foreach (@field_check) {
+    next unless m/\w/o;
+       $template->param( "no$_" => 1);
+}
 $template->param( "add" => 1 ) if ( $op eq 'add' );
 $template->param( "duplicate" => 1 ) if ( $op eq 'duplicate' );
 $template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 );
@@ -285,6 +292,8 @@ if ($op eq 'save' || $op eq 'insert'){
   }
   
   my $password = $input->param('password');
+  my $password2 = $input->param('password2');
+  push @errors, "ERROR_password_mismatch" if ( $password ne $password2 );
   push @errors, "ERROR_short_password" if( $password && $minpw && $password ne '****' && (length($password) < $minpw) );
 
   if (C4::Context->preference('ExtendedPatronAttributes')) {
@@ -338,12 +347,19 @@ if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
             # if we manage to find a valid email address, send notice 
             if ($emailaddr) {
                 $newdata{emailaddr} = $emailaddr;
-                my $letter = getletter ('members', "ACCTDETAILS:$newdata{'branchcode'}") ;
-                # if $branch notice fails, then email a default notice instead.
-                $letter = getletter ('members', "ACCTDETAILS")  if !$letter;
-                SendAlerts ( 'members' , \%newdata , $letter ) if $letter
+                my $err;
+                eval {
+                    $err = SendAlerts ( 'members', \%newdata, "ACCTDETAILS" );
+                };
+                if ( $@ ) {
+                    $template->param(error_alert => $@);
+                } elsif ( defined $err->{error} and $err->{error} eq "no_email" ) {
+                    $template->{VARS}->{'error_alert'} = "no_email";
+                } else {
+                    $template->{VARS}->{'info_alert'} = 1;
+                }
             }
-        } 
+        }
 
                if ($data{'organisations'}){            
                        # need to add the members organisations