3 % if ( $cgi->param('domain') ) {
5 % qsearchs('svc_domain', { 'domain' => $cgi->param('domain') } );
6 % unless ( $svc_domain ) {
7 % #it would be nice if this looked more like the other "not found"
8 % #errors, but this will do for now.
9 % eidiot "Domain ". $cgi->param('domain'). " not found at all";
11 % push @extra_sql, 'domsvc = '. $svc_domain->svcnum;
15 %my $orderby = 'ORDER BY svcnum';
16 %if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
18 % push @extra_sql, 'pkgnum IS NULL'
19 % if $cgi->param('magic') eq 'unlinked';
21 % if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
23 % $sortby = "LOWER($sortby)"
24 % if $sortby eq 'username';
25 % push @extra_sql, "$sortby IS NOT NULL"
26 % if $sortby eq 'uid';
27 % $orderby = "ORDER BY $sortby";
30 %} elsif ( $cgi->param('popnum') =~ /^(\d+)$/ ) {
31 % push @extra_sql, "popnum = $1";
32 % $orderby = "ORDER BY LOWER(username)";
33 %} elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
34 % push @extra_sql, "svcpart = $1";
35 % $orderby = "ORDER BY uid";
36 % #$orderby = "ORDER BY svcnum";
38 % $orderby = "ORDER BY uid";
43 % foreach ( $cgi->param('username_type') ) {
44 % $username_type{$_}++;
47 % $cgi->param('username') =~ /^([\w\-\.\&]+)$/; #untaint username_text
50 % push @username_sql, "username ILIKE '$username'"
51 % if $username_type{'Exact'}
52 % || $username_type{'Fuzzy'};
54 % push @username_sql, "username ILIKE '\%$username\%'"
55 % if $username_type{'Substring'}
56 % || $username_type{'All'};
58 % if ( $username_type{'Fuzzy'} || $username_type{'All'} ) {
59 % &FS::svc_acct::check_and_rebuild_fuzzyfiles;
60 % my $all_username = &FS::svc_acct::all_username;
63 % if ( $username_type{'Fuzzy'} || $username_type{'All'} ) {
64 % foreach ( amatch($username, [ qw(i) ], @$all_username) ) {
69 % #if ($username_type{'Sound-alike'}) {
72 % push @username_sql, "username = '$_'"
73 % foreach (keys %username);
77 % push @extra_sql, '( '. join( ' OR ', @username_sql). ' )';
81 %my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
82 % ' LEFT JOIN part_svc USING ( svcpart ) '.
83 % ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
84 % ' LEFT JOIN cust_main USING ( custnum ) ';
86 %#here is the agent virtualization
87 %push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql;
91 % ? ' WHERE '. join(' AND ', @extra_sql )
94 %my $count_query = "SELECT COUNT(*) FROM svc_acct $addl_from $extra_sql";
95 %#if ( keys %svc_acct ) {
96 %# $count_query .= ' WHERE '.
97 %# join(' AND ', map "$_ = ". dbh->quote($svc_acct{$_}),
103 % 'table' => 'svc_acct',
104 % 'hashref' => {}, # \%svc_acct,
105 % 'select' => join(', ',
108 % 'cust_main.custnum',
109 % FS::UI::Web::cust_sql_fields(),
111 % 'extra_sql' => "$extra_sql $orderby",
112 % 'addl_from' => $addl_from,
115 %my $link = [ "${p}view/svc_acct.cgi?", 'svcnum' ];
116 %my $link_cust = sub {
117 % my $svc_acct = shift;
118 % if ( $svc_acct->custnum ) {
119 % [ "${p}view/cust_main.cgi?", 'custnum' ];
126 <% include( 'elements/search.html',
127 'title' => 'Account Search Results',
128 'name' => 'accounts',
129 'query' => $sql_query,
130 'count_query' => $count_query,
136 FS::UI::Web::cust_header(),
138 'fields' => [ 'svcnum',
142 \&FS::UI::Web::cust_fields,
149 FS::UI::Web::cust_header()