drag address and router even farther into the century
[freeside.git] / httemplate / browse / addr_block.cgi
1 <% include('elements/browse.html',
2                 'title'         => 'Address Blocks',
3                 'name'          => 'address block',
4                 'html_init'     => $html_init,
5                 'html_form'     => $html_form,
6                 'query'         => { 'table'     => 'addr_block',
7                                      'hashref'   => {},
8                                      'extra_sql' => $extra_sql,
9                                      'order_by'  => $order_by,
10                                    },
11                 'count_query'   => "SELECT count(*) from addr_block $extra_sql",
12                 'header'        => [ 'Address Block',
13                                      'Router',
14                                      'Action(s)',
15                                      '',
16                                    ],
17                 'fields'        => [ 'NetAddr',
18                                      sub { my $block = shift;
19                                            my $router = $block->router;
20                                            my $result = '';
21                                            if ($router) {
22                                              $result .= $router->routername. ' (';
23                                              $result .= scalar($block->svc_broadband). ' services)';
24                                            }
25                                            $result;
26                                          },
27                                      $allocate_text,
28                                      sub { shift->router ? '' : '<FONT SIZE="-2">(split)</FONT>' },
29                                    ],
30                 'links'         => [ '',
31                                      '',
32                                      [ 'javascript:void(0)', '' ],
33                                      $split_link,
34                                    ],
35                 'link_onclicks' => [ '',
36                                      '',
37                                      $allocate_link,
38                                      '',
39                                    ],
40                 'cell_styles'   => [ '',
41                                      '',
42                                      'border-right:none;',
43                                      'border-left:none;',
44                                    ],
45           )
46 %>
47 <%init>
48
49 die "access denied"
50   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
51
52 my $p2 = popurl(2);
53 my $path = $p2 . "edit/process/addr_block";
54
55 my $extra_sql = " ";
56 my $order_by = "ORDER BY ";
57 $order_by .= "inet(ip_gateway), " if driver_name =~ /^Pg/i;
58 $order_by .= "inet_aton(ip_gateway), " if driver_name =~ /^mysql/i;
59 $order_by .= "ip_netmask";
60
61 my $html_init = qq(
62 <SCRIPT>
63   function addr_block_areyousure(href, word) {
64     if(confirm("Are you sure you want to "+word+" this address block?") == true)
65       window.location.href = href;
66   }
67 </SCRIPT>
68 );
69
70 $html_init .= include('/elements/error.html');
71
72 my $confirm = sub {
73   my ($verb, $num) = (shift, shift);
74   "javascript:addr_block_areyousure('$path/$verb.cgi?blocknum=$num', '$verb')";
75 };
76
77 my $html_form = qq(
78   <FORM ACTION="$path/add.cgi" METHOD="POST">
79   Gateway/Netmask: 
80   <INPUT TYPE="text" NAME="ip_gateway" SIZE="15">/<INPUT TYPE="text" NAME="ip_netmask" SIZE="2">
81   <INPUT TYPE="submit" NAME="submit" VALUE="Add">
82   </FORM>
83 );
84
85 my $allocate_text = sub { my $block = shift;
86                           my $router = $block->router;
87                           my $result = '';
88                           if ($router) {
89                             $result = '<FONT SIZE="-2">(deallocate)</FONT>'
90                               unless scalar($block->svc_broadband);
91                           }else{
92                             $result .= '<FONT SIZE="-2">(allocate)</FONT>'
93                           }
94                           $result;
95 };
96
97 my $allocate_link = sub {
98   my $block = shift;
99   if ($block->router) { 
100     if (scalar($block->svc_broadband) == 0) { 
101       &{$confirm}('deallocate', $block->blocknum);
102     } else { 
103       "";
104     } 
105   } else { 
106     include( '/elements/popup_link_onclick.html',
107              'action' => "${p2}edit/allocate.html?blocknum=". $block->blocknum,
108              'actionlabel' => 'Allocate block to router',
109            );
110   } 
111 }; 
112
113 my $split_link = sub {
114   my $block = shift;
115   my $ref = [ '', '' ];
116   $ref = [ &{$confirm}('split', $block->blocknum), '' ]
117     unless ($block->router);
118   $ref;
119 }; 
120
121 </%init>