quiet warnings about CGI::param in list context
[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                                  'Upload Speed (Kbps)',
14                                  'Download Speed (Kbps)',
15                                  @header_pkg,
16                                  emt('Pkg. Status'),
17                                  FS::UI::Web::cust_header($cgi->param('cust_fields')),
18                                ],
19               'fields'      => [ 'svcnum',
20                                  'svc',
21                                  sub {
22                                    my $router = shift->router; 
23                                    $router ? $router->routername : '';
24                                  },
25                                  @tower_fields,
26                                  'ip_addr',
27                                  'speed_up',
28                                  'speed_down',
29                                  @fields_pkg,
30                                  sub {
31                                    $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_svc->cust_pkg;
32                                    return '' unless $cust_pkg_cache{$_[0]->svcnum};
33                                    $cust_pkg_cache{$_[0]->svcnum}->ucfirst_status
34                                  },
35                                  \&FS::UI::Web::cust_fields,
36                                ],
37               'links'       => [ $link,
38                                  $link,
39                                  '', #$link_router,
40                                  (map '', @tower_fields),
41                                  $link, # ip_addr
42                                  $link, # speed_up
43                                  $link, # speed_down
44                                  @blank_pkg,
45                                  '', # pkg status
46                                  ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
47                                        FS::UI::Web::cust_header($cgi->param('cust_fields'))
48                                  ),
49                                ],
50               'align'       => 'rll'.('r' x @tower_fields).
51                                 'rrr'. # ip_addr, speed_up, speed_down
52                                 $align_pkg.
53                                 'r'. # pkg status
54                                 FS::UI::Web::cust_aligns(),
55               'color'       => [ 
56                                  '',
57                                  '',
58                                  '',
59                                  (map '', @tower_fields),
60                                  '', # ip_addr
61                                  '', # speed_up
62                                  '', # speed_down
63                                  @blank_pkg,
64                                  sub {
65                                    $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_svc->cust_pkg;
66                                    return '' unless $cust_pkg_cache{$_[0]->svcnum};
67                                    my $c = FS::cust_pkg::statuscolors;
68                                    $c->{$cust_pkg_cache{$_[0]->svcnum}->status };
69                                  }, # pkg status
70                                  FS::UI::Web::cust_colors(),
71                                ],
72               'style'       => [ 
73                                  '',
74                                  '',
75                                  '',
76                                  (map '', @tower_fields),
77                                  '',  # ip_addr
78                                  '', # speed_up
79                                  '', # speed_down
80                                  @blank_pkg,
81                                  'b', # pkg status
82                                  FS::UI::Web::cust_styles(),
83                                ],
84           
85 &>
86 <%init>
87
88 die "access denied" unless
89   $FS::CurrentUser::CurrentUser->access_right('List services');
90
91 my %cust_pkg_cache;
92
93 my $conf = new FS::Conf;
94
95 $m->comp('/elements/handle_uri_query');
96
97 my %search_hash;
98 if ( $cgi->param('magic') eq 'unlinked' ) {
99   %search_hash = ( 'unlinked' => 1 );
100 } else {
101   foreach (qw( custnum agentnum svcpart cust_fields )) {
102     $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
103   }
104   foreach (qw(pkgpart routernum towernum sectornum)) {
105     $search_hash{$_} = [ $cgi->param($_) ] if $cgi->param($_);
106   }
107   if ( defined($cgi->param('cancelled')) ) {
108     $search_hash{'cancelled'} = $cgi->param('cancelled') ? 1 : 0;
109   }
110 }
111
112 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
113   $search_hash{'order_by'} = "ORDER BY $1";
114 }
115
116 my $sql_query = FS::svc_broadband->search(\%search_hash);
117
118 my @tower_header;
119 my @tower_fields;
120 if ( FS::tower_sector->count > 0 ) {
121   push @tower_header, 'Tower/Sector';
122   push @tower_fields, sub { $_[0]->tower_sector ? 
123                             $_[0]->tower_sector->description : '' };
124 }
125
126 my %routerbyblock = ();
127 foreach my $router (qsearch('router', {})) {
128   foreach ($router->addr_block) {
129     $routerbyblock{$_->blocknum} = $router;
130   }
131 }
132
133 my $link = [ $p.'view/svc_broadband.cgi?', 'svcnum' ];
134
135 #XXX get the router link working
136 #my $link_router = sub {
137 #  my $routernum = $routerbyblock{shift->blocknum}->routernum;
138 #  [ $p.'view/router.cgi?'.$routernum, 'routernum' ];
139 #};
140
141 my $link_cust = [ $p.'view/cust_main.cgi?', 'custnum' ];
142
143 my $html_init = include('/elements/email-link.html',
144                   'search_hash' => \%search_hash,
145                   'table' => 'svc_broadband' 
146                 );
147
148 my $query = $m->scomp('/elements/create_uri_query');
149
150 $html_init .= ' | ' .
151   '<a href="' .
152   $fsurl . 'search/svc_broadband-map.html?' . $query .
153   '">' . emt('View a map of these services') . '</a>';
154
155 my (@header_pkg,@fields_pkg,@blank_pkg);
156 my $align_pkg = '';
157 #false laziness with search/svc_acct.cgi
158 $cgi->param('cust_pkg_fields') =~ /^([\w\,]*)$/ or die "bad cust_pkg_fields";
159 my @pkg_fields = split(',', $1);
160 foreach my $pkg_field ( @pkg_fields ) {
161   ( my $header = ucfirst($pkg_field) ) =~ s/_/ /; #:/
162   push @header_pkg, $header;
163
164   #not the most efficient to do it every field, but this is of niche use. so far
165   push @fields_pkg, sub { my $svc_x = shift;
166                           my $cust_pkg = $svc_x->cust_svc->cust_pkg or return '';
167                           my $value;
168                           if ($pkg_field eq 'package') {
169                             $value = $cust_pkg->part_pkg->pkg;
170                             #$value = $cust_pkg->pkg_label;
171                           }
172                           else {
173                             $value = $cust_pkg->get($pkg_field);#closures help alot 
174                             $value ? time2str('%b %d %Y', $value ) : '';
175                           }
176                         };
177
178   push @blank_pkg, '';
179   $align_pkg .= 'c';
180 }
181
182
183 </%init>