summaryrefslogtreecommitdiff
path: root/httemplate/search/svc_broadband.cgi
blob: 856197725d222a0f80e7a02d3e2f79c6b394a9ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<& elements/svc_Common.html,
              'title'       => 'Broadband Search Results',
              'name'        => 'broadband services',
              'html_init'   => $html_init,
              'query'       => $sql_query,
              'count_query' => $sql_query->{'count_query'},
              'redirect'    => [ popurl(2). "view/svc_broadband.cgi?", 'svcnum' ],
              'header'      => [ '#',
                                 'Service',
                                 'Router',
                                 @tower_header,
                                 'IP Address',
                                 FS::UI::Web::cust_header($cgi->param('cust_fields')),
                               ],
              'fields'      => [ 'svcnum',
                                 'svc',
                                 sub {
                                   my $router = shift->router; 
                                   $router ? $router->routername : '';
                                 },
                                 @tower_fields,
                                 'ip_addr',
                                 \&FS::UI::Web::cust_fields,
                               ],
              'links'       => [ $link,
                                 $link,
                                 '', #$link_router,
                                 (map '', @tower_fields),
                                 $link,
                                 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
                                       FS::UI::Web::cust_header($cgi->param('cust_fields'))
                                 ),
                               ],
              'align'       => 'rll'.('r' x @tower_fields).'r'.
                                FS::UI::Web::cust_aligns(),
              'color'       => [ 
                                 '',
                                 '',
                                 '',
                                 (map '', @tower_fields),
                                 '',
                                 FS::UI::Web::cust_colors(),
                               ],
              'style'       => [ 
                                 '',
                                 '',
                                 '',
                                 (map '', @tower_fields),
                                 '',
                                 FS::UI::Web::cust_styles(),
                               ],
          
&>
<%init>

die "access denied" unless
  $FS::CurrentUser::CurrentUser->access_right('List services');

my $conf = new FS::Conf;

my %search_hash;
if ( $cgi->param('magic') eq 'unlinked' ) {
  %search_hash = ( 'unlinked' => 1 );
} else {
  foreach (qw( custnum agentnum svcpart cust_fields )) {
    $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
  }
  foreach (qw(pkgpart routernum towernum sectornum)) {
    $search_hash{$_} = [ $cgi->param($_) ] if $cgi->param($_);
  }
}

if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
  $search_hash{'order_by'} = "ORDER BY $1";
}

my $sql_query = FS::svc_broadband->search(\%search_hash);

my @tower_header;
my @tower_fields;
if ( FS::tower_sector->count > 0 ) {
  push @tower_header, 'Tower/Sector';
  push @tower_fields, sub { $_[0]->tower_sector ? 
                            $_[0]->tower_sector->description : '' };
}

my %routerbyblock = ();
foreach my $router (qsearch('router', {})) {
  foreach ($router->addr_block) {
    $routerbyblock{$_->blocknum} = $router;
  }
}

my $link = [ $p.'view/svc_broadband.cgi?', 'svcnum' ];

#XXX get the router link working
#my $link_router = sub {
#  my $routernum = $routerbyblock{shift->blocknum}->routernum;
#  [ $p.'view/router.cgi?'.$routernum, 'routernum' ];
#};

my $link_cust = [ $p.'view/cust_main.cgi?', 'custnum' ];

my $html_init = include('/elements/email-link.html',
                  'search_hash' => \%search_hash,
                  'table' => 'svc_broadband' 
                );

</%init>