8cdf29d1c2c686d9d37b083e3f3288b7bec70c89
[freeside.git] / httemplate / search / svc_broadband.cgi
1 <& elements/svc_Common.html,
2               'title'       => 'Broadband Search Results',
3               'name'        => 'broadband services',
4               'html_init'   => $html_init,
5               'query'       => $sql_query,
6               'count_query' => $sql_query->{'count_query'},
7               'redirect'    => [ popurl(2). "view/svc_broadband.cgi?", 'svcnum' ],
8               'header'      => [ '#',
9                                  'Service',
10                                  'Router',
11                                  @tower_header,
12                                  'IP Address',
13                                  emt('Pkg. Status'),
14                                  FS::UI::Web::cust_header($cgi->param('cust_fields')),
15                                ],
16               'fields'      => [ 'svcnum',
17                                  'svc',
18                                  sub {
19                                    my $router = shift->router; 
20                                    $router ? $router->routername : '';
21                                  },
22                                  @tower_fields,
23                                  'ip_addr',
24                                  sub {
25                                    $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_svc->cust_pkg;
26                                    return '' unless $cust_pkg_cache{$_[0]->svcnum};
27                                    $cust_pkg_cache{$_[0]->svcnum}->ucfirst_status
28                                  },
29                                  \&FS::UI::Web::cust_fields,
30                                ],
31               'links'       => [ $link,
32                                  $link,
33                                  '', #$link_router,
34                                  (map '', @tower_fields),
35                                  $link,
36                                  '', # pkg status
37                                  ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
38                                        FS::UI::Web::cust_header($cgi->param('cust_fields'))
39                                  ),
40                                ],
41               'align'       => 'rll'.('r' x @tower_fields).'rr'.
42                                 FS::UI::Web::cust_aligns(),
43               'color'       => [ 
44                                  '',
45                                  '',
46                                  '',
47                                  (map '', @tower_fields),
48                                  '',
49                                  sub {
50                                    $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_svc->cust_pkg;
51                                    return '' unless $cust_pkg_cache{$_[0]->svcnum};
52                                    my $c = FS::cust_pkg::statuscolors;
53                                    $c->{$cust_pkg_cache{$_[0]->svcnum}->status };
54                                  }, # pkg status
55                                  FS::UI::Web::cust_colors(),
56                                ],
57               'style'       => [ 
58                                  '',
59                                  '',
60                                  '',
61                                  (map '', @tower_fields),
62                                  '',
63                                  'b',
64                                  FS::UI::Web::cust_styles(),
65                                ],
66           
67 &>
68 <%init>
69
70 die "access denied" unless
71   $FS::CurrentUser::CurrentUser->access_right('List services');
72
73 my %cust_pkg_cache;
74
75 my $conf = new FS::Conf;
76
77 my %search_hash;
78 if ( $cgi->param('magic') eq 'unlinked' ) {
79   %search_hash = ( 'unlinked' => 1 );
80 } else {
81   foreach (qw( custnum agentnum svcpart cust_fields )) {
82     $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
83   }
84   foreach (qw(pkgpart routernum towernum sectornum)) {
85     $search_hash{$_} = [ $cgi->param($_) ] if $cgi->param($_);
86   }
87   if ( defined($cgi->param('cancelled')) ) {
88     $search_hash{'cancelled'} = $cgi->param('cancelled') ? 1 : 0;
89   }
90 }
91
92 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
93   $search_hash{'order_by'} = "ORDER BY $1";
94 }
95
96 my $sql_query = FS::svc_broadband->search(\%search_hash);
97
98 my @tower_header;
99 my @tower_fields;
100 if ( FS::tower_sector->count > 0 ) {
101   push @tower_header, 'Tower/Sector';
102   push @tower_fields, sub { $_[0]->tower_sector ? 
103                             $_[0]->tower_sector->description : '' };
104 }
105
106 my %routerbyblock = ();
107 foreach my $router (qsearch('router', {})) {
108   foreach ($router->addr_block) {
109     $routerbyblock{$_->blocknum} = $router;
110   }
111 }
112
113 my $link = [ $p.'view/svc_broadband.cgi?', 'svcnum' ];
114
115 #XXX get the router link working
116 #my $link_router = sub {
117 #  my $routernum = $routerbyblock{shift->blocknum}->routernum;
118 #  [ $p.'view/router.cgi?'.$routernum, 'routernum' ];
119 #};
120
121 my $link_cust = [ $p.'view/cust_main.cgi?', 'custnum' ];
122
123 my $html_init = include('/elements/email-link.html',
124                   'search_hash' => \%search_hash,
125                   'table' => 'svc_broadband' 
126                 );
127 $html_init .= ' | ' .
128   '<a href="' .
129   $fsurl . 'search/svc_broadband-map.html?' . $cgi->query_string .
130   '">' . emt('View a map of these services') . '</a>';
131
132 </%init>