Revert "RT# 39340 - configured the minimal selfservice to get mac address from radius...
[freeside.git] / httemplate / search / svc_hardware.cgi
1 <& elements/svc_Common.html,
2             'title'             => 'Hardware service search results',
3             'name'              => 'installations',
4             'query'             => $sql_query,
5             'count_query'       => $count_query,
6             'redirect'          => $link_svc,
7             'header'            => [ '#',
8                                      'Service',
9                                      'Device type',
10                                      '', #revision
11                                      'Serial #',
12                                      'Hardware addr.',
13                                      'IP addr.',
14                                      'Smartcard',
15                                      emt('Pkg. Status'),
16                                      FS::UI::Web::cust_header(),
17                                    ],
18             'fields'            => [ 'svcnum',
19                                      'svc',
20                                      'model',
21                                      'revision',
22                                      'serial',
23                                      'display_hw_addr',
24                                      'ip_addr',
25                                      'smartcard',
26                                      sub {
27                                        $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_svc->cust_pkg;
28                                        return '' unless $cust_pkg_cache{$_[0]->svcnum};
29                                        $cust_pkg_cache{$_[0]->svcnum}->ucfirst_status
30                                      },
31                                      \&FS::UI::Web::cust_fields,
32                                    ],
33             'links'             => [ ($link_svc) x 8,
34                                      '', # pkg status
35                                      ( map { $_ ne 'Cust. Status' ? 
36                                                 $link_cust : '' }
37                                        FS::UI::Web::cust_header() )
38                                    ],
39             'align'             => 'rlllllllr' . FS::UI::Web::cust_aligns(),
40             'color'             => [ ('') x 8,
41                                      sub {
42                                        $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_svc->cust_pkg;
43                                        return '' unless $cust_pkg_cache{$_[0]->svcnum};
44                                        my $c = FS::cust_pkg::statuscolors;
45                                        $c->{$cust_pkg_cache{$_[0]->svcnum}->status };
46                                      }, # pkg status
47                                      FS::UI::Web::cust_colors() ],
48             'style'             => [ $svc_cancel_style, ('') x 7,
49                                      'b',
50                                      FS::UI::Web::cust_styles() ],
51 &>
52 <%init>
53
54 die "access denied"
55   unless $FS::CurrentUser::CurrentUser->access_right('List services');
56
57 my %cust_pkg_cache;
58
59 my $addl_from = '
60  LEFT JOIN cust_svc  USING ( svcnum  )
61  LEFT JOIN part_svc  USING ( svcpart )
62  LEFT JOIN cust_pkg  USING ( pkgnum  )'.
63  FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg').'
64  LEFT JOIN hardware_type USING ( typenum )';
65
66 my @extra_sql;
67 push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql(
68                     'null_right' => 'View/link unlinked services'
69                     );
70
71 if ( $cgi->param('magic') =~ /^(unlinked)$/ ) {
72   push @extra_sql, 'pkgnum IS NULL';
73 }
74
75 if ( lc($cgi->param('serial')) =~ /^(\w+)$/ ) {
76   push @extra_sql, "LOWER(serial) LIKE '%$1%'";
77 }
78
79 if ( $cgi->param('hw_addr') =~ /^(\S+)$/ ) {
80   my $hw_addr = uc($1);
81   $hw_addr =~ s/\W//g;
82   push @extra_sql, "hw_addr LIKE '%$hw_addr%'";
83 }
84
85 if ( $cgi->param('ip_addr') ) {
86   my $ip = NetAddr::IP->new($cgi->param('ip_addr'));
87   push @extra_sql, "ip_addr = '".lc($ip->addr)."'" if $ip;
88 }
89
90 if ( lc($cgi->param('smartcard')) =~ /^(\w+)$/ ) {
91   push @extra_sql, "LOWER(smartcard) LIKE '%$1%'";
92 }
93
94 if ( $cgi->param('statusnum') =~ /^(\d+)$/ ) {
95   push @extra_sql, "statusnum = $1";
96 }
97
98 if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
99   push @extra_sql, "hardware_type.classnum = $1";
100 }
101
102 if ( $cgi->param('model') =~ /^([\w\s]+)$/ ) {
103   push @extra_sql, "hardware_type.model = '$1'";
104 }
105
106 if ( $cgi->param('typenum') =~ /^(\d+)$/ ) {
107   push @extra_sql, "svc_hardware.typenum = $1";
108 }
109
110 if ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
111   push @extra_sql, "cust_svc.svcpart = $1";
112   if (defined($cgi->param('cancelled'))) {
113     if ($cgi->param('cancelled')) {
114       push @extra_sql, "cust_pkg.cancel IS NOT NULL";
115     } else {
116       push @extra_sql, "cust_pkg.cancel IS NULL";
117     }
118   }
119 }
120
121 my ($orderby) = $cgi->param('orderby') =~ /^(\w+( ASC| DESC)?)$/i;
122 $orderby ||= 'svcnum';
123
124 my $extra_sql = '';
125 $extra_sql = ' WHERE '.join(' AND ', @extra_sql) if @extra_sql;
126
127 my $sql_query = {
128   'table'     => 'svc_hardware',
129   'select'    => join(', ', 
130                     'svc_hardware.*',
131                     'part_svc.svc',
132                     'cust_main.custnum',
133                     'hardware_type.model',
134                     'hardware_type.revision',
135                     'cust_pkg.cancel',
136                     FS::UI::Web::cust_sql_fields(),
137                  ),
138   'hashref'   => {},
139   'extra_sql' => $extra_sql,
140   'order_by'  => "ORDER BY $orderby",
141   'addl_from' => $addl_from,
142 };
143 my $count_query = "SELECT COUNT(*) FROM svc_hardware $addl_from $extra_sql";
144 my $link_svc = [ $p.'view/svc_hardware.cgi?', 'svcnum' ];
145 my $link_cust = [ $p.'view/cust_main.cgi?', 'custnum' ];
146
147 my $svc_cancel_style = sub {
148   my $svc = shift;
149   ( $svc->getfield('cancel') == 0 ) ? '' : 's';
150 };
151
152 </%init>