X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=5048e4407e4dff457a62ee94394f2dfaae0fbd70;hb=9ab6c15b92d4cf7935f752fd5408d70e494e0f0b;hp=e646b399e6ca0c46c82ec5b8252e73e30e7c26dc;hpb=f3729cae00c3282bb34ff071f0dd5f9bcd5ce9e1;p=freeside.git diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index e646b399e..5048e4407 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -556,8 +556,8 @@ sub qsearch { # Check for encrypted fields and decrypt them. ## only in the local copy, not the cached object no warnings 'deprecated'; # XXX silence the warning for now - if ( $conf_encryption - && eval 'defined(@FS::'. $table . '::encrypted_fields)' ) { + if ( $conf_encryption + && eval '@FS::'. $table . '::encrypted_fields' ) { foreach my $record (@return) { foreach my $field (eval '@FS::'. $table . '::encrypted_fields') { next if $field eq 'payinfo' @@ -765,8 +765,8 @@ sub _from_hashref { # Check for encrypted fields and decrypt them. ## only in the local copy, not the cached object - if ( $conf_encryption - && eval 'defined(@FS::'. $table . '::encrypted_fields)' ) { + if ( $conf_encryption + && eval '@FS::'. $table . '::encrypted_fields' ) { foreach my $record (@return) { foreach my $field (eval '@FS::'. $table . '::encrypted_fields') { next if $field eq 'payinfo' @@ -2210,7 +2210,11 @@ sub _h_statement { "INSERT INTO h_". $self->table. " ( ". join(', ', qw(history_date history_user history_action), @fields ). ") VALUES (". - join(', ', $time, dbh->quote(getotaker()), dbh->quote($action), @values). + join(', ', $time, + dbh->quote($FS::CurrentUser::CurrentUser->username), + dbh->quote($action), + @values + ). ")" ; } @@ -2995,6 +2999,60 @@ sub ut_enumn { : ''; } +=item ut_date COLUMN + +Check/untaint a column containing a date string. + +Date will be normalized to YYYY-MM-DD format + +=cut + +sub ut_date { + my ( $self, $field ) = @_; + my $value = $self->getfield( $field ); + + my @date = split /[\-\/]/, $value; + if ( scalar(@date) == 3 ) { + @date = @date[2,0,1] if $date[2] >= 1900; + + local $@; + my $ymd; + eval { + # DateTime will die given invalid date + $ymd = DateTime->new( + year => $date[0], + month => $date[1], + day => $date[2], + )->ymd('-'); + }; + + unless( $@ ) { + $self->setfield( $field, $ymd ) unless $value eq $ymd; + return ''; + } + + } + return "Illegal (date) field $field: $value"; +} + +=item ut_daten COLUMN + +Check/untaint a column containing a date string. + +Column may be null. + +Date will be normalized to YYYY-MM-DD format + +=cut + +sub ut_daten { + my ( $self, $field ) = @_; + + $self->getfield( $field ) =~ /^()$/ + ? $self->setfield( $field, '' ) + : $self->ut_date( $field ); +} + =item ut_flag COLUMN Check/untaint a column if it contains either an empty string or 'Y'. This