1 <& elements/search.html,
3 name_singular => 'contact',
4 query => { select => $select,
6 addl_from => $addl_from,
8 extra_sql => $extra_sql,
10 count_query => "SELECT COUNT(*) FROM contact $extra_sql", #XXX
18 unless $FS::CurrentUser::CurrentUser->access_right('List contacts');
20 my $select = 'contact.*';
24 my @header = ( 'First', 'Last', 'Title', );
25 my @fields = ( 'first', 'last', 'title', );
26 my @links = ( '', '', '' );
28 my $company_link = '';
30 if ( $cgi->param('selfservice_access') eq 'Y' ) {
31 $hash{'selfservice_access'} = 'Y';
35 if ( $cgi->param('link') ) {
37 my $coalesce = ', COALESCE( cust_main.company,';
38 my $as = ') AS prospect_or_customer';
40 if ( $cgi->param('link') eq 'cust_main' ) {
41 push @header, 'Customer';
42 $select .= "$coalesce cust_main.first||' '||cust_main.last $as";
43 $addl_from = ' LEFT JOIN cust_main USING ( custnum )';
44 $extra_sql = ' custnum IS NOT NULL ';
45 $company_link = [ $p.'view/cust_main.cgi?', 'custnum' ];
46 } elsif ( $cgi->param('link') eq 'prospect_main' ) {
47 push @header, 'Prospect';
48 $select .= "$coalesce contact.first||' '||contact.last $as";
49 $addl_from = ' LEFT JOIN prospect_main USING ( prospectnum )';
50 $extra_sql = ' prospectnum IS NOT NULL ';
51 $company_link = [ $p.'view/prospect_main.html?', 'prospectnum' ];
53 die "don't know how to report on contacts linked to specified table";
56 #because right now its harder to show it for both kinds of contacts
57 push @fields, 'prospect_or_customer';
58 push @links, $company_link;
62 push @header, 'Self-service';
63 push @fields, 'selfservice_access';
65 $extra_sql = (keys(%hash) ? ' AND ' : ' WHERE '). $extra_sql