1 <% include( 'elements/search.html',
2 'title' => 'Account Search Results',
5 'count_query' => $count_query,
11 FS::UI::Web::cust_header(),
13 'fields' => [ 'svcnum',
17 \&FS::UI::Web::cust_fields,
23 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
24 FS::UI::Web::cust_header()
27 'align' => 'rlll'. FS::UI::Web::cust_aligns(),
33 FS::UI::Web::cust_colors(),
40 FS::UI::Web::cust_styles(),
47 unless $FS::CurrentUser::CurrentUser->access_right('List services');
51 if ( $cgi->param('domain') ) {
53 qsearchs('svc_domain', { 'domain' => $cgi->param('domain') } );
54 unless ( $svc_domain ) {
55 #it would be nice if this looked more like the other "not found"
56 #errors, but this will do for now.
57 eidiot "Domain ". $cgi->param('domain'). " not found at all";
59 push @extra_sql, 'domsvc = '. $svc_domain->svcnum;
63 my $orderby = 'ORDER BY svcnum';
64 if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
66 push @extra_sql, 'pkgnum IS NULL'
67 if $cgi->param('magic') eq 'unlinked';
69 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
71 $sortby = "LOWER($sortby)"
72 if $sortby eq 'username';
73 push @extra_sql, "$sortby IS NOT NULL"
75 $orderby = "ORDER BY $sortby";
78 } elsif ( $cgi->param('popnum') =~ /^(\d+)$/ ) {
79 push @extra_sql, "popnum = $1";
80 $orderby = "ORDER BY LOWER(username)";
81 } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
82 push @extra_sql, "svcpart = $1";
83 $orderby = "ORDER BY uid";
84 #$orderby = "ORDER BY svcnum";
86 $orderby = "ORDER BY uid";
91 foreach ( $cgi->param('username_type') ) {
95 $cgi->param('username') =~ /^([\w\-\.\&]+)$/; #untaint username_text
98 push @username_sql, "username ILIKE '$username'"
99 if $username_type{'Exact'}
100 || $username_type{'Fuzzy'};
102 push @username_sql, "username ILIKE '\%$username\%'"
103 if $username_type{'Substring'}
104 || $username_type{'All'};
106 if ( $username_type{'Fuzzy'} || $username_type{'All'} ) {
107 &FS::svc_acct::check_and_rebuild_fuzzyfiles;
108 my $all_username = &FS::svc_acct::all_username;
111 if ( $username_type{'Fuzzy'} || $username_type{'All'} ) {
112 foreach ( amatch($username, [ qw(i) ], @$all_username) ) {
117 #if ($username_type{'Sound-alike'}) {
120 push @username_sql, "username = '$_'"
121 foreach (keys %username);
125 push @extra_sql, '( '. join( ' OR ', @username_sql). ' )';
129 my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
130 ' LEFT JOIN part_svc USING ( svcpart ) '.
131 ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
132 ' LEFT JOIN cust_main USING ( custnum ) ';
134 #here is the agent virtualization
135 push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql(
136 'null_right' => 'View/link unlinked services'
141 ? ' WHERE '. join(' AND ', @extra_sql )
144 my $count_query = "SELECT COUNT(*) FROM svc_acct $addl_from $extra_sql";
145 #if ( keys %svc_acct ) {
146 # $count_query .= ' WHERE '.
147 # join(' AND ', map "$_ = ". dbh->quote($svc_acct{$_}),
153 'table' => 'svc_acct',
154 'hashref' => {}, # \%svc_acct,
155 'select' => join(', ',
159 FS::UI::Web::cust_sql_fields(),
161 'extra_sql' => "$extra_sql $orderby",
162 'addl_from' => $addl_from,
165 my $link = [ "${p}view/svc_acct.cgi?", 'svcnum' ];
166 my $link_cust = sub {
167 my $svc_acct = shift;
168 if ( $svc_acct->custnum ) {
169 [ "${p}view/cust_main.cgi?", 'custnum' ];