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;
19 \&FS::UI::Web::cust_fields,
24 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
25 FS::UI::Web::cust_header()
28 'align' => 'rl'. FS::UI::Web::cust_aligns(),
32 FS::UI::Web::cust_colors(),
37 FS::UI::Web::cust_styles(),
43 unless $FS::CurrentUser::CurrentUser->access_right('List services');
45 my $addl_from = ' LEFT JOIN part_svc USING ( svcpart ) '.
46 ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
47 ' LEFT JOIN cust_main USING ( custnum ) ';
50 my $orderby = 'ORDER BY svcnum'; #has to be ordered by something
51 #for pagination to work
52 if ( length( $cgi->param('search_svc') ) ) {
54 my $string = $cgi->param('search_svc');
55 $string =~ s/(^\s+|\s+$)//; #trim leading & trailing whitespace
57 # implement fuzzy searching in subclasses too at some point?
58 # service searching maybe shouldn't be fuzzy...
63 my $search_sql = "FS::$table"->search_sql($string);
65 AND 0 < ( SELECT COUNT(*) FROM $table
66 WHERE $table.svcnum = cust_svc.svcnum
71 FS::part_svc->svc_tables
74 } elsif ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
76 $cgi->param('svcdb') =~ /^(svc_\w+)$/ or die "unknown svcdb";
77 push @extra_sql, "svcdb = '$1'";
78 $addl_from .= " LEFT JOIN $1 USING ( svcnum ) ";
80 push @extra_sql, 'pkgnum IS NULL'
81 if $cgi->param('magic') eq 'unlinked';
83 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
85 $orderby = "ORDER BY $sortby";
88 } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
90 push @extra_sql, "svcpart = $1";
93 errorpage("No search term specified");
96 #here is the agent virtualization
97 push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql(
98 'null_right' => 'View/link unlinked services'
101 my $extra_sql = ' WHERE '. join(' AND ', @extra_sql );
104 'select' => join(', ',
108 FS::UI::Web::cust_sql_fields(),
110 'table' => 'cust_svc',
111 'addl_from' => $addl_from,
113 'extra_sql' => $extra_sql,
114 'order_by' => $orderby,
117 my $count_query = "SELECT COUNT(*) FROM cust_svc $addl_from $extra_sql";
120 my $cust_svc = shift;
124 #'part_svc' => $cust_svc->part_svc,
125 'svcdb' => $cust_svc->svcdb, #we have it from the joined search
126 #'svc' => $cust_svc, #redundant
132 my $link_cust = sub {
133 my $cust_svc = shift;
134 if ( $cust_svc->custnum ) {
135 [ "${p}view/cust_main.cgi?", 'custnum' ];