diff options
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Mason.pm | 2 | ||||
-rw-r--r-- | FS/FS/part_event/Condition.pm | 17 | ||||
-rw-r--r-- | FS/FS/part_event/Condition/signupdate.pm | 48 |
3 files changed, 67 insertions, 0 deletions
diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm index 6cc32bd04..63eb47cab 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -546,6 +546,8 @@ sub mason_interps { ${$_[0]} =~ s/(['\\])/\\$1/g; ${$_[0]} =~ s/\r/\\r/g; ${$_[0]} =~ s/\n/\\n/g; + # prevent premature termination of the script + ${$_[0]} =~ s[</script>][<\\/script>]ig; ${$_[0]} = "'". ${$_[0]}. "'"; }; diff --git a/FS/FS/part_event/Condition.pm b/FS/FS/part_event/Condition.pm index 914256f45..b969cf6f8 100644 --- a/FS/FS/part_event/Condition.pm +++ b/FS/FS/part_event/Condition.pm @@ -269,6 +269,23 @@ sub option_label { =back +=item option_type OPTION + +Returns the type of the option, as a string: 'text', 'money', 'date', +or 'freq'. + +=cut + +sub option_type { + my( $self, $optionname ) = @_; + + my %option_fields = $self->option_fields; + + ref( $option_fields{$optionname} ) + ? $option_fields{$optionname}->{'type'} + : 'text' +} + =item option_age_from OPTION FROM_TIMESTAMP Retreives a condition option, parses it from a frequency (such as "1d", "1w" or diff --git a/FS/FS/part_event/Condition/signupdate.pm b/FS/FS/part_event/Condition/signupdate.pm new file mode 100644 index 000000000..30613a2ce --- /dev/null +++ b/FS/FS/part_event/Condition/signupdate.pm @@ -0,0 +1,48 @@ +package FS::part_event::Condition::signupdate; + +use strict; +use base qw( FS::part_event::Condition ); +use FS::Record qw(str2time_sql str2time_sql_closing); +use Date::Parse 'str2time'; + +sub description { 'Customer signed up during date range' } + +sub option_fields { + ( + # actually stored as strings + 'start' => { label => 'First day', + type => 'date', + format => '%Y-%m-%d', }, + 'end' => { label => 'Last day', + type => 'date', + format => '%Y-%m-%d', }, + ); +} + +sub condition { + + my($self, $object, %opt) = @_; + + my $cust_main = $self->cust_main($object); + my $start = $self->option('start'); + my $end = $self->option('end'); + + (!$start or $cust_main->signupdate >= str2time($start)) and + (!$end or $cust_main->signupdate < str2time($end) + 86400); +} + +sub condition_sql { + my( $class, $table, %opt ) = @_; + return 'true' if $opt{'driver_name'} ne 'Pg'; + + my $start = $class->condition_sql_option('start'); + my $end = $class->condition_sql_option('end'); + + $start = "$start IS NULL OR cust_main.signupdate >=" . + str2time_sql . "($start)::timestamp" . str2time_sql_closing; + $end = "$end IS NULL OR cust_main.signupdate < 86400 + " . + str2time_sql . "($end)::timestamp" . str2time_sql_closing; + "($start) AND ($end)"; +} + +1; |