disabling a taxclass, RT#5472
[freeside.git] / httemplate / edit / svc_broadband.cgi
1 <% include('elements/svc_Common.html',
2      'post_url'             => popurl(1). 'process/svc_broadband.cgi',
3      'name'                 => 'broadband service',
4      'table'                => 'svc_broadband',
5      'labels'               => { 'svcnum'       => 'Service #',
6                                  'description'  => 'Description',
7                                  'ip_addr'      => 'IP address',
8                                  'speed_down'   => 'Download speed',
9                                  'speed_up'     => 'Upload speed',
10                                  'blocknum'     => 'Router/Block',
11                                  'block_label'  => 'Router/Block',
12                                  'mac_addr'     => 'MAC address',
13                                  'latitude'     => 'Latitude',
14                                  'longitude'    => 'Longitude',
15                                  'altitude'     => 'Altitude',
16                                  'vlan_profile' => 'VLAN profile',
17                                  'performance_profile' => 'Performance profile',
18                                  'authkey'      => 'Authentication key',
19                                },
20      'fields'               => \@fields, 
21      'field_callback'       => $callback,
22      'dummy'                => $cgi->query_string,
23      )
24 %>
25 <%init>
26
27 die "access denied"
28   unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?
29
30 # If it's stupid but it works, it's still stupid.
31 #  -Kristian
32
33 my $conf = new FS::Conf;
34
35 my @fields = (
36   qw( description ip_addr speed_down speed_up blocknum ),
37   { field=>'block_label', type=>'fixed' },
38   qw( mac_addr latitude longitude altitude vlan_profile performance_profile authkey )
39 );
40
41 my $fixedblock = '';
42
43 my $callback = sub {
44   my ($cgi, $object, $fieldref) = @_;
45
46   my $svcpart = $object->svcnum ? $object->cust_svc->svcpart
47                                 : $cgi->param('svcpart');
48
49   my $part_svc = qsearchs( 'part_svc', { svcpart => $svcpart } );
50   die "No part_svc entry!" unless $part_svc;
51
52   my $columndef = $part_svc->part_svc_column($fieldref->{'field'});
53   if ($columndef->columnflag eq 'F') {
54     $fieldref->{'type'} = 'fixed';
55     $fieldref->{'value'} = $columndef->columnvalue;
56     $fixedblock = $fieldref->{value}
57       if $fieldref->{field} eq 'blocknum';
58   }
59
60   if ($object->svcnum) { 
61
62     $fieldref->{type} = 'hidden'
63       if $fieldref->{field} eq 'blocknum';
64       
65     $fieldref->{value} = $object->addr_block->label
66       if $fieldref->{field} eq 'block_label';
67
68   } else { 
69
70     if ($fieldref->{field} eq 'block_label') {
71       if ($fixedblock) {
72         $object->blocknum($fixedblock);
73         $fieldref->{value} = $object->addr_block->label;
74       }else{
75         $fieldref->{type} = 'hidden';
76       }
77     }
78
79     if ($fieldref->{field} eq 'blocknum') {
80       if ( $fixedblock or $conf->exists('auto_router') ) {
81         $fieldref->{type} = 'hidden';
82         $fieldref->{value} = $fixedblock;
83         return;
84       }
85
86       my $cust_pkg = qsearchs( 'cust_pkg', {pkgnum => $cgi->param('pkgnum')} );
87       die "No cust_pkg entry!" unless $cust_pkg;
88
89       $object->svcpart($part_svc->svcpart);
90       my @addr_block =
91         grep {  ! $_->agentnum
92                || $cust_pkg->cust_main->agentnum == $_->agentnum
93                && $FS::CurrentUser::CurrentUser->agentnum($_->agentnum)
94              }
95         map { $_->addr_block } $object->allowed_routers;
96       my @options = map { $_->blocknum } @addr_block;
97       my %option_labels = map { ( $_->blocknum => $_->label ) } @addr_block;
98       $fieldref->{type}    = 'select';
99       $fieldref->{options} = \@options;
100       $fieldref->{labels}  = \%option_labels;
101     }
102
103   }
104 }; 
105
106 </%init>