agent-virtualize VoIP rates, RT#29183
[freeside.git] / httemplate / browse / rate.cgi
1 <% include( 'elements/browse.html',
2               'title'       => 'Rate plans',
3               'menubar'     => \@menubar,
4               'html_init'   => $html_init,
5               'name'        => 'rate plans',
6               'query'       => { 'table'     => 'rate',
7                                  'hashref'   => {},
8                                  'order_by' => 'ORDER BY ratenum',
9                                },
10               'count_query' => $count_query,
11               'header'      => [ '#',       'Rate plan', 'Rates'    ],
12               'fields'      => [ 'ratenum', 'ratename',  $rates_sub ],
13               'links'       => [ $link,     $link,       ''         ],
14               'agent_virt'  => 1,
15               'agent_pos'   => 1,
16               'agent_null_right' => 'Configuration', #'Edit global CDR rates',
17               'really_disable_download' => 1
18           )
19 %>
20 <%once>
21
22 my $all_countrycodes = join("\n", map qq(<OPTION VALUE="$_">$_),
23                                       FS::rate_prefix->all_countrycodes
24                            );
25
26 my $rates_sub = sub {
27   my $rate = shift;
28   my $ratenum = $rate->ratenum;
29
30   qq( <FORM METHOD="GET" ACTION="${p}edit/rate.cgi">
31         <INPUT TYPE="hidden" NAME="ratenum" VALUE="$ratenum">
32         <SELECT NAME="countrycode" onChange="this.form.submit();">
33           <OPTION SELECTED>Select Country Code
34           <OPTION VALUE="">(all)
35           $all_countrycodes
36         </SELECT>
37       </FORM>
38     );
39
40
41 };
42
43 my $html_init = 
44   'Rate plans for VoIP and call billing.<BR><BR>'.
45   qq!<A HREF="${p}edit/rate.cgi"><I>Add a rate plan</I></A>!.
46   qq! | <A HREF="${p}misc/copy-rate_detail.html"><I>Copy rates between plans</I></A>!.
47   '<BR><BR>
48    <SCRIPT>
49    function rate_areyousure(href) {
50     if (confirm("Are you sure you want to delete this rate plan?") == true)
51       window.location.href = href;
52    }
53    </SCRIPT>
54   ';
55
56 my $count_query = 'SELECT COUNT(*) FROM rate';
57
58 my $link = [ $p.'edit/rate.cgi?ratenum=', 'ratenum' ];
59
60 </%once>
61 <%init>
62
63 my $curuser = $FS::CurrentUser::CurrentUser;
64
65 die "access denied"
66   unless $curuser->access_right('Edit CDR rates')
67   #||     $curuser->access_right('Edit global CDR rates')
68   ||     $curuser->access_right('Configuration');
69
70 my @menubar;
71 if ( $curuser->access_right('Configuration') ) { #, 'Edit global CDR rates') ) {
72   push @menubar,
73     'Regions and Prefixes' => $p.'browse/rate_region.html',
74     'Time Periods'         => $p.'browse/rate_time.html',
75     'CDR Types'            => $p.'edit/cdr_type.cgi',
76   ;
77 }
78
79 </%init>