usability: customer tags with checkboxes instead of a select-multiple (fix advanced...
[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 '', @extra_fields
31                                    ],
32 &>
33 <%init>
34
35 die "access denied"
36   unless $FS::CurrentUser::CurrentUser->access_right('Advanced customer search');
37
38 my %search_hash = ();
39
40 #$search_hash{'query'} = $cgi->keywords;
41
42 #scalars
43 my @scalars = qw (
44   agentnum salesnum status
45   address city county state zip country location_history
46   invoice_terms
47   no_censustract with_geocode with_email tax no_tax POST no_POST
48   custbatch usernum
49   cancelled_pkgs
50   cust_fields flattened_pkgs
51   all_tags
52   all_pkg_classnums
53   any_pkg_status
54 );
55
56 for my $param ( @scalars ) {
57   $search_hash{$param} = scalar( $cgi->param($param) )
58     if length($cgi->param($param));
59 }
60
61 #lists
62 for my $param (qw( classnum refnum pkg_classnum )) {
63   $search_hash{$param} = [ $cgi->param($param) ];
64 }
65
66 #tags
67 my $params = $cgi->Vars;
68 $search_hash{'tagnum'} = [
69   map { /^tagnum(\d+)/ && $1 }
70     grep { /^tagnum(\d+)/ && $cgi->param($_) } keys %$params
71 ];
72
73 ###
74 # parse dates
75 ###
76
77 foreach my $field (qw( signupdate birthdate spouse_birthdate anniversary_date )) {
78
79   my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, $field);
80
81   next if $beginning == 0 && $ending == 4294967295 && ( $field ne 'signupdate' || !defined($cgi->param('signuphour')) );
82        #or $disable{$cgi->param('status')}->{$field};
83
84   unless ( $field eq 'signupdate' ) {
85     $beginning -= 43200;
86     $ending    -= 43200;
87   }
88
89   my @ary = ( $beginning, $ending );
90   push @ary, scalar($cgi->param('signuphour')) if $field eq 'signupdate';
91
92   $search_hash{$field} = \@ary;
93
94 }
95
96 ##
97 # amounts
98 ##
99
100 $search_hash{'current_balance'} =
101   [ FS::UI::Web::parse_lt_gt($cgi, 'current_balance') ];
102
103 ###
104 # etc
105 ###
106
107 my $sql_query = FS::cust_main::Search->search(\%search_hash);
108 my $count_query   = delete($sql_query->{'count_query'});
109 my @extra_headers = @{ delete($sql_query->{'extra_headers'}) };
110 my @extra_fields  = @{ delete($sql_query->{'extra_fields'})  };
111
112 my $link = [ "${p}view/cust_main.cgi?", 'custnum' ];
113
114 ###
115 # email links
116 ###
117
118 my $menubar = [];
119
120 if ( $FS::CurrentUser::CurrentUser->access_right('Bulk send customer notices') ) {
121
122   my $uri = new URI;
123   $uri->query_form( \%search_hash );
124   my $query = $uri->query;
125
126   push @$menubar, emt('Email a notice to these customers') =>
127                     "${p}misc/email-customers.html?table=cust_main&$query",
128
129 }
130
131 </%init>