fix error w/current perl - can't call keys on a scalar hashref anymore, RT#77532
[freeside.git] / httemplate / search / cust_main.html
1 <& elements/search.html,
2                   'title'       => emt('Customer Search Results'), 
3                   'menubar'     => $menubar,
4                   'name'        => emt('customers'),
5                   'query'       => $sql_query,
6                   'count_query' => $count_query,
7                   'header'      => [ FS::UI::Web::cust_header(
8                                        $cgi->param('cust_fields')
9                                      ),
10                                      @extra_headers,
11                                    ],
12                   'fields'      => [
13                     \&FS::UI::Web::cust_fields,
14                     @extra_fields,
15                   ],
16                   'color'       => [ FS::UI::Web::cust_colors(),
17                                      map '', @extra_fields
18                                    ],
19                   'style'       => [ FS::UI::Web::cust_styles(),
20                                      map '', @extra_fields
21                                    ],
22                   'align'       => [ FS::UI::Web::cust_aligns(),
23                                      map '', @extra_fields
24                                    ],
25                   'links'       => [ ( map { $_ ne 'Cust. Status' ? $link : '' }
26                                            FS::UI::Web::cust_header(
27                                                       $cgi->param('cust_fields')
28                                                                    )
29                                      ),
30                                      map  { $_ eq 'num_referrals'
31                                               ? $referral_link
32                                               : ''
33                                           }
34                                        @extra_fields
35                                    ],
36 &>
37 <%init>
38
39 die "access denied"
40   unless $FS::CurrentUser::CurrentUser->access_right('Advanced customer search');
41
42 my %search_hash = ();
43
44 #$search_hash{'query'} = $cgi->keywords;
45
46 #scalars
47 my @scalars = qw (
48   agentnum salesnum status
49   address city county state zip country location_history
50   invoice_terms
51   no_censustract with_geocode with_email tax no_tax POST no_POST
52   custbatch usernum
53   cancelled_pkgs
54   cust_fields flattened_pkgs
55   all_tags
56   all_pkg_classnums
57   any_pkg_status
58   with_referrals referral_status
59 );
60
61 for my $param ( @scalars ) {
62   $search_hash{$param} = scalar( $cgi->param($param) )
63     if length($cgi->param($param));
64 }
65
66 #lists
67 for my $param (qw( classnum refnum pkg_classnum )) {
68   $search_hash{$param} = [ $cgi->param($param) ];
69 }
70
71 my $params = $cgi->Vars;
72
73 #contacts
74 $search_hash{'contacts'} = {
75   map { $_ => $cgi->param($_), }
76     grep { /^(contacts_*)/ && $cgi->param($_) }
77       keys %$params
78 };
79
80 #tags
81 $search_hash{'tagnum'} = [
82   map { /^tagnum(\d+)/ && $1 }
83     grep { /^tagnum(\d+)/ && $cgi->param($_) }
84       keys %$params
85 ];
86
87 ###
88 # parse dates
89 ###
90
91 foreach my $field (qw( signupdate birthdate spouse_birthdate anniversary_date )) {
92
93   my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, $field);
94
95   next if $beginning == 0 && $ending == 4294967295 && ( $field ne 'signupdate' || !defined($cgi->param('signuphour')) );
96        #or $disable{$cgi->param('status')}->{$field};
97
98   unless ( $field eq 'signupdate' ) {
99     $beginning -= 43200;
100     $ending    -= 43200;
101   }
102
103   my @ary = ( $beginning, $ending );
104   push @ary, scalar($cgi->param('signuphour')) if $field eq 'signupdate';
105
106   $search_hash{$field} = \@ary;
107
108 }
109
110 ##
111 # amounts
112 ##
113
114 $search_hash{'current_balance'} =
115   [ FS::UI::Web::parse_lt_gt($cgi, 'current_balance') ];
116
117 ###
118 # etc
119 ###
120
121 my $sql_query = FS::cust_main::Search->search(\%search_hash);
122 my $count_query   = delete($sql_query->{'count_query'});
123 my @extra_headers = @{ delete($sql_query->{'extra_headers'}) };
124 my @extra_fields  = @{ delete($sql_query->{'extra_fields'})  };
125
126 my $link = [ "${p}view/cust_main.cgi?", 'custnum' ];
127
128 my $referral_link = [ "${p}search/cust_main.cgi?referral_custnum=", 'custnum' ];
129
130 ###
131 # email links
132 ###
133
134 my $menubar = [];
135
136 if ( $FS::CurrentUser::CurrentUser->access_right('Bulk send customer notices') ) {
137
138   my $uri = new URI;
139   $uri->query_form( \%search_hash );
140   my $query = $uri->query;
141
142   push @$menubar, emt('Email a notice to these customers') =>
143                     "${p}misc/email-customers.html?table=cust_main&$query",
144
145 }
146
147 </%init>