From 689892f05c1a1f5ea6d6728c46e1011e45c5cacb Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 10 Jan 2008 21:53:56 +0000 Subject: new rate editor --- httemplate/edit/elements/edit.html | 4 + httemplate/edit/process/rate_region.cgi | 95 ++++++++-------- httemplate/edit/rate.cgi | 112 +++---------------- httemplate/edit/rate_region.cgi | 192 +++++++++++++++++++------------- 4 files changed, 184 insertions(+), 219 deletions(-) (limited to 'httemplate/edit') diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 5f1db2912..5e8a34367 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -177,6 +177,10 @@ Example: % if $opt{'debug'}; % % my %include_common = ( +% +% #text and derivitives +% 'size' => $f->{'size'}, +% % #checkbox, title, fixed, fixedhidden % #& deprecated weird value hashref used only by reason.html % 'value' => $f->{'value'}, diff --git a/httemplate/edit/process/rate_region.cgi b/httemplate/edit/process/rate_region.cgi index 753224565..3933ff3c5 100755 --- a/httemplate/edit/process/rate_region.cgi +++ b/httemplate/edit/process/rate_region.cgi @@ -1,52 +1,53 @@ -% -% -%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 ); +<% $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"); +<% $cgi->redirect(popurl(3). "browse/rate_region.html") %> %} -% -% +<%init> + +my $conf = new FS::Conf; +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +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'); +} + diff --git a/httemplate/edit/rate.cgi b/httemplate/edit/rate.cgi index c44364da9..269b3b09a 100644 --- a/httemplate/edit/rate.cgi +++ b/httemplate/edit/rate.cgi @@ -1,34 +1,3 @@ -% -% -%my $rate; -%if ( $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 = ( -% '1', => '1 second', -% '6' => '6 second', -% '30' => '30 second', # '1/2 minute', -% '60' => 'minute', -%); -% -%#my $nous = < $p, 'View all rate plans' => "${p}browse/rate.cgi", @@ -49,72 +18,27 @@ Rate plan

-<% table() %> - - Region - Prefix(es) - Included
minutes
- Charge per
minute
- Granularity - -% foreach my $rate_region ( -% #sort { lc($a->regionname) cmp lc($b->regionname) } -% qsearch({ -% 'table' => 'rate_region', -% 'hashref' => {}, -% 'order_by' => 'ORDER BY LOWER(regionname)', -% -% #'select' => 'DISTINCT ON ( regionnum ) rate_region.*', -% #... -% #'addl_from' => 'INNER JOIN rate_prefix USING ( regionnum )', -% #'extra_sql' => "WHERE countrycode != '1'", -% -% # 'ORDER BY regionname' -% # ERROR: SELECT DISTINCT ON expressions must -% # match initial ORDER BY expressions -% # also, DISTINCT ON is a Pg-ism -% }) -% ) { -% my $n = $rate_region->regionnum; -% my $rate_detail = -% $rate->dest_detail($rate_region) -% || new FS::rate_detail { 'min_included' => 0, -% 'min_charge' => 0, -% 'sec_granularity' => '60' -% }; -% - - - - <% $rate_region->regionname %> - <% $rate_region->prefixes_short %> - min_included %>"> - $min_charge ) %>"> - - - -% } +" onClick="document.OneTrueForm.submit.disabled=true; process();"> + - - - Add a region - - +<% include('/elements/footer.html') %> - +<%init> -
" onClick="document.OneTrueForm.submit.disabled=true; process();"> +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); - - - +my $rate; +if ( $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'; + diff --git a/httemplate/edit/rate_region.cgi b/httemplate/edit/rate_region.cgi index d55c0de43..47d1888e0 100644 --- a/httemplate/edit/rate_region.cgi +++ b/httemplate/edit/rate_region.cgi @@ -1,43 +1,5 @@ - -% -% -%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 ) { -% errorpage('multiple country codes per region not yet supported by web UI') -% unless $rate_prefix->countrycode eq $countrycode; -% } -%} -% -% - - <% include("/elements/header.html","$action Region", menubar( - 'Main Menu' => $p, - #'View all regions' => "${p}browse/rate_region.cgi", + 'View all regions' => "${p}browse/rate_region.html", )) %> @@ -47,35 +9,56 @@ +%# region info + <% ntable('#cccccc') %> - - Region name - - - - Country code - - + + Region name + + + + Country code + + - - Prefixes - - - - + + + Prefixes +
(comma-separated) + + + + + +%# rate plan info +
-<% table() %> - - Rate plan - Included
minutes
- Charge per
minute
- Granularity - + +<% include('/elements/table-grid.html') %> +% my $bgcolor1 = '#eeeeee'; +% my $bgcolor2 = '#ffffff'; +% my $bgcolor = ''; + + + + Rate plan + + + Included
minutes
+ + + Charge per
minute
+ + + Granularity + + + % foreach my $rate ( qsearch('rate', {}) ) { % % my $n = $rate->ratenum; @@ -85,32 +68,85 @@ % 'sec_granularity' => '60' % }; % -% +% if ( $bgcolor eq $bgcolor1 ) { +% $bgcolor = $bgcolor2; +% } else { +% $bgcolor = $bgcolor1; +% } - <% $rate->ratename %> - min_included %>"> - $min_charge ) %>"> - - min_included %>"> + + + + $min_charge ) %>"> + + + + + + -% } +% } -

"> - - - - - +

+"> + + + +<% include('/elements/footer.html') %> + +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +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+)$/ or die "unparsable regionnum"; + $rate_region = qsearchs( 'rate_region', { 'regionnum' => $1 } ) + or die "unknown regionnum $1\n"; +} else { #adding + $rate_region = new FS::rate_region {}; +} +my $action = $rate_region->regionnum ? 'Edit' : 'Add'; + +my $p1 = popurl(1); + +tie my %granularity, 'Tie::IxHash', + '1', => '1 second', + '6' => '6 second', + '30' => '30 second', # '1/2 minute', + '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 ) { + errorpage('multiple country codes per region not yet supported by web UI') + unless $rate_prefix->countrycode eq $countrycode; + } +} + + -- cgit v1.2.1