per address block ip auto assignment and auto router selection
[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                                    ],
18                 'fields'        => [ 'NetAddr',
19                                      sub { my $block = shift;
20                                            my $router = $block->router;
21                                            my $result = '';
22                                            if ($router) {
23                                              $result .= $router->routername. ' (';
24                                              $result .= scalar($block->svc_broadband). ' services)';
25                                            }
26                                            $result;
27                                          },
28                                      $allocate_text,
29                                      sub { shift->router ? '' : '<FONT SIZE="-2">(split)</FONT>' },
30                                      sub { '<FONT SIZE="-2">('. (shift->manual_flag ? 'allow' : 'prevent'). ' automatic ip assignment)</FONT>' },
31                                    ],
32                 'links'         => [ '',
33                                      '',
34                                      [ 'javascript:void(0)', '' ],
35                                      $split_link,
36                                      $autoassign_link,
37                                    ],
38                 'link_onclicks' => [ '',
39                                      '',
40                                      $allocate_link,
41                                      '',
42                                    ],
43                 'cell_styles'   => [ '',
44                                      '',
45                                      'border-right:none;',
46                                      'border-left:none;',
47                                    ],
48                 'agent_virt'    => 1,
49                 'agent_null_right' => 'Broadband global configuration',
50                 'agent_pos'     => 1,
51           )
52 %>
53 <%init>
54
55 die "access denied"
56   unless $FS::CurrentUser::CurrentUser->access_right('Broadband configuration')
57   || $FS::CurrentUser::CurrentUser->access_right('Broadband global configuration');
58
59 my $p2 = popurl(2);
60 my $path = $p2 . "edit/process/addr_block";
61
62 my $extra_sql = "";
63
64 my $count_sql = "WHERE ". $FS::CurrentUser::CurrentUser->agentnums_sql(
65   'null_right' => 'Broadband global configuration',
66 );
67
68 my $order_by = "ORDER BY ";
69 $order_by .= "inet(ip_gateway), " if driver_name =~ /^Pg/i;
70 $order_by .= "inet_aton(ip_gateway), " if driver_name =~ /^mysql/i;
71 $order_by .= "ip_netmask";
72
73 my $html_init = qq(
74 <SCRIPT>
75   function addr_block_areyousure(href, word) {
76     if(confirm("Are you sure you want to "+word+" this address block?") == true)
77       window.location.href = href;
78   }
79 </SCRIPT>
80 );
81
82 $html_init .= include('/elements/error.html');
83
84 my $confirm = sub {
85   my ($verb, $num) = (shift, shift);
86   "javascript:addr_block_areyousure('$path/$verb.cgi?blocknum=$num', '$verb')";
87 };
88
89 my $html_foot = qq(
90   <FORM ACTION="$path/add.cgi" METHOD="POST">
91   Gateway/Netmask: 
92   <INPUT TYPE="text" NAME="ip_gateway" SIZE="15">/<INPUT TYPE="text" NAME="ip_netmask" SIZE="2">
93 );
94 $html_foot .= include( '/elements/select-agent.html',
95                        'agent_virt'       => 1,
96                        'agent_null_right' => 'Broadband global configuration',
97                      );
98 $html_foot .= qq(
99   <INPUT TYPE="submit" NAME="submit" VALUE="Add">
100   </FORM>
101 );
102
103 my $allocate_text = sub { my $block = shift;
104                           my $router = $block->router;
105                           my $result = '';
106                           if ($router) {
107                             $result = '<FONT SIZE="-2">(deallocate)</FONT>'
108                               unless scalar($block->svc_broadband);
109                           }else{
110                             $result .= '<FONT SIZE="-2">(allocate)</FONT>'
111                           }
112                           $result;
113 };
114
115 my $allocate_link = sub {
116   my $block = shift;
117   if ($block->router) { 
118     if (scalar($block->svc_broadband) == 0) { 
119       &{$confirm}('deallocate', $block->blocknum);
120     } else { 
121       "";
122     } 
123   } else { 
124     include( '/elements/popup_link_onclick.html',
125              'action' => "${p2}edit/allocate.html?blocknum=". $block->blocknum,
126              'actionlabel' => 'Allocate block to router',
127            );
128   } 
129 }; 
130
131 my $split_link = sub {
132   my $block = shift;
133   my $ref = [ '', '' ];
134   $ref = [ &{$confirm}('split', $block->blocknum), '' ]
135     unless ($block->router);
136   $ref;
137 }; 
138
139 my $autoassign_link = sub {
140   my $block = shift;
141   my $url = "$path/manual_flag.cgi?manual_flag=";
142   $url .=  $block->manual_flag ? '' : 'Y';
143   [ "$url;blocknum=", 'blocknum' ];
144 }; 
145
146 </%init>