% # use strict; #use vars qw( $conf %ncancelled_pkgs %all_pkgs $cgi @cust_main $sortby ); use vars qw( $conf %all_pkgs $cgi @cust_main $sortby ); use CGI; use CGI::Carp qw(fatalsToBrowser); use IO::Handle; use String::Approx qw(amatch); use FS::UID qw(cgisuidsetup); use FS::Record qw(qsearch qsearchs dbdef); use FS::CGI qw(header menubar eidiot popurl table); use FS::cust_main; use FS::cust_svc; $cgi = new CGI; cgisuidsetup($cgi); $conf = new FS::Conf; if ( $cgi->param('browse') ) { my $query = $cgi->param('browse'); if ( $query eq 'custnum' ) { $sortby=\*custnum_sort; @cust_main=qsearch('cust_main',{}); } elsif ( $query eq 'last' ) { $sortby=\*last_sort; @cust_main=qsearch('cust_main',{}); } elsif ( $query eq 'company' ) { $sortby=\*company_sort; @cust_main=qsearch('cust_main',{}); } else { die "unknown browse field $query"; } } else { @cust_main=(); &cardsearch if $cgi->param('card_on') && $cgi->param('card'); &lastsearch if $cgi->param('last_on') && $cgi->param('last_text'); &companysearch if $cgi->param('company_on') && $cgi->param('company_text'); &referralsearch if $cgi->param('referral_custnum'); } @cust_main = grep { $_->ncancelled_pkgs || ! $_->all_pkgs } @cust_main if $cgi->param('showcancelledcustomers') eq '0' #see if it was set by me || ( $conf->exists('hidecancelledcustomers') && ! $cgi->param('showcancelledcustomers') ); if ( $conf->exists('hidecancelledpackages' ) ) { %all_pkgs = map { $_->custnum => [ $_->ncancelled_pkgs ] } @cust_main; } else { %all_pkgs = map { $_->custnum => [ $_->all_pkgs ] } @cust_main; } if ( scalar(@cust_main) == 1 && ! $cgi->param('referral_custnum') ) { print $cgi->redirect(popurl(2). "view/cust_main.cgi?". $cust_main[0]->custnum); exit; } elsif ( scalar(@cust_main) == 0 ) { eidiot "No matching customers found!\n"; } else { my($total)=scalar(@cust_main); print $cgi->header( '-expires' => 'now' ), header("Customer Search Results",menubar( 'Main Menu', popurl(2) )), "$total matching customers found "; if ( $cgi->param('showcancelledcustomers') eq '0' #see if it was set by me || ( $conf->exists('hidecancelledcustomers') && ! $cgi->param('showcancelledcustomers') ) ) { $cgi->param('showcancelledcustomers', 1); print qq!( show cancelled customers )!; } else { $cgi->param('showcancelledcustomers', 0); print qq!( hide cancelled customers )!; } if ( $cgi->param('referral_custnum') ) { $cgi->param('referral_custnum') =~ /^(\d+)$/ or eidiot "Illegal referral_custnum\n"; my $referral_custnum = $1; my $cust_main = qsearchs('cust_main', { custnum => $referral_custnum } ); print '
'; } print "