1 <& /elements/header.html, 'Broadband Search Results' &>
3 <& elements/gmap.html, features => \@features, overlays => \@overlays &>
5 <& /elements/footer.html &>
8 die "access denied" unless
9 $FS::CurrentUser::CurrentUser->access_right('List services');
11 my $conf = new FS::Conf;
13 $m->comp('/elements/handle_uri_query');
15 my @features; # geoJSON structure
17 # accept all the search logic from svc_broadband.cgi...
19 if ( $cgi->param('magic') eq 'unlinked' ) {
20 %search_hash = ( 'unlinked' => 1 );
22 foreach (qw( custnum agentnum svcpart cust_fields )) {
23 $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
25 foreach (qw(pkgpart routernum towernum sectornum)) {
26 $search_hash{$_} = [ $cgi->param($_) ] if $cgi->param($_);
30 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
31 $search_hash{'order_by'} = "ORDER BY $1";
34 my $sql_query = FS::svc_broadband->search(\%search_hash);
36 my %routerbyblock = ();
38 my @rows = qsearch($sql_query);
43 foreach my $svc_broadband (@rows) {
44 # don't try to show it if coords aren't set
45 next if !$svc_broadband->latitude || !$svc_broadband->longitude;
46 # coerce coordinates to numbers
48 $svc_broadband->longitude + 0,
49 $svc_broadband->latitude + 0,
51 push @coord, $svc_broadband->altitude + 0
52 if length($svc_broadband->altitude); # it's optional
54 my $svcnum = $svc_broadband->svcnum;
55 my $color = $svc_broadband->addr_status_color;
59 id => 'svc_broadband/'.$svcnum,
62 coordinates => \@coord,
65 #content => include('.svc_broadband', $svc_broadband),
66 url => $fsurl . 'view/svc_broadband-popup.html?' . $svcnum,
74 # look up tower location and draw connecting line
75 next if !$svc_broadband->sectornum;
76 my $sector = $sectors{$svc_broadband->sectornum} ||= $svc_broadband->tower_sector;
77 my $towernum = $sector->towernum;
78 my $tower = $towers{$towernum};
81 $tower = $towers{$towernum} = $sector->tower;
82 $tower_coord{$towernum} =
83 [ $tower->longitude + 0,
85 ($tower->altitude || 0) + 0,
90 if ( $tower->latitude and $tower->longitude ) {
95 coordinates => [ \@coord, $tower_coord{$towernum} ],
99 strokeColor => $color,
105 # also extend tower's ROI to include this point
106 # (this is experimental; might get better results using the centroid of
107 # all connected services or something)
108 my $bounds = $tower_bounds{$towernum} ||= {
109 east => $tower->longitude,
110 west => $tower->longitude,
111 north => $tower->latitude,
112 south => $tower->latitude,
114 if ($coord[0] > $bounds->{east}) {
115 $bounds->{east} = $coord[0];
116 } elsif ($coord[0] < $bounds->{west}) {
117 $bounds->{west} = $coord[0];
119 if ($coord[1] > $bounds->{north}) {
120 $bounds->{north} = $coord[1]
121 } elsif ($coord[1] < $bounds->{south}) {
122 $bounds->{south} = $coord[1]
125 } # if tower has coords
126 } # foreach $svc_broadband
128 foreach my $tower (values(%towers)) {
129 my $towernum = $tower->towernum;
130 my $bounds = $tower_bounds{$towernum};
131 # add some padding for easier reading
132 my $dx = 0.1 * ($bounds->{east} - $bounds->{west});
133 my $dy = 0.1 * ($bounds->{north} - $bounds->{south});
134 $bounds->{east} += $dx;
135 $bounds->{west} -= $dx;
136 $bounds->{north} += $dy;
137 $bounds->{south} -= $dy;
140 id => 'tower/'.$towernum,
143 coordinates => $tower_coord{$towernum},
149 url => $fsurl.'images/antenna-square-21x51.png',
150 anchor => { x => 10, y => 4 }
153 content => include('.tower', $tower),
154 bounds => $tower_bounds{$towernum},
160 foreach my $sector (values %sectors) {
161 if ( length($sector->image) > 0 ) {
163 url => $fsurl.'view/sector_map-png.cgi?' . $sector->sectornum
165 foreach (qw(south north west east)) {
166 $o->{$_} = $sector->get($_) + 0;
175 % my $can_edit = $FS::CurrentUser::CurrentUser->access_right('Configuration');
178 <a target="_blank" href="<% $fsurl %>edit/tower.html?<% $tower->towernum %>">
180 Tower #<% $tower->towernum %> | <% $tower->towername %>