i18
authorivan <ivan>
Tue, 27 Jun 2000 12:15:37 +0000 (12:15 +0000)
committerivan <ivan>
Tue, 27 Jun 2000 12:15:37 +0000 (12:15 +0000)
FS/FS/Record.pm
FS/FS/cust_main.pm

index 69913c1..12cc77e 100644 (file)
@@ -8,7 +8,6 @@ use Carp qw(carp cluck croak confess);
 use File::CounterFile;
 use FS::UID qw(dbh checkruid swapuid getotaker datasrc driver_name);
 use FS::dbdef;
-use diagnostics;
 
 @ISA = qw(Exporter);
 @EXPORT_OK = qw(dbh fields hfields qsearch qsearchs dbdef);
@@ -694,25 +693,32 @@ sub ut_alphan {
   '';
 }
 
-=item ut_phonen COLUMN
+=item ut_phonen COLUMN [ COUNTRY ]
 
 Check/untaint phone numbers.  May be null.  If there is an error, returns
 the error, otherwise returns false.
 
+Takes an optional two-letter ISO country code; without it or with unsupported
+countries, ut_phonen simply calls ut_alphan.
+
 =cut
 
 sub ut_phonen {
-  my($self,$field)=@_;
+  my( $self, $field, $country ) = @_;
+  return $self->ut_alphan($field) unless defined $country;
   my $phonen = $self->getfield($field);
   if ( $phonen eq '' ) {
     $self->setfield($field,'');
-  } else {
+  } elsif ( $country eq 'US' ) {
     $phonen =~ s/\D//g;
     $phonen =~ /^(\d{3})(\d{3})(\d{4})(\d*)$/
       or return "Illegal (phone) $field: ". $self->getfield($field);
     $phonen = "$1-$2-$3";
     $phonen .= " x$4" if $4;
     $self->setfield($field,$phonen);
+  } else {
+    warn "don't know how to check phone numbers for country $country";
+    return $self->ut_alphan($field);
   }
   '';
 }
@@ -841,7 +847,7 @@ sub hfields {
 
 =head1 VERSION
 
-$Id: Record.pm,v 1.6 2000-06-27 11:29:52 ivan Exp $
+$Id: Record.pm,v 1.7 2000-06-27 12:15:37 ivan Exp $
 
 =head1 BUGS
 
index 2a8a8b7..b863748 100644 (file)
@@ -312,9 +312,6 @@ sub check {
     || $self->ut_text('city')
     || $self->ut_textn('county')
     || $self->ut_textn('state')
-    || $self->ut_phonen('daytime')
-    || $self->ut_phonen('night')
-    || $self->ut_phonen('fax')
   ;
   return $error if $error;
 
@@ -357,7 +354,14 @@ sub check {
       } );
   }
 
-  $self->zip =~ /^\s*(\w[\w\-\s]{3,8}\w)\s*$/
+  $error =
+    $self->ut_phonen('daytime', $self->country)
+    || $self->ut_phonen('night', $self->country)
+    || $self->ut_phonen('fax', $self->country)
+  ;
+  return $error if $error;
+
+  $self->zip =~ /^\s*(\w[\w\-\s]{2,8}\w)\s*$/
     or return "Illegal zip: ". $self->zip;
   $self->zip($1);
 
@@ -995,7 +999,7 @@ sub check_invoicing_list {
 
 =head1 VERSION
 
-$Id: cust_main.pm,v 1.6 2000-06-24 00:28:30 ivan Exp $
+$Id: cust_main.pm,v 1.7 2000-06-27 12:15:37 ivan Exp $
 
 =head1 BUGS