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