3 # $Id: cust_main.cgi,v 1.3 1998-12-17 09:41:08 ivan Exp $
6 # http://server.name/path/cust_main.cgi
8 # Note: Should be run setuid freeside as user nobody.
10 # ivan@voicenet.com 96-dec-12
12 # rewrite ivan@sisd.com 98-mar-4
14 # now does browsing too ivan@sisd.com 98-mar-6
16 # Changes to allow page to work at a relative position in server
17 # bmccane@maxbaud.net 98-apr-3
19 # display total, use FS::CGI ivan@sisd.com 98-jul-17
21 # $Log: cust_main.cgi,v $
22 # Revision 1.3 1998-12-17 09:41:08 ivan
23 # s/CGI::(Base|Request)/CGI.pm/;
25 # Revision 1.2 1998/11/12 08:10:22 ivan
26 # CGI.pm instead of CGI-modules
27 # relative URLs using popurl
28 # got rid of lots of little tables
29 # s/agrep/String::Approx/;
30 # bubble up packages and services and link (slow)
34 use vars qw(%ncancelled_pkgs %all_pkgs);
36 use CGI::Carp qw(fatalsToBrowser);
38 use String::Approx qw(amatch);
39 use FS::UID qw(cgisuidsetup);
40 use FS::Record qw(qsearch qsearchs);
41 use FS::CGI qw(header menubar idiot popurl table);
50 if ( $cgi->keywords ) {
51 my($query)=$cgi->keywords;
52 if ( $query eq 'custnum' ) {
53 $sortby=\*custnum_sort;
54 @cust_main=qsearch('cust_main',{});
55 } elsif ( $query eq 'last' ) {
57 @cust_main=qsearch('cust_main',{});
58 } elsif ( $query eq 'company' ) {
59 $sortby=\*company_sort;
60 @cust_main=qsearch('cust_main',{});
63 &cardsearch if ( $cgi->param('card_on') && $cgi->param('card') );
64 &lastsearch if ( $cgi->param('last_on') && $cgi->param('last_text') );
65 &companysearch if ( $cgi->param('company_on') && $cgi->param('company_text') );
68 my(%ncancelled_pkgs) =
69 map { $_->custnum => [ $_->ncancelled_pkgs ] } @cust_main;
71 map { $_->custnum => [ $_->all_pkgs ] } @cust_main;
73 if ( scalar(@cust_main) == 1 ) {
74 print $cgi->redirect(popurl(2). "view/cust_main.cgi?". $cust_main[0]->custnum);
76 } elsif ( scalar(@cust_main) == 0 ) {
77 idiot "No matching customers found!\n";
81 my($total)=scalar(@cust_main);
82 print $cgi->header, header("Customer Search Results",menubar(
83 'Main Menu', popurl(2)
84 )), "$total matching customers found<BR>", table, <<END;
90 <TH COLSPAN=2>Services</TH>
96 sort $sortby grep(!$saw{$_->custnum}++, @cust_main)
98 my($custnum,$last,$first,$company)=(
100 $cust_main->getfield('last'),
101 $cust_main->getfield('first'),
106 my($rowspan)=0;#scalar( @{$all_pkgs{$custnum}} );
107 foreach ( @{$all_pkgs{$custnum}} ) {
108 my(@cust_svc) = qsearch( 'cust_svc', { 'pkgnum' => $_->pkgnum } );
109 push @lol_cust_svc, \@cust_svc;
110 $rowspan += scalar(@cust_svc) || 1;
113 #my($rowspan) = scalar(@{$all_pkgs{$custnum}});
114 my($view) = popurl(2). "/view/cust_main.cgi?$custnum";
117 <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$custnum</FONT></A></TD>
118 <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$last, $first</FONT></A></TD>
119 <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$company</FONT></A></TD>
123 foreach ( @{$all_pkgs{$custnum}} ) {
124 my($pkgnum) = ($_->pkgnum);
125 my($pkg) = $_->part_pkg->pkg;
126 my($pkgview) = popurl(2). "/view/cust_pkg.cgi?$pkgnum";
127 #my(@cust_svc) = shift @lol_cust_svc;
128 my(@cust_svc) = qsearch( 'cust_svc', { 'pkgnum' => $_->pkgnum } );
129 my($rowspan) = scalar(@cust_svc) || 1;
131 print $n1, qq!<TD ROWSPAN=$rowspan><A HREF="$pkgview"><FONT SIZE=-1>$pkg</FONT></A></TD>!;
133 foreach my $cust_svc ( @cust_svc ) {
134 my($label, $value, $svcdb) = $cust_svc->label;
135 my($svcnum) = $cust_svc->svcnum;
136 my($sview) = popurl(2). "/view";
137 print $n2,qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$label</FONT></A></TD>!,
138 qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$value</FONT></A></TD>!;
141 #print qq!</TR><TR>\n!;
159 $a->getfield('last') cmp $b->getfield('last');
163 return -1 if $a->company && ! $b->company;
164 return 1 if ! $a->company && $b->company;
165 $a->getfield('company') cmp $b->getfield('company');
169 $a->getfield('custnum') <=> $b->getfield('custnum');
174 my($card)=$cgi->param('card');
176 $card =~ /^(\d{13,16})$/ or do { idiot "Illegal card number\n"; exit; };
179 push @cust_main, qsearch('cust_main',{'payinfo'=>$payinfo, 'payby'=>'CARD'});
185 foreach ( $cgi->param('last_type') ) {
189 $cgi->param('last_text') =~ /^([\w \,\.\-\']*)$/
190 or do { idiot "Illegal last name"; exit; };
193 if ( $last_type{'Exact'}
194 && ! $last_type{'Fuzzy'}
195 # && ! $last_type{'Sound-alike'}
198 push @cust_main, qsearch('cust_main',{'last'=>$last});
204 my(@all_last)=map $_->getfield('last'), qsearch('cust_main',{});
205 if ($last_type{'Fuzzy'}) {
206 foreach ( amatch($last, [ qw(i) ], @all_last) ) {
211 #if ($last_type{'Sound-alike'}) {
214 foreach ( keys %last ) {
215 push @cust_main, qsearch('cust_main',{'last'=>$_});
225 foreach ( $cgi->param('company_type') ) {
229 $cgi->param('company_text') =~ /^([\w \,\.\-\']*)$/
230 or do { idiot "Illegal company"; exit; };
233 if ( $company_type{'Exact'}
234 && ! $company_type{'Fuzzy'}
235 # && ! $company_type{'Sound-alike'}
238 push @cust_main, qsearch('cust_main',{'company'=>$company});
243 my(@all_company)=map $_->company, qsearch('cust_main',{});
245 if ($company_type{'Fuzzy'}) {
246 foreach ( amatch($company, [ qw(i) ], @all_company ) ) {
251 #if ($company_type{'Sound-alike'}) {
254 foreach ( keys %company ) {
255 push @cust_main, qsearch('cust_main',{'company'=>$_});
259 $sortby=\*company_sort;