cdr rating by day and time, part 2, RT#4763
[freeside.git] / httemplate / edit / rate_region.cgi
1 <% include("/elements/header.html","$action Region", menubar(
2       'View all regions' => "${p}browse/rate_region.html",
3     ))
4 %>
5
6 <% include('/elements/error.html') %>
7
8 <FORM ACTION="<%$p1%>process/rate_region.cgi" METHOD=POST>
9
10 <INPUT TYPE="hidden" NAME="regionnum" VALUE="<% $rate_region->regionnum %>">
11
12 %# region info
13
14 <% ntable('#cccccc') %>
15
16   <TR>
17     <TH ALIGN="right">Region name</TH>
18     <TD><INPUT TYPE="text" NAME="regionname" SIZE=32 VALUE="<% $rate_region->regionname %>"></TR>
19   </TR>
20
21   <TR>
22     <TH ALIGN="right">Country code</TH>
23     <TD><INPUT TYPE="text" NAME="countrycode" SIZE=4 MAXLENGTH=3 VALUE="<% $countrycode %>"></TR>
24   </TR>
25
26   <TR>
27     <TD ALIGN="right">
28       <B>Prefixes</B>
29       <BR><FONT SIZE="-1">(comma-separated)</FONT>
30     </TD>
31     <TD>
32       <TEXTAREA NAME="npa" WRAP=SOFT><% join(', ', map { $_->npa. (length($_->nxx) ? '-'.$_->nxx : '') } @rate_prefix ) %></TEXTAREA>
33     </TD>
34   </TR>
35
36 </TABLE>
37
38 <BR><BR>
39 <INPUT TYPE="submit" VALUE="<% $rate_region->regionnum ? "Apply changes" : "Add region" %>">
40 </FORM>
41 %# rate plan info, if the region has been created yet
42
43 % if($rate_region->regionnum) {
44 <BR>
45 <BR>
46 <FONT SIZE="+2">Rates in this region</FONT>
47 <% include('/edit/elements/rate_detail.html',
48             'regionnum' => $rate_region->regionnum,
49 ) %>
50 % }
51
52 <% include('/elements/footer.html') %>
53 <%once>
54
55 tie my %conn_secs,   'Tie::IxHash', FS::rate_detail::conn_secs();
56
57 </%once>
58 <%init>
59
60 die "access denied"
61   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
62
63 my $conf = new FS::Conf;
64 my $money_char = $conf->config('money_char') || '$';
65
66 my $rate_region;
67 if ( $cgi->param('error') ) {
68   $rate_region = new FS::rate_region ( {
69     map { $_, scalar($cgi->param($_)) } fields('rate_region')
70   } );
71 } elsif ( $cgi->keywords ) {
72   my($query) = $cgi->keywords;
73   $query =~ /^(\d+)$/ or die "unparsable regionnum";
74   $rate_region = qsearchs( 'rate_region', { 'regionnum' => $1 } )
75     or die "unknown regionnum $1\n";
76 } else { #adding
77   $rate_region = new FS::rate_region {};
78 }
79 my $action = $rate_region->regionnum ? 'Edit' : 'Add';
80
81 my $p1 = popurl(1);
82
83 tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
84
85 my @rate_prefix = $rate_region->rate_prefix;
86 my $countrycode = '';
87 if ( @rate_prefix ) {
88   $countrycode = $rate_prefix[0]->countrycode;
89   foreach my $rate_prefix ( @rate_prefix ) {
90     errorpage('multiple country codes per region not yet supported by web UI')
91       unless $rate_prefix->countrycode eq $countrycode;
92   }
93 }
94
95 </%init>