use Exporter;
use Carp qw(carp cluck croak confess);
use Scalar::Util qw( blessed );
+use File::Slurp qw( slurp );
use File::CounterFile;
-use Locale::Country;
use Text::CSV_XS;
-use File::Slurp qw( slurp );
use DBI qw(:sql_types);
use DBIx::DBSchema 0.38;
-use FS::UID qw(dbh getotaker datasrc driver_name);
+use Locale::Country;
+use Locale::Currency;
+use NetAddr::IP; # for validation
+use FS::UID qw(dbh datasrc driver_name);
use FS::CurrentUser;
use FS::Schema qw(dbdef);
use FS::SearchCache;
use FS::Msgcat qw(gettext);
-use NetAddr::IP; # for validation
-use Data::Dumper;
#use FS::Conf; #dependency loop bs, in install_callback below instead
use FS::part_virtual_field;
# grep defined( $record->{$_} ) && $record->{$_} ne '', @fields
# ) or croak "Error executing \"$statement\": ". $sth->errstr;
- $sth->execute or croak "Error executing \"$statement\": ". $sth->errstr;
+ my $ok = $sth->execute;
+ if (!$ok) {
+ my $error = "Error executing \"$statement\"";
+ $error .= ' (' . join(', ', map {"'$_'"} @value) . ')' if @value;
+ $error .= ': '. $sth->errstr;
+ croak $error;
+ }
my $table = $stable[0];
my $pkey = '';
=cut
+use Data::Dumper;
sub batch_import {
my $param = shift;
my $data = slurp($file);
my $asn_output = $parser->decode( $data )
- or die "No ". $asn_format->{'macro'}. " found\n";
+ or return "No ". $asn_format->{'macro'}. " found\n";
$asn_header_buffer = &{ $asn_format->{'header_buffer'} }( $asn_output );
last unless scalar(@buffer);
my $row = shift @buffer;
+ &{ $asn_format->{row_callback} }( $row, $asn_header_buffer )
+ if $asn_format->{row_callback};
foreach my $key ( keys %{ $asn_format->{map} } ) {
$hash{$key} = &{ $asn_format->{map}{$key} }( $row, $asn_header_buffer );
}
return "Empty file!";
}
- $dbh->commit or die $dbh->errstr if $oldAutoCommit;;
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
''; #no error
my @values = map { _quote( $self->getfield($_), $self->table, $_) } @fields;
"INSERT INTO h_". $self->table. " ( ".
- join(', ', qw(history_date history_user history_action), @fields ).
+ join(', ', qw(history_date history_usernum history_action), @fields ).
") VALUES (".
- join(', ', $time, dbh->quote(getotaker()), dbh->quote($action), @values).
+ join(', ', $time,
+ $FS::CurrentUser::CurrentUser->usernum,
+ dbh->quote($action),
+ @values
+ ).
")"
;
}
#warn "field $field is tainted" if is_tainted($field);
my($counter) = new File::CounterFile "$table.$field",0;
-# hack for web demo
-# getotaker() =~ /^([\w\-]{1,16})$/ or die "Illegal CGI REMOTE_USER!";
-# my($user)=$1;
-# my($counter) = new File::CounterFile "$user/$table.$field",0;
-# endhack
my $index = $counter->inc;
$index = $counter->inc while qsearchs($table, { $field=>$index } );
$self->ut_money($field);
}
+=item ut_currencyn COLUMN
+
+Check/untaint currency indicators, such as USD or EUR. May be null. If there
+is an error, returns the error, otherwise returns false.
+
+=cut
+
+sub ut_currencyn {
+ my($self, $field) = @_;
+ if ($self->getfield($field) eq '') { #can be null
+ $self->setfield($field, '');
+ return '';
+ }
+ $self->ut_currency($field);
+}
+
+=item ut_currency COLUMN
+
+Check/untaint currency indicators, such as USD or EUR. May not be null. If
+there is an error, returns the error, otherwise returns false.
+
+=cut
+
+sub ut_currency {
+ my($self, $field) = @_;
+ my $value = uc( $self->getfield($field) );
+ if ( code2currency($value) ) {
+ $self->setfield($value);
+ } else {
+ return "Unknown currency $value";
+ }
+
+ '';
+}
+
=item ut_text COLUMN
Check/untaint text. Alphanumerics, spaces, and the following punctuation