X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=2c745b4137a599ac31749ed340a4a2a5b40ee081;hp=6409da33d68549996d1299840bc6e1e5ab746f45;hb=6ef34dda51afba96d8dc6c4dd72427c3d4003945;hpb=aff324b078531b8ab82e692a2c182d8f1ae0c932 diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 6409da33d..2c745b413 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -6,8 +6,9 @@ use subs qw(reload_dbdef); use Exporter; use Carp qw(carp cluck croak confess); use File::CounterFile; +use Locale::Country; use DBIx::DBSchema; -use FS::UID qw(dbh checkruid swapuid getotaker datasrc driver_name); +use FS::UID qw(dbh checkruid getotaker datasrc driver_name); @ISA = qw(Exporter); @EXPORT_OK = qw(dbh fields hfields qsearch qsearchs dbdef); @@ -565,7 +566,6 @@ sub unique { #warn "table $table is tainted" if is_tainted($table); #warn "field $field is tainted" if is_tainted($field); - &swapuid; my($counter) = new File::CounterFile "$table.$field",0; # hack for web demo # getotaker() =~ /^([\w\-]{1,16})$/ or die "Illegal CGI REMOTE_USER!"; @@ -576,7 +576,6 @@ sub unique { my($index)=$counter->inc; $index=$counter->inc while qsearchs($table,{$field=>$index}); #just in case - &swapuid; $index =~ /^(\d*)$/; $index=$1; @@ -730,7 +729,7 @@ sub ut_phonen { my $phonen = $self->getfield($field); if ( $phonen eq '' ) { $self->setfield($field,''); - } elsif ( $country eq 'US' ) { + } elsif ( $country eq 'US' || $country eq 'CA' ) { $phonen =~ s/\D//g; $phonen =~ /^(\d{3})(\d{3})(\d{4})(\d*)$/ or return "Illegal (phone) $field: ". $self->getfield($field); @@ -739,7 +738,7 @@ sub ut_phonen { $self->setfield($field,$phonen); } else { warn "don't know how to check phone numbers for country $country"; - return $self->ut_alphan($field); + return $self->ut_textn($field); } ''; } @@ -821,6 +820,27 @@ sub ut_zip { ''; } +=item ut_country COLUMN + +Check/untaint country codes. Country names are changed to codes, if possible - +see L. + +=cut + +sub ut_country { + my( $self, $field ) = @_; + unless ( $self->getfield($field) =~ /^(\w\w)$/ ) { + if ( $self->getfield($field) =~ /^([\w \,\.\(\)\']+)$/ + && country2code($1) ) { + $self->setfield($field,uc(country2code($1))); + } + } + $self->getfield($field) =~ /^(\w\w)$/ + or return "Illegal (country) $field: ". $self->getfield($field); + $self->setfield($field,uc($1)); + ''; +} + =item ut_anything COLUMN Untaints arbitrary data. Be careful. @@ -949,7 +969,7 @@ sub DESTROY { return; } =head1 VERSION -$Id: Record.pm,v 1.21 2001-08-11 05:50:52 ivan Exp $ +$Id: Record.pm,v 1.25 2001-08-21 09:34:13 ivan Exp $ =head1 BUGS