This commit was generated by cvs2svn to compensate for changes in r8690,
[freeside.git] / httemplate / search / cust_main.html
1 <% include( 'elements/search.html',
2                   'title'       => 'Customer Search Results', 
3                   'menubar'     => $menubar,
4                   'name'        => '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 %>
34 <%init>
35
36 die "access denied"
37   unless ( $FS::CurrentUser::CurrentUser->access_right('List customers') &&
38            $FS::CurrentUser::CurrentUser->access_right('List packages')
39          );
40
41 my %search_hash = ();
42
43 #$search_hash{'query'} = $cgi->keywords;
44
45 #scalars
46 my @scalars = qw (
47   agentnum status cancelled_pkgs cust_fields flattened_pkgs custbatch
48   no_censustract paydate_year paydate_month invoice_terms
49 );
50
51 for my $param ( @scalars ) {
52   $search_hash{$param} = scalar( $cgi->param($param) )
53     if $cgi->param($param);
54 }
55
56 #lists
57 for my $param (qw( classnum payby )) {
58   $search_hash{$param} = [ $cgi->param($param) ];
59 }
60
61 ###
62 # parse dates
63 ###
64
65 foreach my $field (qw( signupdate )) {
66
67   my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, $field);
68
69   next if $beginning == 0 && $ending == 4294967295;
70        #or $disable{$cgi->param('status')}->{$field};
71
72   $search_hash{$field} = [ $beginning, $ending ];
73
74 }
75
76 ##
77 # amounts
78 ##
79
80 $search_hash{'current_balance'} =
81   [ FS::UI::Web::parse_lt_gt($cgi, 'current_balance') ];
82
83 ###
84 # etc
85 ###
86
87 my $sql_query = FS::cust_main->search(\%search_hash);
88 my $count_query   = delete($sql_query->{'count_query'});
89 my @extra_headers = @{ delete($sql_query->{'extra_headers'}) };
90 my @extra_fields  = @{ delete($sql_query->{'extra_fields'})  };
91
92 my $link = [ "${p}view/cust_main.cgi?", 'custnum' ];
93
94 ###
95 # email links
96 ###
97
98 my $menubar = [];
99
100 if ( $FS::CurrentUser::CurrentUser->access_right('Bulk send customer notices') ) {
101
102   my $uri = new URI;
103   $uri->query_form( \%search_hash );
104   my $query = $uri->query;
105
106   push @$menubar, 'Email a notice to these customers' =>
107                     "${p}misc/email-customers.html?$query",
108
109 }
110
111 </%init>