X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=42af68ca582dca2e8d3137dd517b5cc42340e4d3;hb=821f900c5a594cdf3cff082e5d527eade23f2e18;hp=252b760bf9033e7b1958d3a4ac395ed44130ee7f;hpb=27ed323fad9fca12f507a524e1788fb37e36501e;p=freeside.git diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 252b760bf..42af68ca5 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -1618,11 +1618,12 @@ sub batch_import { my $count; my $parser; my @buffer = (); + my $asn_header_buffer; if ( $type eq 'csv' || $type eq 'fixedlength' ) { if ( $type eq 'csv' ) { - my %attr = (); + my %attr = ( 'binary' => 1, ); $attr{sep_char} = $sep_char if $sep_char; $parser = new Text::CSV_XS \%attr; @@ -1692,6 +1693,8 @@ sub batch_import { my $asn_output = $parser->decode( $data ) or die "No ". $asn_format->{'macro'}. " found\n"; + $asn_header_buffer = &{ $asn_format->{'header_buffer'} }( $asn_output ); + my $rows = &{ $asn_format->{'arrayref'} }( $asn_output ); $count = @buffer = @$rows; @@ -1786,7 +1789,7 @@ sub batch_import { last unless scalar(@buffer); my $row = shift @buffer; foreach my $key ( keys %{ $asn_format->{map} } ) { - $hash{$key} = &{ $asn_format->{map}{$key} }( $row ); + $hash{$key} = &{ $asn_format->{map}{$key} }( $row, $asn_header_buffer ); } } else { @@ -2088,11 +2091,18 @@ is an error, returns the error, otherwise returns false. sub ut_money { my($self,$field)=@_; - $self->setfield($field, 0) if $self->getfield($field) eq ''; - $self->getfield($field) =~ /^\s*(\-)?\s*(\d*)(\.\d{2})?\s*$/ - or return "Illegal (money) $field: ". $self->getfield($field); - #$self->setfield($field, "$1$2$3" || 0); - $self->setfield($field, ( ($1||''). ($2||''). ($3||'') ) || 0); + + if ( $self->getfield($field) eq '' ) { + $self->setfield($field, 0); + } elsif ( $self->getfield($field) =~ /^\s*(\-)?\s*(\d*)(\.\d{1})\s*$/ ) { + #handle one decimal place without barfing out + $self->setfield($field, ( ($1||''). ($2||''). ($3.'0') ) || 0); + } elsif ( $self->getfield($field) =~ /^\s*(\-)?\s*(\d*)(\.\d{2})?\s*$/ ) { + $self->setfield($field, ( ($1||''). ($2||''). ($3||'') ) || 0); + } else { + return "Illegal (money) $field: ". $self->getfield($field); + } + ''; } @@ -2503,10 +2513,29 @@ sub ut_name { # warn "ut_name allowed alphanumerics: +(sort grep /\w/, map { chr() } 0..255), "\n"; $self->getfield($field) =~ /^([\w \,\.\-\']+)$/ or return gettext('illegal_name'). " $field: ". $self->getfield($field); - $self->setfield($field,$1); + my $name = $1; + $name =~ s/^\s+//; + $name =~ s/\s+$//; + $name =~ s/\s+/ /g; + $self->setfield($field, $name); ''; } +=item ut_namen COLUMN + +Check/untaint proper names; allows alphanumerics, spaces and the following +punctuation: , . - ' + +May not be null. + +=cut + +sub ut_namen { + my( $self, $field ) = @_; + return $self->setfield($field, '') if $self->getfield($field) =~ /^$/; + $self->ut_name($field); +} + =item ut_zip COLUMN Check/untaint zip codes.