1 <% include( 'elements/browse.html',
2 'title' => 'Rating Regions and Prefixes',
3 'name_singular' => 'region', #'rate region',
4 'menubar' => [ 'Rate plans' => $p.'browse/rate.cgi' ],
5 'html_init' => $html_init,
6 'html_posttotal' => $html_posttotal,
9 'table' => 'rate_region',
11 'extra_sql' => $extra_sql,
12 'order_by' => 'ORDER BY LOWER(regionname)',
14 'count_query' => $count_query,
15 'header' => [ '#', 'Region', 'Country code', 'Prefixes' ],
16 'fields' => [ 'regionnum', 'regionname', 'ccode', 'prefixes' ],
17 'links' => [ $link, $link, $link, $link ],
22 my $edit_url = $p.'edit/rate_region.cgi';
24 my $link = [ "$edit_url?", 'regionnum' ];
27 'Regions and prefixes for VoIP and call billing.<BR><BR>'.
28 qq(<A HREF="$edit_url"><I>Add a new region</I></A><BR><BR>);
30 #not quite right for the shouldn't-happen multiple countrycode per region case
31 my $select = 'rate_region.*, ';
34 if ( driver_name =~ /^Pg/ ) {
35 my $fromwhere = 'FROM rate_prefix'.
36 ' WHERE rate_prefix.regionnum = rate_region.regionnum';
37 my $prefix_sql = " CASE WHEN nxx IS NULL OR nxx = '' ".
39 " ELSE npa || '-' || nxx ".
41 my $prefixes_sql = "SELECT $prefix_sql $fromwhere AND npa IS NOT NULL";
42 $select .= "( SELECT countrycode $fromwhere LIMIT 1 ) AS ccode,
43 ARRAY_TO_STRING( ARRAY($prefixes_sql), ',' ) AS prefixes";
44 } elsif ( driver_name =~ /^mysql/i ) {
45 $join = 'LEFT JOIN rate_prefix USING ( regionnum )';
46 $select .= "GROUP_CONCAT( DISTINCT countrycode ) AS ccode,
47 GROUP_CONCAT( npa ORDER BY npa ) AS prefixes ";
48 $group_sql = 'GROUP BY regionnum, regionname';
50 die 'unknown database '. driver_name;
53 my $base_count_sql = 'SELECT COUNT(*) FROM rate_region';
59 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
61 $cgi->param('dummy', 1);
62 my $countrycode_filter_change =
63 "window.location = '".
64 $cgi->self_url. ";countrycode=' + this.options[this.selectedIndex].value;";
67 my $extra_sql = $group_sql;
68 my $count_query = $base_count_sql;
69 if ( $cgi->param('countrycode') =~ /^(\d+)$/ ) {
71 my $ccode_sql = '( SELECT countrycode FROM rate_prefix
72 WHERE rate_prefix.regionnum = rate_region.regionnum
75 $extra_sql = " WHERE $ccode_sql = '$1' $extra_sql";
76 $count_query .= " WHERE $ccode_sql = '$1'";
80 '(show country code: '.
81 qq(<SELECT NAME="countrycode" onChange="$countrycode_filter_change">).
82 qq(<OPTION VALUE="">(all)).
83 join("\n", map { qq(<OPTION VALUE="$_").
84 ($_ eq $countrycode ? ' SELECTED' : '' ).
87 FS::rate_prefix->all_countrycodes