1 <% include( 'elements/search.html',
2 'title' => 'Service search results',
5 'count_query' => $count_query,
10 FS::UI::Web::cust_header(),
12 'fields' => [ 'svcnum',
14 #$_[0]->svc. ': '. $_[0]->label;
15 my($label, $value, $svcdb) = $_[0]->label;
19 \&FS::UI::Web::cust_fields,
25 FS::UI::Web::cust_header()
32 my $addl_from = ' LEFT JOIN part_svc USING ( svcpart ) '.
33 ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
34 ' LEFT JOIN cust_main USING ( custnum ) ';
37 my $orderby = 'ORDER BY svcnum'; #has to be ordered by something
38 #for pagination to work
39 if ( length( $cgi->param('search_svc') ) ) {
41 my $string = $cgi->param('search_svc');
42 $string =~ s/(^\s+|\s+$)//; #trim leading & trailing whitespace
44 # implement fuzzy searching in subclasses too at some point?
45 # service searching maybe shouldn't be fuzzy...
50 my $search_sql = "FS::$table"->search_sql($string);
52 AND 0 < ( SELECT COUNT(*) FROM $table
53 WHERE $table.svcnum = cust_svc.svcnum
58 FS::part_svc->svc_tables
61 } elsif ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
63 $cgi->param('svcdb') =~ /^(svc_\w+)$/ or die "unknown svcdb";
64 push @extra_sql, "svcdb = '$1'";
66 push @extra_sql, 'pkgnum IS NULL'
67 if $cgi->param('magic') eq 'unlinked';
69 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
71 $orderby = "ORDER BY $sortby";
74 } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
76 push @extra_sql, "svcpart = $1";
79 eidiot("No search term specified");
82 #here is the agent virtualization
83 push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql;
85 my $extra_sql = ' WHERE '. join(' AND ', @extra_sql );
88 'select' => join(', ',
92 FS::UI::Web::cust_sql_fields(),
94 'table' => 'cust_svc',
95 'addl_from' => $addl_from,
97 'extra_sql' => "$extra_sql $orderby",
100 my $count_query = "SELECT COUNT(*) FROM cust_svc $addl_from $extra_sql";
103 my $cust_svc = shift;
104 my $url = FS::UI::Web::svc_url(
107 #'part_svc' => $cust_svc->part_svc,
108 'svcdb' => $cust_svc->svcdb, #we have it from the joined search
109 #'svc' => $cust_svc, #redundant
115 my $link_cust = sub {
116 my $cust_svc = shift;
117 if ( $cust_svc->custnum ) {
118 [ "${p}view/cust_main.cgi?", 'custnum' ];