enable CardFortress in test database, #71513
[freeside.git] / httemplate / browse / part_event.html
1 <% include( 'elements/browse.html',
2                 'title'              => 'Billing Event Definitions',
3                 'html_init'          => $html_init,
4                 'name'               => 'billing event definitions',
5                 'disableable'        => 1,
6                 'disabled_statuspos' => 2,
7                 'agent_virt'         => 1,
8                 'agent_null_right'   => 'Edit global billing events',
9                 'agent_pos'          => 3,
10                 'query'              => { 'select'    => 'part_event.*',
11                                           'table'     => 'part_event',
12                                           'addl_from' => $join_conditions,
13                                           'hashref'   => {},
14                                           'order_by'  => $order_conditions,
15                                         },
16                 'count_query'        => $count_query,
17                 'header'             => [ '#',
18                                           'Event',
19                                           'Type',
20                                           'Check freq.',
21                                           'Conditions',
22                                           'Action',
23                                         ],
24                 'fields'             => [ 'eventpart',
25                                           $event_sub,
26                                           $eventtable_sub,
27                                           $check_freq_sub,
28                                           $conditions_sub,
29                                           $action_sub,
30                                         ],
31                 'links'              => [ $link,
32                                           '',
33                                           '',
34                                           '',
35                                           '',
36                                           '',
37                                         ],
38                 'align'              => 'rllccc',
39           )
40 %>
41 <%once>
42
43 my $link = [ $p.'edit/part_event.html?', 'eventpart' ];
44
45 my $event_sub = sub {
46   my $part_event = shift;
47   my $onclick = include('/elements/popup_link_onclick.html',
48     action      => $p.'view/part_event-targets.html?eventpart='.
49                     $part_event->eventpart,
50     actionlabel => 'Event query', #no, XSS - '.$part_event->event,
51     width       => 650,
52     height      => 420,
53     close_text  => 'Close',
54   );
55   [#rows
56     [#subcolumns
57       {
58         'data'       => encode_entities($part_event->event),
59         'link'       => $p.'edit/part_event.html?'.$part_event->eventpart,
60       },
61       {
62         'data'       => '(query) ',
63         'size'       => '-1',
64         'data_style' => 'b',
65         'onclick'    => $onclick,
66       },
67     ],
68   ];
69 };
70
71 my $eventtable_labels = FS::part_event->eventtable_labels;
72 my $eventtable_sub = sub { $eventtable_labels->{ shift->eventtable }; };
73
74 my $check_freq_labels = FS::part_event->check_freq_labels;
75 my $check_freq_sub = sub { $check_freq_labels->{ shift->check_freq }; };
76
77 my $conditions_sub = sub {
78   my $part_event = shift;
79   my $addl = 0;
80
81   [
82     map {
83            my $part_event_condition = $_;
84            my %options = $part_event_condition->options;
85
86            [
87              {
88                'data'       => $part_event_condition->description,
89                'width'      => '100%',
90                'align'      => 'center',
91                'colspan'    => 2,
92                'style'      => ( $addl++ ? 'border-top: 1px solid gray' : '' ), 
93              },
94            ],
95
96            map {
97
98              my $data = $options{$_};
99              if ( ref($data) ) {
100                $data = join('<BR>', keys %$data); #XXX display hash values too?
101              }
102
103              [
104                {
105                  'data'   => $part_event_condition->option_label($_). ':',
106                  'align'  => 'right',
107                  'valign' => 'top',
108                  'size'   => '-1',
109                },
110                {
111                  'data'  => $data,
112                  'align' => 'left',
113                  'size'  => '-1',
114                },
115              ];
116
117            } keys %options
118
119         }
120         $part_event->part_event_condition
121
122   ];
123
124 };
125
126 my $action_sub = sub {
127   my $part_event = shift;
128
129   my %options = $part_event->options;
130   
131   [
132
133     [
134       {
135         'data'       => $part_event->description,
136         'width'      => '100%',
137         'align'      => 'center',
138         'colspan'    => 2,
139       },
140     ],
141
142     map {
143           [
144             {
145               'data'  => $part_event->option_label($_). ':',
146               'align' => 'right',
147               'size'  => '-1',
148             },
149             {
150              'data'  => $options{$_},
151              'align' => 'left',
152               'size'  => '-1',
153             },
154           ];
155         }
156
157         keys %options
158   ];
159
160 };
161
162 </%once>
163 <%init>
164
165 die "access denied"
166   unless $FS::CurrentUser::CurrentUser->access_right('Edit billing events')
167       || $FS::CurrentUser::CurrentUser->access_right('Edit global billing events');
168
169 my $html_init =
170   #XXX better description
171   'Events are billing, collection or other actions triggered when certain '.
172   'customer, invoice, package or other conditions are met.<BR><BR>'.
173   qq!<FORM METHOD="POST" ACTION="${p}edit/part_event.html">!.
174   qq!<A HREF="${p}edit/part_event.html"><I>Add a new event</I></A>!.
175   '&nbsp;or&nbsp;<SELECT NAME="clone"><OPTION></OPTION>';
176
177 foreach my $part_event ( qsearch('part_event', {'disabled'=>''}) ) {
178   $html_init .= '<OPTION VALUE="'. $part_event->eventpart. '">'.
179                   $part_event->eventpart. ': '. 
180                   encode_entities($part_event->event).
181                 '</OPTION>';
182 }
183
184 $html_init .= '</SELECT><INPUT TYPE="submit" VALUE="Clone existing event">'.
185               '</FORM><BR>';
186      
187 my $count_query = 'SELECT COUNT(*) FROM part_event WHERE '.
188                   $FS::CurrentUser::CurrentUser->agentnums_sql(
189                     'null_right'    => 'Edit global billing events',
190                     'viewall_right' => 'None',
191                   );
192
193 my $join_conditions  = FS::part_event_condition->join_conditions_sql('', 'time' => time);
194 my $order_conditions = FS::part_event_condition->order_conditions_sql;
195
196 </%init>