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 ( $query eq 'svcnum' ) {
15 % #$orderby = "ORDER BY svcnum";
16 %} elsif ( $query eq 'username' ) {
17 % $orderby = "ORDER BY LOWER(username)";
18 %} elsif ( $query eq 'uid' ) {
19 % $orderby = "ORDER BY uid";
20 % push @extra_sql, "uid IS NOT NULL";
21 %} elsif ( $cgi->param('popnum') =~ /^(\d+)$/ ) {
22 % push @extra_sql, "popnum = $1";
23 % $orderby = "ORDER BY LOWER(username)";
24 %} elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
25 % push @extra_sql, "svcpart = $1";
26 % $orderby = "ORDER BY uid";
27 % #$orderby = "ORDER BY svcnum";
29 % $orderby = "ORDER BY uid";
34 % foreach ( $cgi->param('username_type') ) {
35 % $username_type{$_}++;
38 % $cgi->param('username') =~ /^([\w\-\.\&]+)$/; #untaint username_text
41 % push @username_sql, "username ILIKE '$username'"
42 % if $username_type{'Exact'}
43 % || $username_type{'Fuzzy'};
45 % push @username_sql, "username ILIKE '\%$username\%'"
46 % if $username_type{'Substring'}
47 % || $username_type{'All'};
49 % if ( $username_type{'Fuzzy'} || $username_type{'All'} ) {
50 % &FS::svc_acct::check_and_rebuild_fuzzyfiles;
51 % my $all_username = &FS::svc_acct::all_username;
54 % if ( $username_type{'Fuzzy'} || $username_type{'All'} ) {
55 % foreach ( amatch($username, [ qw(i) ], @$all_username) ) {
60 % #if ($username_type{'Sound-alike'}) {
63 % push @username_sql, "username = '$_'"
64 % foreach (keys %username);
68 % push @extra_sql, '( '. join( ' OR ', @username_sql). ' )';
72 %my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
73 % ' LEFT JOIN part_svc USING ( svcpart ) '.
74 % ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
75 % ' LEFT JOIN cust_main USING ( custnum ) ';
77 %#here is the agent virtualization
78 %push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql;
82 % ? ' WHERE '. join(' AND ', @extra_sql )
85 %my $count_query = "SELECT COUNT(*) FROM svc_acct $addl_from $extra_sql";
86 %#if ( keys %svc_acct ) {
87 %# $count_query .= ' WHERE '.
88 %# join(' AND ', map "$_ = ". dbh->quote($svc_acct{$_}),
94 % 'table' => 'svc_acct',
95 % 'hashref' => {}, # \%svc_acct,
96 % 'select' => join(', ',
99 % 'cust_main.custnum',
100 % FS::UI::Web::cust_sql_fields(),
102 % 'extra_sql' => "$extra_sql $orderby",
103 % 'addl_from' => $addl_from,
106 %my $link = [ "${p}view/svc_acct.cgi?", 'svcnum' ];
107 %my $link_cust = sub {
108 % my $svc_acct = shift;
109 % if ( $svc_acct->custnum ) {
110 % [ "${p}view/cust_main.cgi?", 'custnum' ];
117 <% include( 'elements/search.html',
118 'title' => 'Account Search Results',
119 'name' => 'accounts',
120 'query' => $sql_query,
121 'count_query' => $count_query,
127 FS::UI::Web::cust_header(),
129 'fields' => [ 'svcnum',
133 \&FS::UI::Web::cust_fields,
140 FS::UI::Web::cust_header()