summaryrefslogtreecommitdiff
path: root/httemplate/edit
diff options
context:
space:
mode:
authorivan <ivan>2004-11-20 17:26:56 +0000
committerivan <ivan>2004-11-20 17:26:56 +0000
commit48ba2845d0119c56971d5b724661aa37e73b49dd (patch)
treef5b2946aec0b5ee6910c97e88aa9112cec50a405 /httemplate/edit
parent521e7787b230669dc10e6fbd909e70ddb8121990 (diff)
first pass at VoIP rating
Diffstat (limited to 'httemplate/edit')
-rwxr-xr-xhttemplate/edit/part_pkg.cgi7
-rwxr-xr-xhttemplate/edit/process/rate.cgi37
-rwxr-xr-xhttemplate/edit/process/rate_region.cgi51
-rw-r--r--httemplate/edit/rate.cgi94
-rw-r--r--httemplate/edit/rate_region.cgi114
5 files changed, 301 insertions, 2 deletions
diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi
index 6a06c3525..dc2992459 100755
--- a/httemplate/edit/part_pkg.cgi
+++ b/httemplate/edit/part_pkg.cgi
@@ -295,8 +295,11 @@ my $widget = new HTML::Widgets::SelectLayers(
? $plandata{$field}
: $href->{$field}{'default'} ).
qq!" onChange="fchanged(this)">!;
- } elsif ( $href->{$field}{'type'} eq 'select_multiple' ) {
- $html .= qq!<SELECT MULTIPLE NAME="$field" onChange="fchanged(this)">!;
+ } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
+ $html .= '<SELECT';
+ $html .= ' MULTIPLE'
+ if $href->{$field}{'type'} eq 'select_multiple';
+ $html .= qq! NAME="$field" onChange="fchanged(this)">!;
foreach my $record (
qsearch( $href->{$field}{'select_table'},
$href->{$field}{'select_hash'} )
diff --git a/httemplate/edit/process/rate.cgi b/httemplate/edit/process/rate.cgi
new file mode 100755
index 000000000..04ff5f8f7
--- /dev/null
+++ b/httemplate/edit/process/rate.cgi
@@ -0,0 +1,37 @@
+<%
+
+my $ratenum = $cgi->param('ratenum');
+
+my $old = qsearchs('rate', { 'ratenum' => $ratenum } ) if $ratenum;
+
+my @rate_detail = map {
+ my $regionnum = $_->regionnum;
+ new FS::rate_detail {
+ 'dest_regionnum' => $regionnum,
+ map { $_ => $cgi->param("$_$regionnum") }
+ qw( min_included min_charge sec_granularity )
+ };
+} qsearch('rate_region', {} );
+
+my $new = new FS::rate ( {
+ map {
+ $_, scalar($cgi->param($_));
+ } fields('rate')
+} );
+
+my $error;
+if ( $ratenum ) {
+ $error = $new->replace($old, 'rate_detail' => \@rate_detail );
+} else {
+ $error = $new->insert( 'rate_detail' => \@rate_detail );
+ $ratenum = $new->getfield('ratenum');
+}
+
+if ( $error ) {
+ $cgi->param('error', $error);
+ print $cgi->redirect(popurl(2). "rate.cgi?". $cgi->query_string );
+} else {
+ print $cgi->redirect(popurl(3). "browse/rate.cgi");
+}
+
+%>
diff --git a/httemplate/edit/process/rate_region.cgi b/httemplate/edit/process/rate_region.cgi
new file mode 100755
index 000000000..09d3d2c42
--- /dev/null
+++ b/httemplate/edit/process/rate_region.cgi
@@ -0,0 +1,51 @@
+<%
+
+my $regionnum = $cgi->param('regionnum');
+
+my $old = qsearchs('rate_region', { 'regionnum' => $regionnum } ) if $regionnum;
+
+my $new = new FS::rate_region ( {
+ map {
+ $_, scalar($cgi->param($_));
+ } ( fields('rate_region') )
+} );
+
+my $countrycode = $cgi->param('countrycode');
+my @npa = split(/\s*,\s*/, $cgi->param('npa'));
+$npa[0] = '' unless @npa;
+my @rate_prefix = map {
+ new FS::rate_prefix {
+ 'countrycode' => $countrycode,
+ 'npa' => $_,
+ }
+ } @npa;
+
+my @dest_detail = map {
+ my $ratenum = $_->ratenum;
+ new FS::rate_detail {
+ 'ratenum' => $ratenum,
+ map { $_ => $cgi->param("$_$ratenum") }
+ qw( min_included min_charge sec_granularity )
+ };
+} qsearch('rate', {} );
+
+
+my $error;
+if ( $regionnum ) {
+ $error = $new->replace($old, 'rate_prefix' => \@rate_prefix,
+ 'dest_detail' => \@dest_detail, );
+} else {
+ $error = $new->insert( 'rate_prefix' => \@rate_prefix,
+ 'dest_detail' => \@dest_detail, );
+ $regionnum = $new->getfield('regionnum');
+}
+
+if ( $error ) {
+ $cgi->param('error', $error);
+ print $cgi->redirect(popurl(2). "rate_region.cgi?". $cgi->query_string );
+} else {
+ #print $cgi->redirect(popurl(3). "browse/rate_region.cgi");
+ print $cgi->redirect(popurl(3). "browse/rate.cgi");
+}
+
+%>
diff --git a/httemplate/edit/rate.cgi b/httemplate/edit/rate.cgi
new file mode 100644
index 000000000..83a89c475
--- /dev/null
+++ b/httemplate/edit/rate.cgi
@@ -0,0 +1,94 @@
+<!-- mason kludge -->
+<%
+
+my $rate;
+if ( $cgi->param('error') ) {
+ $rate = new FS::rate ( {
+ map { $_, scalar($cgi->param($_)) } fields('rate')
+ } );
+} elsif ( $cgi->keywords ) {
+ my($query) = $cgi->keywords;
+ $query =~ /^(\d+)$/;
+ $rate = qsearchs( 'rate', { 'ratenum' => $1 } );
+} else { #adding
+ $rate = new FS::rate {};
+}
+my $action = $rate->ratenum ? 'Edit' : 'Add';
+
+my $p1 = popurl(1);
+
+my %granularity = (
+ '6' => '6 second',
+ '60' => 'minute',
+);
+
+%>
+
+<%= header("$action Rate plan", menubar(
+ 'Main Menu' => $p,
+ 'View all rate plans' => "${p}browse/rate.cgi",
+ ))
+%>
+
+<% if ( $cgi->param('error') ) { %>
+<FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT><BR>
+<% } %>
+
+<FORM ACTION="<%=$p1%>process/rate.cgi" METHOD=POST>
+
+<INPUT TYPE="hidden" NAME="ratenum" VALUE="<%= $rate->ratenum %>">
+
+Rate plan
+<INPUT TYPE="text" NAME="ratename" SIZE=32 VALUE="<%= $rate->ratename %>">
+<BR><BR>
+
+<%= table() %>
+<TR>
+ <TH>Region</TH>
+ <TH>Prefix(es)</TH>
+ <TH><FONT SIZE=-1>Included<BR>minutes</FONT></TH>
+ <TH><FONT SIZE=-1>Charge per<BR>minute</FONT></TH>
+ <TH><FONT SIZE=-1>Granularity</FONT></TH>
+</TR>
+
+<% foreach my $rate_region (
+ qsearch('rate_region', {}, '', 'ORDER BY regionname' )
+ ) {
+ my $n = $rate_region->regionnum;
+ my $rate_detail =
+ $rate->dest_detail($rate_region)
+ || new FS::rate_region { 'min_included' => 0,
+ 'min_charge' => 0,
+ 'sec_granularity' => '60'
+ };
+%>
+ <TR>
+ <TD><A HREF="<%=$p%>edit/rate_region.cgi?<%= $rate_region->regionnum %>"><%= $rate_region->regionname %></A></TD>
+ <TD><%= $rate_region->prefixes_short %></TD>
+ <TD><INPUT TYPE="text" SIZE=5 NAME="min_included<%=$n%>" VALUE="<%= $cgi->param("min_included$n") || $rate_detail->min_included %>"></TD>
+ <TD>$<INPUT TYPE="text" SIZE=4 NAME="min_charge<%=$n%>" VALUE="<%= sprintf('%.2f', $cgi->param("min_charge$n") || $rate_detail->min_charge ) %>"></TD>
+ <TD>
+ <SELECT NAME="sec_granularity<%=$n%>">
+ <% foreach my $granularity ( keys %granularity ) { %>
+ <OPTION VALUE="<%=$granularity%>"<%= $granularity == ( $cgi->param("sec_granularity$n") || $rate_detail->sec_granularity ) ? ' SELECTED' : '' %>><%=$granularity{$granularity}%>
+ <% } %>
+ </SELECT>
+ </TR>
+<% } %>
+
+<TR>
+ <TD COLSPAN=5 ALIGN="center">
+ <A HREF="<%=$p%>edit/rate_region.cgi"><I>Add a region</I></A>
+ </TD>
+</TR>
+
+</TABLE>
+
+<BR><INPUT TYPE="submit" VALUE="<%=
+ $rate->ratenum ? "Apply changes" : "Add rate plan"
+%>">
+
+ </FORM>
+ </BODY>
+</HTML>
+
diff --git a/httemplate/edit/rate_region.cgi b/httemplate/edit/rate_region.cgi
new file mode 100644
index 000000000..cc14dd37d
--- /dev/null
+++ b/httemplate/edit/rate_region.cgi
@@ -0,0 +1,114 @@
+<!-- mason kludge -->
+<%
+
+my $rate_region;
+if ( $cgi->param('error') ) {
+ $rate_region = new FS::rate_region ( {
+ map { $_, scalar($cgi->param($_)) } fields('rate_region')
+ } );
+} elsif ( $cgi->keywords ) {
+ my($query) = $cgi->keywords;
+ $query =~ /^(\d+)$/;
+ $rate_region = qsearchs( 'rate_region', { 'regionnum' => $1 } );
+} else { #adding
+ $rate_region = new FS::rate_region {};
+}
+my $action = $rate_region->regionnum ? 'Edit' : 'Add';
+
+my $p1 = popurl(1);
+
+my %granularity = (
+ '6' => '6 second',
+ '60' => 'minute',
+);
+
+my @rate_prefix = $rate_region->rate_prefix;
+my $countrycode = '';
+if ( @rate_prefix ) {
+ $countrycode = $rate_prefix[0]->countrycode;
+ foreach my $rate_prefix ( @rate_prefix ) {
+ eidiot 'multiple country codes per region not yet supported by web UI'
+ unless $rate_prefix->countrycode eq $countrycode;
+ }
+}
+
+%>
+
+<%= header("$action Region", menubar(
+ 'Main Menu' => $p,
+ #'View all regions' => "${p}browse/rate_region.cgi",
+ ))
+%>
+
+<% if ( $cgi->param('error') ) { %>
+<FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT><BR>
+<% } %>
+
+<FORM ACTION="<%=$p1%>process/rate_region.cgi" METHOD=POST>
+
+<INPUT TYPE="hidden" NAME="regionnum" VALUE="<%= $rate_region->regionnum %>">
+
+<%= ntable('#cccccc') %>
+<TR>
+ <TH ALIGN="right">Region name</TH>
+ <TD><INPUT TYPE="text" NAME="regionname" SIZE=32 VALUE="<%= $rate_region->regionname %>"></TR>
+</TR>
+
+<TR>
+ <TH ALIGN="right">Country code</TH>
+ <TD><INPUT TYPE="text" NAME="countrycode" SIZE=4 MAXLENGTH=3 VALUE="<%= $countrycode %>"></TR>
+</TR>
+
+
+<TR>
+ <TH ALIGN="right">Prefixes</TH>
+ <TD>
+ <TEXTAREA NAME="npa" WRAP=SOFT><%= join(', ', map $_->npa, @rate_prefix ) %></TEXTAREA>
+ </TD>
+</TR>
+
+</TABLE>
+
+<BR>
+<%= table() %>
+<TR>
+ <TH>Rate plan</TH>
+ <TH><FONT SIZE=-1>Included<BR>minutes</FONT></TH>
+ <TH><FONT SIZE=-1>Charge per<BR>minute</FONT></TH>
+ <TH><FONT SIZE=-1>Granularity</FONT></TH>
+</TR>
+
+<% foreach my $rate ( qsearch('rate', {}) ) {
+
+ my $n = $rate->ratenum;
+ my $rate_detail = $rate->dest_detail($rate_region)
+ || new FS::rate_region { 'min_included' => 0,
+ 'min_charge' => 0,
+ 'sec_granularity' => '60'
+ };
+
+%>
+ <TR>
+ <TD><A HREF="<%=$p%>edit/rate.cgi?<%= $rate->ratenum %>"><%= $rate->ratename %></TD>
+ <TD><INPUT TYPE="text" SIZE=5 NAME="min_included<%=$n%>" VALUE="<%= $cgi->param("min_included$n") || $rate_detail->min_included %>"></TD>
+ <TD>$<INPUT TYPE="text" SIZE=4 NAME="min_charge<%=$n%>" VALUE="<%= sprintf('%.2f', $cgi->param("min_charge$n") || $rate_detail->min_charge ) %>"></TD>
+ <TD>
+ <SELECT NAME="sec_granularity<%=$n%>">
+ <% foreach my $granularity ( keys %granularity ) { %>
+ <OPTION VALUE="<%=$granularity%>"<%= $granularity == ( $cgi->param("sec_granularity$n") || $rate_detail->sec_granularity ) ? ' SELECTED' : '' %>><%=$granularity{$granularity}%>
+ <% } %>
+ </SELECT>
+ </TR>
+<% } %>
+
+</TABLE>
+
+<BR><BR><INPUT TYPE="submit" VALUE="<%=
+ $rate_region->regionnum ? "Apply changes" : "Add region"
+%>">
+
+ </FORM>
+ </BODY>
+</HTML>
+
+