1 <% include( 'elements/process.html',
3 'table' => 'part_event',
4 'viewall_dir' => 'browse',
7 'link_table' => 'part_event_condition',
8 'num_col' => 'eventpart',
9 'name_col' => 'conditionname',
10 'names_list' => [ FS::part_event_condition->all_conditionnames() ],
11 'param_style' => 'name_colN values',
12 'args_callback' => sub { # FS/FS/m2name_Common.pm
13 my( $object, $prefix, $params, $listref ) = @_;
14 #warn "$object $prefix $params $listref\n";
16 my $cond = $object->conditionname;
18 my %option_fields = $object->option_fields;
23 my $cgi_field = "$prefix$cond.$field";
25 my $value = $params->{$cgi_field};
27 my $info = $option_fields{$_};
28 $info = { label=>$info, type=>'text' }
31 if ( $info->{'type'} =~
32 /^(select|checkbox)-?multiple$/
33 or $info->{'type'} =~ /^select/
34 && $info->{'multiple'}
37 #special processing for compound fields
38 $value = { map { $_ => 1 }
41 } elsif ( $info->{'type'} eq 'freq' ) {
42 $value = '0' if !length($value) and !$info->{'allow_blank'};
43 $value = '0' if $value =~ /[^\d]/;
44 $value .= $params->{$cgi_field.'_units'} if length($value);
47 #warn "value of $cgi_field is $value\n";
55 'args_callback' => sub {
57 my( $cgi, $object ) = @_;
59 my $prefix = $object->action.'.';
61 map { my $option = $_;
62 #my $value = scalar( $cgi->param( "$prefix$option" ) );
63 my $value = join(',', $cgi->param( "$prefix$option" ) );
65 if ( $option eq 'reasonnum' && $value == -1 ) {
66 my $reason_prefix = $object->action . '_' . $option . '_new_';
67 my $new_reason = FS::reason->new;
68 foreach ( qw( reason_type reason unsuspend pkgpart
69 unsuspend_hold unused_credit ) ) {
70 $new_reason->set($_, $cgi->param("$reason_prefix$_"));
72 warn Dumper $new_reason;
73 my $error = $new_reason->insert;
74 die "error creating reason: $error" if $error;
75 $value = $new_reason->reasonnum;
77 ( $option => $value );
79 @{ $object->option_fields_listref || [] };
82 'precheck_callback' => sub {
84 my $action = $cgi->param('action') or return;
85 my %actionfields = map { $_ =~ /^$action\.(.*)/; $1 => scalar($cgi->param($_)) }
86 grep { /^$action\./ } $cgi->param;
87 if ( exists($actionfields{'reasonnum'}) and
88 length($actionfields{'reasonnum'}) == 0 ) {
89 return 'Reason required';
91 if ( $cgi->param('_initialize') ) {
92 $cgi->param('disabled', 'Y');
95 my $balance_age_rx = qr/^(condition.+)\.balance_age\.age$/;
97 foreach my $param ( keys %{ $cgi->Vars() } ){
99 next unless ( $param =~ /$balance_age_rx/ );
100 next unless $cgi->param($1) eq 'balance_age';
102 my $errstr = FS::part_event::Condition::balance_age->
103 check_options( { age => scalar($cgi->param($param)),
104 age_units => scalar($cgi->param("${param}_units")),
108 return $errstr if $errstr;
113 'noerror_callback' => sub {
114 my ($cgi, $new) = @_;
115 if ( $cgi->param('_initialize') ) {
116 my $job = new FS::queue {
117 'job' => 'FS::part_event::process_initialize'
119 my $error = $job->insert('eventpart' => $new->eventpart);
120 warn "error queueing job: $error\n" if $error; # can't do anything else
125 'agent_null_right' => 'Edit global billing events',
131 unless $FS::CurrentUser::CurrentUser->access_right('Edit billing events')
132 || $FS::CurrentUser::CurrentUser->access_right('Edit global billing events');