communigate (phase 2): rules: show conditions/actions on rule browse, fix rule edit...
[freeside.git] / httemplate / browse / rate_detail.html
1 <% include( 'elements/browse.html',
2      'title'          => $title,
3      'name_singular'  => 'rate',
4      'html_init'      => $html_init,
5      'menubar'        => [ 'Rate plans' => $p.'browse/rate.cgi' ],
6      'query'          => {
7                            'table'     => 'rate_detail',
8                            'addl_from' => $join,
9                            'hashref'   => { 'ratenum' => $ratenum },
10                            'extra_sql' => $where,
11                          },
12      'count_query'    => "SELECT COUNT(*) FROM rate_detail $join".
13                          " WHERE ratenum = $ratenum $where",
14      'header'         => [
15                            'Region',
16                            'Prefix(es)',
17                            'Included<BR>minutes',
18                            'Connection<BR>charge',
19                            'Charge per<BR>minute',
20                            'Granularity',
21                            'Usage class',
22                          ],
23      'fields'         => [
24                            'regionname',
25                            sub { shift->dest_region->prefixes_short },
26                            sub { shift->min_included. $edit_hint },
27                            $conn_charge_sub,
28                            sub { $money_char. shift->min_charge. $edit_hint },
29                            sub { $granularity{ shift->sec_granularity } },
30                            'classname',
31                          ],
32      'links'          => [ '', '', $edit_link,    $edit_link,    '', '' ],
33      'link_onclicks'  => [ '', '', $edit_onclick, $edit_onclick, '', '' ],
34      'align'          => 'llrrcc',
35    )
36 %>
37 <%once>
38
39 tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
40 tie my %conn_secs,   'Tie::IxHash', FS::rate_detail::conn_secs();
41
42 my $conf = new FS::Conf;
43 my $money_char = $conf->config('money_char') || '$';
44
45 my $join =
46   ' JOIN rate_region ON ( rate_detail.dest_regionnum = rate_region.regionnum )';
47
48 my $edit_link = [ 'javascript:void(0);', sub { ''; } ];
49
50 my $edit_onclick = sub {
51   my $rate_detail = shift;
52   my $ratedetailnum = $rate_detail->ratedetailnum;
53   include( '/elements/popup_link_onclick.html',
54              'action'      => "${p}edit/rate_detail.html?$ratedetailnum",
55              'actionlabel' => 'Edit rate',
56              'height'      => 420,
57              #default# 'width'       => 540,
58              #default# 'color'       => '#333399',
59          );
60 };
61 my $edit_hint = '&nbsp;<FONT SIZE="-1">(edit)</FONT>';
62
63 my $conn_charge_sub = sub {
64    my $rate_detail = shift;
65    #return '' unless $rate_detail->conn_charge > 0 || $rate_detail->conn_sec;
66    $money_char. $rate_detail->conn_charge.
67      ($rate_detail->conn_sec ? ' for '.$conn_secs{$rate_detail->conn_sec} : '').
68      $edit_hint;
69 };
70
71 </%once>
72 <%init>
73
74 die "access denied"
75   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
76
77 my $html_init = include('/elements/init_overlib.html');
78
79 $cgi->param('ratenum') =~ /^(\d+)$/ or die "unparsable ratenum";
80 my $ratenum = $1;
81 my $rate = qsearchs('rate', { 'ratenum' => $ratenum } )
82   or die "unknown ratenum $ratenum";
83 my $ratename = $rate->ratename;
84 my $title = "$ratename rates";
85
86 my @where = ();
87
88 if ( $cgi->param('countrycode') =~ /^(\d+)$/ ) { 
89   my $countrycode = $1;
90   push @where, "0 < ( SELECT COUNT(*) FROM rate_prefix
91                         WHERE rate_prefix.regionnum = rate_region.regionnum
92                           AND countrycode = '$countrycode'
93                     )
94                ";
95   $title .= " for +$countrycode";
96 }
97
98 my $where = scalar(@where) ? ' AND '.join(' AND ', @where ) : '';
99
100 </%init>