fix contact self-service disabled on edit (and some basic contact reports), RT#25533...
[freeside.git] / httemplate / search / contact.html
1 <& elements/search.html,
2   title         => 'Contacts',
3   name_singular => 'contact',
4   query         => { select    => $select,
5                      table     => 'contact',
6                      addl_from => $addl_from,
7                      hashref   => \%hash,
8                      extra_sql => $extra_sql,
9                    },
10   count_query   => "SELECT COUNT(*) FROM contact $extra_sql", #XXX
11   header        => \@header,
12   fields        => \@fields,
13   links         => \@links,
14 &>
15 <%init>
16
17 die "access denied"
18   unless $FS::CurrentUser::CurrentUser->access_right('List contacts');
19
20 my $select = 'contact.*';
21 my %hash = ();
22 my $addl_from = '';
23
24 my @header = ( 'First', 'Last', 'Title', );
25 my @fields = ( 'first', 'last', 'title', );
26 my @links = ( '', '', '' );
27
28 my $company_link = '';
29
30 if ( $cgi->param('selfservice_access') eq 'Y' ) {
31   $hash{'selfservice_access'} = 'Y';
32 }
33
34 my $extra_sql = '';
35 if ( $cgi->param('link') ) {
36
37   my $coalesce = ', COALESCE( cust_main.company,';
38   my $as       = ') AS prospect_or_customer';
39
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' ];
52   } else {
53     die "don't know how to report on contacts linked to specified table";
54   }
55
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; 
59
60 }
61
62 push @header, 'Self-service';
63 push @fields, 'selfservice_access';
64
65 $extra_sql = (keys(%hash) ? ' AND ' : ' WHERE '). $extra_sql
66  if $extra_sql;
67
68 </%init>