3 %my $orderby = 'ORDER BY svcnum';
5 %my($query)=$cgi->keywords;
6 %$query ||= ''; #to avoid use of unitialized value errors
9 %if ( $query =~ /^UN_(.*)$/ ) {
11 % push @extra_sql, 'pkgnum IS NULL';
14 % if ( $cgi->param('domain') ) {
16 % qsearchs('svc_domain', { 'domain' => $cgi->param('domain') } );
17 % unless ( $svc_domain ) {
18 % #it would be nice if this looked more like the other "not found"
19 % #errors, but this will do for now.
20 % eidiot "Domain ". $cgi->param('domain'). " not found at all";
22 % push @extra_sql, 'domsvc = '. $svc_domain->svcnum;
26 %if ( $query eq 'svcnum' ) {
27 % #$orderby = "ORDER BY svcnum";
28 %} elsif ( $query eq 'username' ) {
29 % $orderby = "ORDER BY LOWER(username)";
30 %} elsif ( $query eq 'uid' ) {
31 % $orderby = "ORDER BY uid";
32 % push @extra_sql, "uid IS NOT NULL";
33 %} elsif ( $cgi->param('popnum') =~ /^(\d+)$/ ) {
34 % push @extra_sql, "popnum = $1";
35 % $orderby = "ORDER BY LOWER(username)";
36 %} elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
37 % push @extra_sql, "svcpart = $1";
38 % $orderby = "ORDER BY uid";
39 % #$orderby = "ORDER BY svcnum";
41 % $orderby = "ORDER BY uid";
46 % foreach ( $cgi->param('username_type') ) {
47 % $username_type{$_}++;
50 % $cgi->param('username') =~ /^([\w\-\.\&]+)$/; #untaint username_text
53 % push @username_sql, "username ILIKE '$username'"
54 % if $username_type{'Exact'}
55 % || $username_type{'Fuzzy'};
57 % push @username_sql, "username ILIKE '\%$username\%'"
58 % if $username_type{'Substring'}
59 % || $username_type{'All'};
61 % if ( $username_type{'Fuzzy'} || $username_type{'All'} ) {
62 % &FS::svc_acct::check_and_rebuild_fuzzyfiles;
63 % my $all_username = &FS::svc_acct::all_username;
66 % if ( $username_type{'Fuzzy'} || $username_type{'All'} ) {
67 % foreach ( amatch($username, [ qw(i) ], @$all_username) ) {
72 % #if ($username_type{'Sound-alike'}) {
75 % push @username_sql, "username = '$_'"
76 % foreach (keys %username);
80 % push @extra_sql, '( '. join( ' OR ', @username_sql). ' )';
84 %my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
85 % ' LEFT JOIN part_svc USING ( svcpart ) '.
86 % ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
87 % ' LEFT JOIN cust_main USING ( custnum ) ';
89 %#here is the agent virtualization
90 %push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql;
94 % ? ' WHERE '. join(' AND ', @extra_sql )
97 %my $count_query = "SELECT COUNT(*) FROM svc_acct $addl_from $extra_sql";
98 %#if ( keys %svc_acct ) {
99 %# $count_query .= ' WHERE '.
100 %# join(' AND ', map "$_ = ". dbh->quote($svc_acct{$_}),
106 % 'table' => 'svc_acct',
107 % 'hashref' => {}, # \%svc_acct,
108 % 'select' => join(', ',
111 % 'cust_main.custnum',
112 % FS::UI::Web::cust_sql_fields(),
114 % 'extra_sql' => "$extra_sql $orderby",
115 % 'addl_from' => $addl_from,
118 %my $link = [ "${p}view/svc_acct.cgi?", 'svcnum' ];
119 %my $link_cust = sub {
120 % my $svc_acct = shift;
121 % if ( $svc_acct->custnum ) {
122 % [ "${p}view/cust_main.cgi?", 'custnum' ];
129 <% include( 'elements/search.html',
130 'title' => 'Account Search Results',
131 'name' => 'accounts',
132 'query' => $sql_query,
133 'count_query' => $count_query,
139 FS::UI::Web::cust_header(),
141 'fields' => [ 'svcnum',
145 \&FS::UI::Web::cust_fields,
152 FS::UI::Web::cust_header()