default to a session cookie instead of setting an explicit timeout, weird timezone...
[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 <TABLE CLASS="fsinnerbox">
15
16 % if ( $rate_region->agent_regionid ) {
17     <TR>
18       <TH ALIGN="right">Legacy #</TH>
19       <TD><% $rate_region->agent_regionid |h %></TD>
20     </TR>
21 % }
22
23   <TR>
24     <TH ALIGN="right">Region name</TH>
25     <TD><INPUT TYPE="text" NAME="regionname" SIZE=32 VALUE="<% $rate_region->regionname %>"></TR>
26   </TR>
27
28   <TR>
29     <TH ALIGN="right">Country code</TH>
30     <TD><INPUT TYPE="text" NAME="countrycode" SIZE=4 MAXLENGTH=3 VALUE="<% $countrycode %>"></TR>
31   </TR>
32
33   <TR>
34     <TH ALIGN="right">
35       <B>Prefixes</B>
36       <BR><FONT SIZE="-1">(comma-separated)</FONT>
37     </TH>
38     <TD>
39       <TEXTAREA NAME="npa" WRAP=SOFT><% join(', ', map { $_->npa. (length($_->nxx) ? '-'.$_->nxx : '') } @rate_prefix ) %></TEXTAREA>
40     </TD>
41   </TR>
42
43   <& /elements/tr-checkbox.html,
44     label       => 'Exact match',
45     field       => 'exact_match',
46     cell_style  => 'font-weight: bold',
47     value       => 'Y',
48     curr_value  => $rate_region->exact_match
49   &>
50
51 </TABLE>
52
53 <BR>
54 <INPUT TYPE="submit" VALUE="<% $rate_region->regionnum ? "Apply changes" : "Add region" %>">
55 </FORM>
56 %# rate plan info, if the region has been created yet
57
58 % if($rate_region->regionnum) {
59 <BR><BR><FONT SIZE="+2">Rates in this region</FONT>
60 % if ( my $select_cdr_type = include('/elements/select-cdr_type.html',
61 %  'curr_value'   => $cdrtypenum,
62 %  'onchange'     => 'form.submit();',
63 %  'name_col'     => 'cdrtypename',
64 %  'value_col'    => 'cdrtypenum',
65 %  'empty_label'  => '(default)',
66 % ) ) {
67 <FORM ACTION="<%$cgi->url%>" METHOD="GET">
68 <INPUT TYPE="hidden" NAME="regionnum"   VALUE="<% $rate_region->regionnum %>">
69 <FONT SIZE="+1">Usage type: <% $select_cdr_type %></FONT>
70 </FORM>
71 % }
72 <% include('/edit/elements/rate_detail.html',
73             'regionnum'   => $rate_region->regionnum,
74             'cdrtypenum'  => $cdrtypenum,
75 ) %>
76 % }
77
78 <% include('/elements/footer.html') %>
79 <%once>
80
81 tie my %conn_secs,   'Tie::IxHash', FS::rate_detail::conn_secs();
82
83 </%once>
84 <%init>
85
86 die "access denied"
87   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
88
89 my $conf = new FS::Conf;
90 my $money_char = $conf->config('money_char') || '$';
91
92 my $rate_region;
93 if ( $cgi->param('error') ) {
94   $rate_region = new FS::rate_region ( {
95     map { $_, scalar($cgi->param($_)) } fields('rate_region')
96   } );
97 } elsif ( $cgi->param('regionnum') ) {
98   $cgi->param('regionnum') =~ /^(\d+)$/ or die "unparseable regionnum";
99   $rate_region = qsearchs( 'rate_region', { 'regionnum' => $1 } )
100     or die "unknown regionnum $1\n";
101 } else { #adding
102   $rate_region = new FS::rate_region {};
103 }
104 my $action = $rate_region->regionnum ? 'Edit' : 'Add';
105
106 my $p1 = popurl(1);
107
108 tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
109
110 my @rate_prefix = $rate_region->rate_prefix;
111 my $countrycode = '';
112 if ( @rate_prefix ) {
113   $countrycode = $rate_prefix[0]->countrycode;
114   foreach my $rate_prefix ( @rate_prefix ) {
115     errorpage('multiple country codes per region not yet supported by web UI')
116       unless $rate_prefix->countrycode eq $countrycode;
117   }
118 }
119 my $cdrtypenum = '';
120 if ( $cgi->param('cdrtypenum') =~ /^(\d+)$/ ) {
121   $cdrtypenum = $1;
122 }
123 </%init>