new access right names
[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_foot'     => $html_foot,
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 $count_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                 'agent_virt'    => 1,
46                 'agent_null_right' => 'Broadband global configuration',
47                 'agent_pos'     => 1,
48           )
49 %>
50 <%init>
51
52 die "access denied"
53   unless $FS::CurrentUser::CurrentUser->access_right('Broadband configuration')
54   || $FS::CurrentUser::CurrentUser->access_right('Broadband global configuration');
55
56 my $p2 = popurl(2);
57 my $path = $p2 . "edit/process/addr_block";
58
59 my $extra_sql = "";
60
61 my $count_sql = "WHERE ". $FS::CurrentUser::CurrentUser->agentnums_sql(
62   'null_right' => 'Broadband global configuration',
63 );
64
65 my $order_by = "ORDER BY ";
66 $order_by .= "inet(ip_gateway), " if driver_name =~ /^Pg/i;
67 $order_by .= "inet_aton(ip_gateway), " if driver_name =~ /^mysql/i;
68 $order_by .= "ip_netmask";
69
70 my $html_init = qq(
71 <SCRIPT>
72   function addr_block_areyousure(href, word) {
73     if(confirm("Are you sure you want to "+word+" this address block?") == true)
74       window.location.href = href;
75   }
76 </SCRIPT>
77 );
78
79 $html_init .= include('/elements/error.html');
80
81 my $confirm = sub {
82   my ($verb, $num) = (shift, shift);
83   "javascript:addr_block_areyousure('$path/$verb.cgi?blocknum=$num', '$verb')";
84 };
85
86 my $html_foot = qq(
87   <FORM ACTION="$path/add.cgi" METHOD="POST">
88   Gateway/Netmask: 
89   <INPUT TYPE="text" NAME="ip_gateway" SIZE="15">/<INPUT TYPE="text" NAME="ip_netmask" SIZE="2">
90 );
91 $html_foot .= include( '/elements/select-agent.html',
92                        'agent_virt'       => 1,
93                        'agent_null_right' => 'Broadband global configuration',
94                      );
95 $html_foot .= qq(
96   <INPUT TYPE="submit" NAME="submit" VALUE="Add">
97   </FORM>
98 );
99
100 my $allocate_text = sub { my $block = shift;
101                           my $router = $block->router;
102                           my $result = '';
103                           if ($router) {
104                             $result = '<FONT SIZE="-2">(deallocate)</FONT>'
105                               unless scalar($block->svc_broadband);
106                           }else{
107                             $result .= '<FONT SIZE="-2">(allocate)</FONT>'
108                           }
109                           $result;
110 };
111
112 my $allocate_link = sub {
113   my $block = shift;
114   if ($block->router) { 
115     if (scalar($block->svc_broadband) == 0) { 
116       &{$confirm}('deallocate', $block->blocknum);
117     } else { 
118       "";
119     } 
120   } else { 
121     include( '/elements/popup_link_onclick.html',
122              'action' => "${p2}edit/allocate.html?blocknum=". $block->blocknum,
123              'actionlabel' => 'Allocate block to router',
124            );
125   } 
126 }; 
127
128 my $split_link = sub {
129   my $block = shift;
130   my $ref = [ '', '' ];
131   $ref = [ &{$confirm}('split', $block->blocknum), '' ]
132     unless ($block->router);
133   $ref;
134 }; 
135
136 </%init>