summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2001-08-19 00:48:49 +0000
committerivan <ivan>2001-08-19 00:48:49 +0000
commite7b0bcbf0b1feff0e0e38d5858f512286a4d0ba7 (patch)
treef41d5c80dc1818f3a191e88924f3493a943af6d2 /FS
parentab2a71970ac434c3bf628af426d23d9b992fd816 (diff)
country fields will now accept names and change them to two-letter codes
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Record.pm24
-rw-r--r--FS/FS/cust_main.pm9
2 files changed, 26 insertions, 7 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index cf902e6a1..8dbd4aff3 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -6,6 +6,7 @@ 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);
@@ -821,6 +822,27 @@ sub ut_zip {
'';
}
+=item ut_country COLUMN
+
+Check/untaint country codes. Country names are changed to codes, if possible -
+see L<Locale::Country>.
+
+=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 +971,7 @@ sub DESTROY { return; }
=head1 VERSION
-$Id: Record.pm,v 1.23 2001-08-17 11:33:17 ivan Exp $
+$Id: Record.pm,v 1.24 2001-08-19 00:48:49 ivan Exp $
=head1 BUGS
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index c3a3e3fc6..3084b9058 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -500,6 +500,7 @@ sub check {
|| $self->ut_text('city')
|| $self->ut_textn('county')
|| $self->ut_textn('state')
+ || $self->ut_country('country')
|| $self->ut_anything('comments')
;
#barf. need message catalogs. i18n. etc.
@@ -523,8 +524,6 @@ sub check {
$self->ss("$1-$2-$3");
}
- $self->country =~ /^(\w\w)$/ or return "Illegal country: ". $self->country;
- $self->country($1);
unless ( qsearchs('cust_main_county', {
'country' => $self->country,
'state' => '',
@@ -565,13 +564,11 @@ sub check {
|| $self->ut_text('ship_city')
|| $self->ut_textn('ship_county')
|| $self->ut_textn('ship_state')
+ || $self->ut_country('ship_country')
;
return $error if $error;
#false laziness with above
- $self->ship_country =~ /^(\w\w)$/
- or return "Illegal ship_country: ". $self->ship_country;
- $self->ship_country($1);
unless ( qsearchs('cust_main_county', {
'country' => $self->ship_country,
'state' => '',
@@ -1351,7 +1348,7 @@ sub check_invoicing_list {
=head1 VERSION
-$Id: cust_main.pm,v 1.18 2001-08-17 10:55:04 ivan Exp $
+$Id: cust_main.pm,v 1.19 2001-08-19 00:48:49 ivan Exp $
=head1 BUGS