quiet warnings about CGI::param in list context
[freeside.git] / httemplate / search / cust_main.cgi
index c501c50..24d49c5 100755 (executable)
         ( <a href="<% $cgi->self_url %>"><% mt("$linklabel canceled customers") |h %></a> )
 %  }
 
+%  unless ($cgi->param('browse')) {
+    <& /elements/agent_transfer_link.html, {'list' => \@cust_main} &>
+%  }
+
 %  if ( $cgi->param('referral_custnum') ) {
 %    $cgi->param('referral_custnum') =~ /^(\d+)$/
 %      or errorpage(emt("Illegal referral_custnum"));
 %          'select'      => 'part_svc.*, COUNT(*) AS num_cust_svc',
 %          'table'       => 'part_svc', 
 %          'addl_from'   => 'LEFT JOIN cust_svc USING ( svcpart )',
-%          'extra_sql'   => 'WHERE pkgnum = ? GROUP BY part_svc.svcpart',
+%          'extra_sql'   => 'WHERE pkgnum = ? '.
+%                           ' GROUP BY '. join(', ',
+%                             map "part_svc.$_", fields('part_svc')
+%                           ),
 %          'extra_param' => [ [$cust_pkg->pkgnum,'int'] ],
 %        })
 %      ) {
 my $curuser = $FS::CurrentUser::CurrentUser;
 
 die "access denied"
-  unless $curuser->access_right('List all customers');
+  unless $curuser->access_right('List all customers')
+      || $curuser->access_right('List customers');
 
 my $conf = new FS::Conf;
-my $maxrecords = $conf->config('maxsearchrecordsperpage');
+my $maxrecords = $conf->config('maxsearchrecordsperpage') || 100;
 # summarize more than this many services of the same svcpart
 my $large_pkg_size = $conf->config('cust_pkg-large_pkg_size') || 0;
 
@@ -348,9 +356,11 @@ my(@cust_main, $sortby, $orderby);
 my @select = ();
 my @addl_headers = ();
 my @addl_cols = ();
-if ( $cgi->param('browse')
-     || $cgi->param('otaker_on')
-     || $cgi->param('agentnum_on')
+if ( (    $cgi->param('browse')
+       || $cgi->param('otaker_on')
+       || $cgi->param('agentnum_on')
+     )
+     and $curuser->access_right('List all customers')
 ) {
 
   my %search = ();
@@ -498,7 +508,7 @@ if ( $cgi->param('browse')
     );
   }
 
-  @cust_main = grep { $_->num_ncancelled_pkgs || ! $_->num_pkgs } @cust_main
+  @cust_main = grep { $_->status ne 'cancelled' } @cust_main
     if ! $cgi->param('cancelled')
        && (
          $cgi->param('showcancelledcustomers') eq '0' #see if it was set by me
@@ -579,7 +589,7 @@ sub cardsearch {
 
   my($card)=$cgi->param('card');
   $card =~ s/\D//g;
-  $card =~ /^(\d{13,16}|\d{8,9})$/ or errorpage(emt("Illegal card number"));
+  $card =~ /^(\d{13,19}|\d{8,9})$/ or errorpage(emt("Illegal card number"));
   my($payinfo)=$1;
 
   [ qsearch('cust_main',{'payinfo'=>$payinfo, 'payby'=>'CARD'}),
@@ -700,12 +710,20 @@ sub address2search {
       or errorpage(emt("Illegal address2"));
   my $address2 = $1;
 
-  push @cust_main, qsearch( 'cust_main',
-                            { 'address2' => { 'op'    => 'ILIKE',
-                                              'value' => $address2 } } );
-  push @cust_main, qsearch( 'cust_main',
-                            { 'ship_address2' => { 'op'    => 'ILIKE',
-                                                   'value' => $address2 } } );
+  # matching at the start or end of an address, but not in the middle
+  my @where;
+  foreach my $toggle (0,1) {
+    push @where, 'LOWER(cust_location.address2) LIKE LOWER('
+                 . dbh->quote($toggle ? $address2 . '%' : '%' . $address2)
+                 . ')';
+  }
+
+  push @cust_main, qsearch({
+    'debug'     => 1,
+    'table'     => 'cust_main',
+    'addl_from' => 'JOIN cust_location ON (cust_location.locationnum IN (cust_main.bill_locationnum, cust_main.ship_locationnum))',
+    'extra_sql' => 'WHERE ' . join(' OR ',@where),
+  });
 
   \@cust_main;
 }