From 2eda79fb265b3acdde85881f1160f6daa73f2d84 Mon Sep 17 00:00:00 2001 From: jeff Date: Fri, 18 Apr 2008 03:29:59 +0000 Subject: [PATCH] drag address and router even farther into the century --- FS/t/addr_block.t | 5 + FS/t/router.t | 5 + httemplate/browse/addr_block.cgi | 194 +++++++++++++--------- httemplate/browse/router.cgi | 103 ++++-------- httemplate/edit/allocate.html | 26 +++ httemplate/edit/process/addr_block/add.cgi | 7 + httemplate/edit/process/addr_block/allocate.cgi | 38 ++--- httemplate/edit/process/addr_block/deallocate.cgi | 7 + httemplate/edit/process/addr_block/split.cgi | 7 + 9 files changed, 217 insertions(+), 175 deletions(-) create mode 100644 FS/t/addr_block.t create mode 100644 FS/t/router.t create mode 100644 httemplate/edit/allocate.html diff --git a/FS/t/addr_block.t b/FS/t/addr_block.t new file mode 100644 index 000000000..4f49a4416 --- /dev/null +++ b/FS/t/addr_block.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::addr_block; +$loaded=1; +print "ok 1\n"; diff --git a/FS/t/router.t b/FS/t/router.t new file mode 100644 index 000000000..fe171b3dc --- /dev/null +++ b/FS/t/router.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::router; +$loaded=1; +print "ok 1\n"; diff --git a/httemplate/browse/addr_block.cgi b/httemplate/browse/addr_block.cgi index 7a9351918..d597ee17e 100644 --- a/httemplate/browse/addr_block.cgi +++ b/httemplate/browse/addr_block.cgi @@ -1,91 +1,121 @@ -<% include('/elements/header.html', 'Address Blocks') %> - -<% include('/elements/error.html') %> - -<% include('/elements/table-grid.html') %> -% my $bgcolor1 = '#eeeeee'; -% my $bgcolor2 = '#ffffff'; -% my $bgcolor = ''; - - - Address block(s) - Router - Action(s) - - -% foreach $block (sort {$a->NetAddr cmp $b->NetAddr} @addr_block) { -% if ( $bgcolor eq $bgcolor1 ) { -% $bgcolor = $bgcolor2; -% } else { -% $bgcolor = $bgcolor1; -% } - - - <%$block->NetAddr%> - -% if (my $router = $block->router) { -% -% if (scalar($block->svc_broadband) == 0) { - - - <%$router->routername%> - - -
- - -
- -% } else { - - - <%$router->routername%> - -% } -% -% } else { - - -
- - - -
- - -
- - -
- - -% } - - -% } - - - -

-
-Gateway/Netmask: -/ - - -<% include('/elements/footer.html') %> +<% include('elements/browse.html', + 'title' => 'Address Blocks', + 'name' => 'address block', + 'html_init' => $html_init, + 'html_form' => $html_form, + 'query' => { 'table' => 'addr_block', + 'hashref' => {}, + 'extra_sql' => $extra_sql, + 'order_by' => $order_by, + }, + 'count_query' => "SELECT count(*) from addr_block $extra_sql", + 'header' => [ 'Address Block', + 'Router', + 'Action(s)', + '', + ], + 'fields' => [ 'NetAddr', + sub { my $block = shift; + my $router = $block->router; + my $result = ''; + if ($router) { + $result .= $router->routername. ' ('; + $result .= scalar($block->svc_broadband). ' services)'; + } + $result; + }, + $allocate_text, + sub { shift->router ? '' : '(split)' }, + ], + 'links' => [ '', + '', + [ 'javascript:void(0)', '' ], + $split_link, + ], + 'link_onclicks' => [ '', + '', + $allocate_link, + '', + ], + 'cell_styles' => [ '', + '', + 'border-right:none;', + 'border-left:none;', + ], + ) +%> <%init> die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); -my @addr_block = qsearch('addr_block', {}); -my @router = qsearch('router', {}); -my $block; my $p2 = popurl(2); my $path = $p2 . "edit/process/addr_block"; +my $extra_sql = " "; +my $order_by = "ORDER BY "; +$order_by .= "inet(ip_gateway), " if driver_name =~ /^Pg/i; +$order_by .= "inet_aton(ip_gateway), " if driver_name =~ /^mysql/i; +$order_by .= "ip_netmask"; + +my $html_init = qq( + +); + +$html_init .= include('/elements/error.html'); + +my $confirm = sub { + my ($verb, $num) = (shift, shift); + "javascript:addr_block_areyousure('$path/$verb.cgi?blocknum=$num', '$verb')"; +}; + +my $html_form = qq( + + Gateway/Netmask: + / + +
+); + +my $allocate_text = sub { my $block = shift; + my $router = $block->router; + my $result = ''; + if ($router) { + $result = '(deallocate)' + unless scalar($block->svc_broadband); + }else{ + $result .= '(allocate)' + } + $result; +}; + +my $allocate_link = sub { + my $block = shift; + if ($block->router) { + if (scalar($block->svc_broadband) == 0) { + &{$confirm}('deallocate', $block->blocknum); + } else { + ""; + } + } else { + include( '/elements/popup_link_onclick.html', + 'action' => "${p2}edit/allocate.html?blocknum=". $block->blocknum, + 'actionlabel' => 'Allocate block to router', + ); + } +}; + +my $split_link = sub { + my $block = shift; + my $ref = [ '', '' ]; + $ref = [ &{$confirm}('split', $block->blocknum), '' ] + unless ($block->router); + $ref; +}; + diff --git a/httemplate/browse/router.cgi b/httemplate/browse/router.cgi index a52f609a1..9d856f67c 100644 --- a/httemplate/browse/router.cgi +++ b/httemplate/browse/router.cgi @@ -1,76 +1,43 @@ -<% include('/elements/header.html', 'Routers') %> - -<% include('/elements/error.html') %> - -%my $hidecustomerrouters = 0; -%my $hideurl = ''; -%if ($cgi->param('hidecustomerrouters') eq '1') { -% $hidecustomerrouters = 1; -% $cgi->param('hidecustomerrouters', 0); -% $hideurl = 'Show customer routers'; -%} else { -% $hidecustomerrouters = 0; -% $cgi->param('hidecustomerrouters', 1); -% $hideurl = 'Hide customer routers'; -%} - -Add a new router | <%$hideurl%> - -<% include('/elements/table-grid.html') %> -% my $bgcolor1 = '#eeeeee'; -% my $bgcolor2 = '#ffffff'; -% my $bgcolor = ''; - - - Router name - Address block(s) - - -% foreach my $router (sort {$a->routernum <=> $b->routernum} @router) { -% next if $hidecustomerrouters && $router->svcnum; -% my @addr_block = $router->addr_block; -% if (scalar(@addr_block) == 0) { -% push @addr_block, ' '; -% } -% -% if ( $bgcolor eq $bgcolor1 ) { -% $bgcolor = $bgcolor2; -% } else { -% $bgcolor = $bgcolor1; -% } - - - - - <%$router->routername%> - - - - - -% foreach my $block ( @addr_block ) { - - - - -% } -
<%UNIVERSAL::isa($block, 'FS::addr_block') ? $block->NetAddr : ' '%>
- - - - -% } - - - -<% include('/elements/footer.html') %> - +<% include('elements/browse.html', + 'title' => 'Routers', + 'menubar' => [ @menubar ], + 'name_singular' => 'router', + 'query' => { 'table' => 'router', + 'hashref' => {}, + 'extra_sql' => $extra_sql, + }, + 'count_query' => "SELECT count(*) from router $extra_sql", + 'header' => [ 'Router name', + 'Address block(s)', + ], + 'fields' => [ 'routername', + sub { join( '
', map { $_->NetAddr } + shift->addr_block + ); + }, + ], + 'links' => [ [ "${p2}edit/router.cgi?", 'routernum' ], + '', + ], + ) +%> <%init> die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); -my @router = qsearch('router', {}); my $p2 = popurl(2); +my $extra_sql = ''; + +my @menubar = ( 'Add a new router', "${p2}edit/router.cgi" ); + +if ($cgi->param('hidecustomerrouters') eq '1') { + $extra_sql = 'WHERE svcnum > 0'; + $cgi->param('hidecustomerrouters', 0); + push @menubar, 'Show customer routers', $cgi->self_url(); +} else { + $cgi->param('hidecustomerrouters', 1); + push @menubar, 'Hide customer routers', $cgi->self_url(); +} diff --git a/httemplate/edit/allocate.html b/httemplate/edit/allocate.html new file mode 100644 index 000000000..29c16ae6a --- /dev/null +++ b/httemplate/edit/allocate.html @@ -0,0 +1,26 @@ +<% include('elements/edit.html', + 'name' => 'Allocation', + 'table' => 'addr_block', + 'labels' => { 'NetAddr' => 'Block', + 'routernum' => 'Router', + }, + 'fields' => [ { 'field' => 'NetAddr', + 'type' => 'fixed', + }, + { 'field' => 'routernum', + 'type' => 'select-table', + 'table' => 'router', + 'name_col' => 'routername', + 'disable_empty' => 1, + }, + ], + 'post_url' => "process/addr_block/allocate.cgi", + 'popup' => 1, + ) +%> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + + diff --git a/httemplate/edit/process/addr_block/add.cgi b/httemplate/edit/process/addr_block/add.cgi index 85780c678..e9f9b9736 100755 --- a/httemplate/edit/process/addr_block/add.cgi +++ b/httemplate/edit/process/addr_block/add.cgi @@ -19,3 +19,10 @@ %} % +<%init> + +my $conf = new FS::Conf; +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + + diff --git a/httemplate/edit/process/addr_block/allocate.cgi b/httemplate/edit/process/addr_block/allocate.cgi index a94c0320f..d1bd73f1f 100755 --- a/httemplate/edit/process/addr_block/allocate.cgi +++ b/httemplate/edit/process/addr_block/allocate.cgi @@ -1,26 +1,14 @@ -% -%my $error = ''; -%my $blocknum = $cgi->param('blocknum'); -%my $routernum = $cgi->param('routernum'); -% -%my $addr_block = qsearchs('addr_block', { blocknum => $blocknum }); -%my $router = qsearchs('router', { routernum => $routernum }); -% -%if($addr_block) { -% if ($router) { -% $error = $addr_block->allocate($router); -% } else { -% $error = "Cannot find router with routernum $routernum"; -% } -%} else { -% $error = "Cannot find block with blocknum $blocknum"; -%} -% -%if ( $error ) { -% $cgi->param('error', $error); -% print $cgi->redirect(popurl(4). "browse/addr_block.cgi?" . $cgi->query_string); -%} else { -% print $cgi->redirect(popurl(4). "browse/addr_block.cgi"); -%} -% +<% include( '../elements/process.html', + 'table' => 'addr_block', + 'copy_on_empty' => [ fields 'addr_block' ], + 'error_redirect' => popurl(3). 'allocate.html?', + 'popup_reload' => 'Block allocated', + ) +%> +<%init> +my $conf = new FS::Conf; +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + + diff --git a/httemplate/edit/process/addr_block/deallocate.cgi b/httemplate/edit/process/addr_block/deallocate.cgi index 494c19f75..95e1b7e4d 100755 --- a/httemplate/edit/process/addr_block/deallocate.cgi +++ b/httemplate/edit/process/addr_block/deallocate.cgi @@ -23,3 +23,10 @@ %} % +<%init> + +my $conf = new FS::Conf; +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + + diff --git a/httemplate/edit/process/addr_block/split.cgi b/httemplate/edit/process/addr_block/split.cgi index 617c3f8ce..b3a33b18a 100755 --- a/httemplate/edit/process/addr_block/split.cgi +++ b/httemplate/edit/process/addr_block/split.cgi @@ -18,3 +18,10 @@ %} % +<%init> + +my $conf = new FS::Conf; +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + + -- 2.11.0