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