summaryrefslogtreecommitdiff
path: root/httemplate/search/elements/grouped-search/html
blob: ae8086512dada51543ef74a162d355e9b24fc927 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<%shared>
my $conf = FS::Conf->new;
</%shared>
<%init>
my %opt = @_;
$opt{'name'} ||= PL($opt{'name_singular'});

my $group_info = $m->comp('core', %opt);

my $redirect;

if ( $group_info->{num} == 0 ) {
  $redirect = $opt{'redirect_empty'};
  $redirect = &$redirect($cgi) if $redirect && ref($redirect) eq 'CODE';
  if ($redirect) {
    redirect( $redirect );
  } else { # just print this stuff and exit
    $m->comp('/elements/header.html', $opt{'title'});
    $m->print('<BR><BR>No matching ' . $opt{'name'} . ' found.<BR>');
    $m->comp('/elements/footer.html');
    $m->abort;
  }
}

# this mode has a concept of "current group"
my $curr_group = 0;
if ($cgi->param('group') =~ /^(\d+)$/) {
  $curr_group = $1;
}

my $group = $group_info->{groups}[$curr_group];
my $query = $group_info->{queries}[$curr_group];
my $footer = $group_info->{group_footers}[$curr_group];
my $total_footer =  $group_info->{total_footer} || [];
# pagination
my ($limit, $offset);
my $maxrecords = $conf->config('maxsearchrecordsperpage') || 100;
if ( $cgi->param('maxrecords') =~ /^(\d+)$/ ) {
  $maxrecords = $1;
}
if ( $maxrecords ) {
  $limit = "LIMIT $maxrecords";
  if ( $cgi->param('offset') =~ /^(\d+)$/ ) {
    $offset = $1;
    $limit .= " OFFSET $offset";
  }
}
$query->{order_by} .= $limit if $limit;

#warn Dumper($query); #DEBUG

# run the query
my @rows = $query->qsearch;

#warn Dumper(\@rows); #DEBUG

my $pager = '';
# show pager if needed
if ( $group->num_rows > scalar(@rows) ) {
  $pager = include( '/elements/pager.html',
    'offset'      => $offset,
    'num_rows'    => scalar(@rows),
    'total'       => $group->num_rows,
    'maxrecords'  => $maxrecords,
  );
}

# set up tab bar
my @menubar;
if ($group_info->{num} > 1) {
  for (my $i = 0; $i < $group_info->{num}; $i++) {
    push @menubar, $group_info->{group_labels}[$i], ";group=$i";
  }
}

# not enabled yet; if we need this at some point, enable it on a per-report
# basis and then disable it for search/cust_pay.html, because it's redundant
# to see "Check   Check #130108", "Credit card   Card #401...", etc.

## if this is the combined view, add a column for the group key
#if ( $curr_group == 0 and $opt{'show_combined'} ) {
#  unshift @{$opt{'header'}}, '';
#  unshift @{$opt{'fields'}}, $opt{group_label};
#  unshift @{$opt{'sort_fields'}}, $opt{group_column} if $opt{'sort_fields'};
#  $opt{'align'} = 'c'.$opt{'align'};
#  foreach (qw(header2 links link_onclicks color size style cell_style xls_format)) {
#    if ( $opt{$_} ) {
#      unshift @{$opt{$_}}, '';
#    }
#  }
#}

my $conf = FS::Conf->new;
my $money = $conf->config('money_char') || '$';
</%init>

<& /elements/header.html, $opt{title} &>

%# tab bar
% $cgi->delete('group');
% $cgi->delete('offset');
% $cgi->delete('type');
<& /elements/menubar.html,
  { newstyle => 1,
    url_base => $cgi->self_url,
    selected => $group_info->{group_labels}[$curr_group] },
  @menubar
&>

<DIV CLASS="fstabcontainer">
% if ( $group->num_rows > 0 ) {
<P><% emt('[quant,_1,_2]', $group->num_rows, $opt{name_singular}) %> for <% emt($money.$group->paid) %>
</P>
%# download links
<P><% emt('Download results:') %>
% $cgi->param('type', 'xls');
<A HREF="<% $cgi->self_url %>"><% emt('Spreadsheet') %></A>&nbsp;|&nbsp;
% $cgi->param('type', 'html-print');
<A HREF="<% $cgi->self_url %>"><% emt('webpage') %></A>
% $cgi->delete('type');
</P>
% }

<% $pager %>

<STYLE>
  table.grid {
    border-spacing: 0;
  }
</STYLE>
<table class="grid">
  <thead>
  <& /search/elements/search-html.html:header_row,
    'header'      => $opt{'header'},
    'header2'     => $opt{'header2'},
    'sort_fields' => ($opt{'sort_fields'} || $opt{'fields'}),
  &>
  </thead>
  <tbody>
  <& /search/elements/search-html.html:data_rows,
    'rows' => \@rows,
    'opt'  => \%opt,
  &>
  </tbody>
  <tfoot>
  <& /search/elements/search-html.html:footer_row, row => $footer, opt => \%opt &>
%   if ( scalar @$total_footer ) {
  <& /search/elements/search-html.html:footer_row, row => $total_footer, opt => \%opt &>
%   }
  </tfoot>
</table>

<% $pager %>
</DIV>

<& /elements/footer.html &>