summaryrefslogtreecommitdiff
path: root/httemplate/browse/addr_block.cgi
blob: 917f94c965ff98796a07924116336d3d61880af9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<% include('elements/browse.html',
                'title'         => 'Address Blocks',
                'name'          => 'address block',
                'html_init'     => $html_init,
                'html_foot'     => $html_foot,
                'query'         => { 'table'     => 'addr_block',
                                     'hashref'   => {},
                                     'extra_sql' => $extra_sql,
                                     'order_by'  => $order_by,
                                   },
                'count_query'   => "SELECT count(*) from addr_block $count_sql",
                'header'        => [ 'Address Block',
                                     'Router',
                                     'Action(s)',
                                     '',
                                   ],
                'fields'        => [ 'NetAddr',
                                     sub { my $block = shift;
                                           my $router = $block->router;
                                           my $result = '';
                                           if ($router) {
                                             $result .= $router->routername. ' (';
                                             $result .= scalar($block->svc_broadband). ' services)';
                                           }
                                           $result;
                                         },
                                     $allocate_text,
                                     sub { shift->router ? '' : '<FONT SIZE="-2">(split)</FONT>' },
                                   ],
                'links'         => [ '',
                                     '',
                                     [ 'javascript:void(0)', '' ],
                                     $split_link,
                                   ],
                'link_onclicks' => [ '',
                                     '',
                                     $allocate_link,
                                     '',
                                   ],
                'cell_styles'   => [ '',
                                     '',
                                     'border-right:none;',
                                     'border-left:none;',
                                   ],
                'agent_virt'    => 1,
                'agent_null_right' => 'Engineering global configuration',
                'agent_pos'     => 1,
          )
%>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Engineering configuration')
  || $FS::CurrentUser::CurrentUser->access_right('Engineering global configuration');

my $p2 = popurl(2);
my $path = $p2 . "edit/process/addr_block";

my $extra_sql = "";

my $count_sql = "WHERE ". $FS::CurrentUser::CurrentUser->agentnums_sql(
  'null_right' => 'Engineering global configuration',
);

my $order_by = "ORDER BY ";
$order_by .= "inet(ip_gateway), " if driver_name =~ /^Pg/i;
$order_by .= "inet_aton(ip_gateway), " if driver_name =~ /^mysql/i;
$order_by .= "ip_netmask";

my $html_init = qq(
<SCRIPT>
  function addr_block_areyousure(href, word) {
    if(confirm("Are you sure you want to "+word+" this address block?") == true)
      window.location.href = href;
  }
</SCRIPT>
);

$html_init .= include('/elements/error.html');

my $confirm = sub {
  my ($verb, $num) = (shift, shift);
  "javascript:addr_block_areyousure('$path/$verb.cgi?blocknum=$num', '$verb')";
};

my $html_foot = qq(
  <FORM ACTION="$path/add.cgi" METHOD="POST">
  Gateway/Netmask: 
  <INPUT TYPE="text" NAME="ip_gateway" SIZE="15">/<INPUT TYPE="text" NAME="ip_netmask" SIZE="2">
);
$html_foot .= include( '/elements/select-agent.html',
                       'agent_virt'       => 1,
                       'agent_null_right' => 'Engineering global configuration',
                     );
$html_foot .= qq(
  <INPUT TYPE="submit" NAME="submit" VALUE="Add">
  </FORM>
);

my $allocate_text = sub { my $block = shift;
                          my $router = $block->router;
                          my $result = '';
                          if ($router) {
                            $result = '<FONT SIZE="-2">(deallocate)</FONT>'
                              unless scalar($block->svc_broadband);
                          }else{
                            $result .= '<FONT SIZE="-2">(allocate)</FONT>'
                          }
                          $result;
};

my $allocate_link = sub {
  my $block = shift;
  if ($block->router) { 
    if (scalar($block->svc_broadband) == 0) { 
      &{$confirm}('deallocate', $block->blocknum);
    } else { 
      "";
    } 
  } else { 
    include( '/elements/popup_link_onclick.html',
             'action' => "${p2}edit/allocate.html?blocknum=". $block->blocknum,
             'actionlabel' => 'Allocate block to router',
           );
  } 
}; 

my $split_link = sub {
  my $block = shift;
  my $ref = [ '', '' ];
  $ref = [ &{$confirm}('split', $block->blocknum), '' ]
    unless ($block->router);
  $ref;
}; 

</%init>