1 <& elements/search.html,
2 'title' => emt('Service search results'),
3 'name' => emt('services'),
5 'count_query' => $count_query,
7 'header' => [ emt('#'),
10 FS::UI::Web::cust_header(),
12 'fields' => [ 'svcnum',
14 #$_[0]->svc. ': '. $_[0]->label;
15 my($label, $value, $svcdb) = $_[0]->label;
16 my $id = $_[0]->agent_svcid
17 ? $_[0]->agent_svcid.': '
22 \&FS::UI::Web::cust_fields,
27 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
28 FS::UI::Web::cust_header()
31 'align' => 'rl'. FS::UI::Web::cust_aligns(),
35 FS::UI::Web::cust_colors(),
40 FS::UI::Web::cust_styles(),
46 unless $FS::CurrentUser::CurrentUser->access_right('List services');
50 my $orderby = 'ORDER BY svcnum'; #has to be ordered by something
51 #for pagination to work
53 if ( length( $cgi->param('search_svc') ) ) {
56 FS::cust_svc->smart_search_param(
57 'search' => scalar($cgi->param('search_svc'))
63 my $addl_from = ' LEFT JOIN part_svc USING ( svcpart ) '.
64 ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
65 FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg');
69 if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
71 $cgi->param('svcdb') =~ /^(svc_\w+)$/ or die "unknown svcdb";
72 push @extra_sql, "svcdb = '$1'";
73 $addl_from .= " LEFT JOIN $1 USING ( svcnum ) ";
75 push @extra_sql, 'pkgnum IS NULL'
76 if $cgi->param('magic') eq 'unlinked';
78 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
80 $orderby = "ORDER BY $sortby";
83 } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
85 push @extra_sql, "svcpart = $1";
88 errorpage("No search term specified");
91 #here is the agent virtualization
92 push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql(
93 'null_right' => 'View/link unlinked services'
96 my $extra_sql = ' WHERE '. join(' AND ', @extra_sql );
99 'table' => 'cust_svc',
100 'addl_from' => $addl_from,
102 'extra_sql' => $extra_sql,
107 $sql_query->{'select'} = join(', ',
111 FS::UI::Web::cust_sql_fields(),
113 $sql_query->{'order_by'} = $orderby;
115 my $count_query = "SELECT COUNT(*) FROM cust_svc ". $sql_query->{addl_from}.
116 ' '. $sql_query->{extra_sql};
119 my $cust_svc = shift;
123 #'part_svc' => $cust_svc->part_svc,
124 'svcdb' => $cust_svc->svcdb, #we have it from the joined search
125 #'svc' => $cust_svc, #redundant
131 my $link_cust = sub {
132 my $cust_svc = shift;
133 if ( $cust_svc->custnum ) {
134 [ "${p}view/cust_main.cgi?", 'custnum' ];