-<% 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 = '<A HREF="' . $cgi->self_url() . '">Show customer routers</A>';
-%} else {
-% $hidecustomerrouters = 0;
-% $cgi->param('hidecustomerrouters', 1);
-% $hideurl = '<A HREF="' . $cgi->self_url() . '">Hide customer routers</A>';
-%}
-
-<A HREF="<%$p2%>edit/router.cgi">Add a new router</A> | <%$hideurl%>
-
-<% include('/elements/table-grid.html') %>
-% my $bgcolor1 = '#eeeeee';
-% my $bgcolor2 = '#ffffff';
-% my $bgcolor = '';
-
- <TR>
- <TH CLASS="grid" BGCOLOR="#cccccc">Router name</TH>
- <TH CLASS="grid" BGCOLOR="#cccccc">Address block(s)</TH>
- </TR>
-
-% 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;
-% }
-
- <TR>
-
- <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
- <A HREF="<%$p2%>edit/router.cgi?<%$router->routernum%>"><%$router->routername%></A>
- </TD>
-
- <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
- <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
-
-% foreach my $block ( @addr_block ) {
-
- <TR>
- <TD><%UNIVERSAL::isa($block, 'FS::addr_block') ? $block->NetAddr : ' '%></TD>
- </TR>
-% }
- </TABLE>
- </TD>
-
- </TR>
+<% 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 $count_sql",
+ 'header' => [ 'Router name',
+ 'Address block(s)',
+ 'IP addressing',
+ 'Action',
+ ],
+ 'fields' => [ 'routername',
+ sub { join( '<BR>', map { $_->NetAddr }
+ shift->addr_block
+ );
+ },
+ sub { shift->manual_addr ? 'Manual' : 'Automatic' },
+ sub { 'Delete' },
+ ],
+ 'links' => [ [ "${p2}edit/router.cgi?", 'routernum' ],
+ '',
+ '',
+ [ "${p}misc/delete-router.html?", 'routernum' ],
+ ],
+ 'agent_virt' => 1,
+ 'agent_null_right'=> "Broadband global configuration",
+ 'agent_pos' => 1,
+ )
+%>
+<%init>
-% }
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Broadband configuration')
+ || $FS::CurrentUser::CurrentUser->access_right('Broadband global configuration');
-</TABLE>
+my $p2 = popurl(2);
+my $extra_sql = '';
-<% include('/elements/footer.html') %>
+my @menubar = ( 'Add a new router', "${p2}edit/router.cgi" );
-<%init>
+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();
+}
-die "access denied"
- unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+my $count_sql = $extra_sql. ( $extra_sql =~ /WHERE/ ? ' AND' : 'WHERE' ).
+ $FS::CurrentUser::CurrentUser->agentnums_sql(
+ 'null_right' => 'Broadband global configuration',
+ );
-my @router = qsearch('router', {});
-my $p2 = popurl(2);
</%init>