allow svc_broadband to link directly to a router, #14698
[freeside.git] / httemplate / view / svc_broadband.cgi
1 <& elements/svc_Common.html,
2   table   => 'svc_broadband',
3   labels  => \%labels,
4   fields  => \@fields,
5   svc_callback => \&svc_callback,
6 &>
7 <%init>
8
9 my $conf = FS::Conf->new;
10 my $fields = FS::svc_broadband->table_info->{'fields'};
11 my %labels = map { $_ => ( ref($fields->{$_}) 
12                             ? $fields->{$_}{'label'} 
13                             : $fields->{$_}
14                           );
15                  } keys %$fields;
16
17 #my %labels = ();
18
19 $labels{'description'} = emt('Description');
20 $labels{'router'} = emt('Router');
21 $labels{'speed_down'} = emt('Download Speed');
22 $labels{'speed_up'} = emt('Upload Speed');
23 $labels{'ip_addr'} = emt('IP Address');
24 $labels{'usergroup'} = emt('RADIUS groups'); #?
25
26 $labels{'coordinates'} = 'Latitude/Longitude';
27
28 my @fields = (
29   'description',
30   { field => 'routernum', value => \&router },
31   'speed_down',
32   'speed_up',
33   { field => 'ip_addr', value => \&ip_addr },
34   { field => 'sectornum', value => \&sectornum },
35   'mac_addr',
36   #'latitude',
37   #'longitude',
38   { field => 'coordinates', value => \&coordinates },
39   'altitude',
40   'vlan_profile',
41   'authkey',
42   'plan_id',
43 );
44
45 push @fields,
46   { field => 'usergroup', value => \&usergroup }
47   if $conf->exists('svc_broadband-radius');
48
49 sub router {
50   my $svc = shift;
51   my $router = $svc->router or return '';
52   my $block = $svc->addr_block;
53   $block = '; '.$block->cidr if $block;
54   $router->routernum . ': ' . $router->routername . $block
55 }
56
57 sub ip_addr {
58   my $svc = shift;
59   my $ip_addr = $svc->ip_addr;
60   my $out = $ip_addr;
61   $out .= ' (' . include('/elements/popup_link-ping.html', ip => $ip_addr) . ')'
62     if $ip_addr;
63   if ( my $addr_block = $svc->addr_block ) {
64     $out .= '<br>Netmask: ' . $addr_block->NetAddr->mask .
65             '<br>Gateway: ' . $addr_block->ip_gateway;
66   }
67   $out;
68 }
69
70 sub usergroup {
71   my $svc = shift;
72   my $usergroup = $svc->usergroup;
73   join('<BR>', $svc->radius_groups('long_description'));
74 }
75
76 sub sectornum {
77   my $svc_broadband = shift;
78   return '' unless $svc_broadband->sectornum;
79   my $tower_sector = $svc_broadband->tower_sector;
80   my $link = $tower_sector->ip_addr
81                ? '<A HREF="http://'. $tower_sector->ip_addr. '">'
82                : '';
83
84   $link .  $tower_sector->description. ( $link ? '</A>' : '');
85 }
86
87 sub coordinates {
88   my $s = shift; #$svc_broadband
89   return '' unless $s->latitude && $s->longitude;
90
91   my $d = $s->description;
92   unless ($d) {
93     my $cust_pkg = $s->cust_svc->cust_pkg;
94     $d = $cust_pkg->cust_main->name_short if $cust_pkg;
95   }
96   
97   #'Latitude: '. $s->latitude. ', Longitude: '. $s->longitude. ' '.
98   $s->latitude. ', '. $s->longitude. ' '.
99     include('/elements/coord-links.html', $s->latitude, $s->longitude, $d);
100 }
101
102 sub svc_callback {
103   # trying to move to the callback style
104   my ($cgi, $svc_x, $part_svc, $cust_pkg, $fields, $opt) = @_;
105   # again, we assume at most one of these exports per part_svc
106   my ($nas_export) = $part_svc->part_export('broadband_nas');
107   if ( $nas_export ) {
108     my $nas = qsearchs('nas', { 'svcnum' => $svc_x->svcnum });
109     if ( $nas ) {
110       $svc_x->set($_, $nas->$_) foreach (fields('nas'));
111       push @$fields, qw(shortname secret type ports server community);
112       $opt->{'labels'}{'shortname'}  = 'Short name';
113       $opt->{'labels'}{'secret'}     = 'Shared secret';
114       $opt->{'labels'}{'type'}       = 'Type';
115       $opt->{'labels'}{'ports'}      = 'Ports';
116       $opt->{'labels'}{'server'}     = 'Server';
117       $opt->{'labels'}{'community'}  = 'Community';
118     } #if $nas
119   } #$nas_export
120 };
121
122
123 </%init>