From 13f822a442f093f5658e5571c3d236b80be0113f Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 13 Jun 2002 23:00:15 +0000 Subject: fuzzy username searching (Bug#422) --- httemplate/index.html | 2 +- httemplate/search/svc_acct.cgi | 44 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) (limited to 'httemplate') diff --git a/httemplate/index.html b/httemplate/index.html index 8ce12569e..5e47b9464 100644 --- a/httemplate/index.html +++ b/httemplate/index.html @@ -31,7 +31,7 @@
Customer # or all customers by customer number
Last name or all customers by last name
Company or all customers by company
-
Username or all accounts by username
+
Username or all accounts by username
Domain or all domains
diff --git a/httemplate/search/svc_acct.cgi b/httemplate/search/svc_acct.cgi index 0a4338b52..549231d3f 100755 --- a/httemplate/search/svc_acct.cgi +++ b/httemplate/search/svc_acct.cgi @@ -244,10 +244,50 @@ sub uid_sort { sub usernamesearch { + my @svc_acct; + + my %username_type; + foreach ( $cgi->param('username_type') ) { + $username_type{$_}++; + } + $cgi->param('username') =~ /^([\w\-\.\&]+)$/; #untaint username_text - my($username)=$1; + my $username = $1; + + if ( $username_type{'Exact'} || $username_type{'Fuzzy'} ) { + push @svc_acct, qsearch( 'svc_acct', + { 'username' => { 'op' => 'ILIKE', + 'value' => $username } } ); + } + + if ( $username_type{'Substring'} || $username_type{'All'} ) { + push @svc_acct, qsearch( 'svc_acct', + { 'username' => { 'op' => 'ILIKE', + 'value' => "%$username%" } } ); + } + + if ( $username_type{'Fuzzy'} || $username_type{'All'} ) { + &FS::svc_acct::check_and_rebuild_fuzzyfiles; + my $all_username = &FS::svc_acct::all_username; + + my %username; + if ( $username_type{'Fuzzy'} || $username_type{'All'} ) { + foreach ( amatch($username, [ qw(i) ], @$all_username) ) { + $username{$_}++; + } + } + + #if ($username_type{'Sound-alike'}) { + #} + + foreach ( keys %username ) { + push @svc_acct, qsearch('svc_acct',{'username'=>$_}); + } + + } - [ qsearch('svc_acct',{'username'=>$username}) ]; + #[ qsearch('svc_acct',{'username'=>$username}) ]; + \@svc_acct; } -- cgit v1.2.1