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);
43 $value .= $params->{$cgi_field.'_units'};
46 #warn "value of $cgi_field is $value\n";
54 'args_callback' => sub {
56 my( $cgi, $object ) = @_;
58 my $prefix = $object->action.'.';
60 map { my $option = $_;
61 #my $value = scalar( $cgi->param( "$prefix$option" ) );
62 my $value = join(',', $cgi->param( "$prefix$option" ) );
64 if ( $option eq 'reasonnum' && $value == -1 ) {
65 my $reason_prefix = $object->action . '_' . $option . '_new_';
66 my $new_reason = FS::reason->new;
67 foreach ( qw( reason_type reason unsuspend pkgpart
68 unsuspend_hold unused_credit ) ) {
69 $new_reason->set($_, $cgi->param("$reason_prefix$_"));
71 warn Dumper $new_reason;
72 my $error = $new_reason->insert;
73 die "error creating reason: $error" if $error;
74 $value = $new_reason->reasonnum;
76 ( $option => $value );
78 @{ $object->option_fields_listref };
81 'precheck_callback' => sub {
83 my $action = $cgi->param('action') or return;
84 my %actionfields = map { $_ =~ /^$action\.(.*)/; $1 => $cgi->param($_) }
85 grep { /^$action\./ } $cgi->param;
86 if ( exists($actionfields{'reasonnum'}) and
87 length($actionfields{'reasonnum'}) == 0 ) {
88 return 'Reason required';
90 if ( $cgi->param('_initialize') ) {
91 $cgi->param('disabled', 'Y');
94 my $balance_age_rx = qr/^(condition.+)\.balance_age\.age$/;
96 foreach my $param ( keys %{ $cgi->Vars() } ){
98 next unless ( $param =~ /$balance_age_rx/ );
99 next unless $cgi->param($1) eq 'balance_age';
101 my $errstr = FS::part_event::Condition::balance_age->
102 check_options( { age => $cgi->param($param),
103 age_units => $cgi->param("${param}_units") } );
105 return $errstr if $errstr;
110 'noerror_callback' => sub {
111 my ($cgi, $new) = @_;
112 if ( $cgi->param('_initialize') ) {
113 my $job = new FS::queue {
114 'job' => 'FS::part_event::process_initialize'
116 my $error = $job->insert('eventpart' => $new->eventpart);
117 warn "error queueing job: $error\n" if $error; # can't do anything else
122 'agent_null_right' => 'Edit global billing events',
128 unless $FS::CurrentUser::CurrentUser->access_right('Edit billing events')
129 || $FS::CurrentUser::CurrentUser->access_right('Edit global billing events');