1 % if ( exists($opt{'redirect'}) && $opt{'redirect'}
2 % && scalar(@$rows) == 1 && $total == 1
3 % && $type ne 'html-print'
5 % my $redirect = $opt{'redirect'};
6 % $redirect = &{$redirect}($rows->[0], $cgi) if ref($redirect) eq 'CODE';
7 % my( $url, $method ) = @$redirect;
8 % redirect( $url. $rows->[0]->$method() );
9 % } elsif ( exists($opt{'redirect_empty'}) && ! scalar(@$rows) && $total == 0
10 % && $type ne 'html-print'
11 % && $opt{'redirect_empty'}
12 % && ( ref($opt{'redirect_empty'}) ne 'CODE'
13 % || &{$opt{'redirect_empty'}}($cgi) )
15 % my $redirect = $opt{'redirect_empty'};
16 % $redirect = &{$redirect}($cgi) if ref($redirect) eq 'CODE';
17 % redirect( $redirect );
19 % if ( $opt{'name_singular'} ) {
20 % $opt{'name'} = PL($opt{'name_singular'});
22 % ( my $xlsname = $opt{'name'} ) =~ s/\W//g;
23 % if ( $total == 1 ) {
24 % if ( $opt{'name_singular'} ) {
25 % $opt{'name'} = $opt{'name_singular'}
27 % #$opt{'name'} =~ s/s$// if $total == 1;
28 % $opt{'name'} =~ s/((s)e)?s$/$2/ if $total == 1;
32 % unless ( $opt{nohtmlheader} ) {
34 % if ( $type eq 'html-print' ) {
35 <& /elements/header-popup.html, $opt{'title'} &>
37 % if ( $type eq 'select' ) {
38 <&/elements/header-popup.html, $opt{'title'} &>
42 % if ( $opt{'menubar'} ) {
43 % @menubar = @{ $opt{'menubar'} };
45 % # @menubar = ( 'Main menu' => $p );
48 <& /elements/header.html, $opt{'title'},
49 include( '/elements/menubar.html', @menubar )
57 % unless ( $type eq 'html-print' ) {
59 % if ( $opt{'add_link'} ) { #or after html_init?
60 <A HREF="<%$p%>edit/<% $opt{query}->{table} %>.html"><I>Add a <% $opt{'name_singular'} %></I></A><BR><BR>
63 <% defined($opt{'html_init'})
64 ? ( ref($opt{'html_init'})
65 ? &{$opt{'html_init'}}()
74 % unless ( $opt{'disable_nonefound'} ) {
75 <BR><BR>No matching <% $opt{'name'} %> found.<BR>
79 % if ( $total || $opt{'disableable'} ) { #hmm... and there *are* ones to show??
88 % if (! $opt{'disable_total'}) {
89 <% $total %> total <% $opt{'name'} %>
92 % if ( $confmax && $total > $confmax
93 % && ! $opt{'disable_maxselect'}
94 % && $type ne 'html-print' )
96 % $cgi->delete('maxrecords');
97 % $cgi->param('_dummy', 1);
99 ( show <SELECT NAME="maxrecords" onChange="window.location = '<% "$self_url?". $cgi->query_string %>;maxrecords=' + this.options[this.selectedIndex].value;">
101 % foreach my $max ( map { $_ * $confmax } qw( 1 5 10 25 ) ) {
102 <OPTION VALUE="<% $max %>" <% ( $maxrecords == $max ) ? 'SELECTED' : '' %>><% $max %></OPTION>
107 % $cgi->param('maxrecords', $maxrecords);
110 % if ( defined($opt{'html_posttotal'}) && $type ne 'html-print' ) {
111 <% ref($opt{'html_posttotal'})
112 ? &{$opt{'html_posttotal'}}()
113 : $opt{'html_posttotal'}
118 % if ( $opt{'count_addl'} ) {
120 % foreach my $count ( @{$opt{'count_addl'}} ) {
121 % my $data = $count_arrayref->[++$n];
122 % if ( ref($count) ) {
123 <% &{ $count }( $data ) %>
125 <% sprintf( $count, $data ) %><BR>
133 % if ( $curuser->access_right('Download report data')
134 % and !$opt{'disable_download'}
135 % and $type ne 'html-print' ) {
137 <TD ALIGN="right" CLASS="noprint">
139 <% $opt{'download_label'} || 'Download full results' %><BR>
141 % $cgi->param('_type', "$xlsname.xls" );
142 as <A HREF="<% "$self_url?". $cgi->query_string %>">Excel spreadsheet</A><BR>
144 % $cgi->param('_type', 'csv');
145 as <A HREF="<% "$self_url?". $cgi->query_string %>">CSV file</A><BR>
147 % if ( defined($opt{xml_elements}) ) {
148 % $cgi->param('_type', 'xml');
149 as <A HREF="<% "$self_url?". $cgi->query_string %>">XML file</A><BR>
152 % $cgi->param('_type', 'html-print');
153 as <A HREF="<% "$self_url?". $cgi->query_string %>">printable copy</A>
156 % $cgi->param('_type', "html" );
164 % unless ( $type eq 'html_print' ) {
166 <% $pager = include( '/elements/pager.html',
168 'num_rows' => scalar(@$rows),
170 'maxrecords' => $maxrecords,
174 <% defined($opt{'html_form'})
175 ? ( ref($opt{'html_form'})
176 ? &{$opt{'html_form'}}()
184 <% include('/elements/table-grid.html') %>
189 % my @fields = @{ $opt{'sort_fields'} || $opt{'fields'} || [] };
190 % my $order_by = $cgi->param('order_by');
191 % foreach my $header ( @{ $opt{header} } ) {
193 % my $field = shift @fields;
195 % $colspan-- if $colspan > 0;
198 % my $label = ref($header) ? $header->{label} : $header;
199 % unless ( ref($field) || !$field ) {
200 % if ( $order_by eq $field ) {
201 % $cgi->param('order_by', "$field DESC");
203 % $cgi->param('order_by', $field);
205 % $label = qq(<A HREF="$self_url?). $cgi->query_string.
209 % $colspan = ref($header) ? $header->{colspan} : 0;
212 % if ( $opt{header2} ) {
213 % if ( !length($opt{header2}->[$h2]) ) {
215 % splice @{ $opt{header2} }, $h2, 1;
218 % $style = 'STYLE="border-bottom: none"'
223 ROWSPAN = "<% $rowspan %>"
224 <% $colspan ? 'COLSPAN = "'.$colspan.'"' : '' %>
233 % if ( $opt{header2} ) {
235 % foreach my $header ( @{ $opt{header2} } ) {
236 % my $label = ref($header) ? $header->{label} : $header;
237 <TH CLASS="grid" BGCOLOR="#cccccc">
238 <FONT SIZE="-1"><% $label %></FONT>
244 % my $bgcolor1 = '#eeeeee';
245 % my $bgcolor2 = '#ffffff';
248 % foreach my $row ( @$rows ) {
250 % if ( $bgcolor eq $bgcolor1 ) {
251 % $bgcolor = $bgcolor2;
253 % $bgcolor = $bgcolor1;
257 % if ( $row eq $opt{'footer_data'} ) {
258 % $rowstyle = ' STYLE="border-top: dashed 1px black; font-style: italic"';
259 % $bgcolor = '#dddddd';
263 % if ( $opt{'link_field' } ) {
264 % my $link_field = $opt{'link_field'};
265 % if ( ref($link_field) eq 'CODE' ) {
266 % $trid = &{$link_field}($row);
268 % $trid = $row->$link_field();
271 <TR ID="<%$trid |h%>"<%$rowstyle%>>
274 % if ( $opt{'fields'} ) {
276 % my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : '';
277 % my $onclicks = $opt{'link_onclicks'} ? [ @{$opt{'link_onclicks'}} ] : [];
278 % my $tooltips = $opt{'tooltips'} ? [ @{$opt{'tooltips'}} ] : [];
279 % my $aligns = $opt{'align'} ? [ @{$opt{'align'}} ] : '';
280 % my $colors = $opt{'color'} ? [ @{$opt{'color'}} ] : [];
281 % my $sizes = $opt{'size'} ? [ @{$opt{'size'}} ] : [];
282 % my $styles = $opt{'style'} ? [ @{$opt{'style'}} ] : [];
283 % my $cstyles = $opt{'cell_style'} ? [ @{$opt{'cell_style'}} ] : [];
285 % foreach my $field (
288 % if ( ref($_) eq 'ARRAY' ) {
292 % '<TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0 WIDTH="100%">'.
306 % uc($_).'="'. $e->{$_}. '"';
308 % grep exists($e->{$_}),
309 % qw( align bgcolor colspan rowspan
310 % style valign width )
315 % ? '<A HREF="'. $e->{'link'}. '">'
318 % ( $e->{'onclick'} # don't use with 'link'
319 % ? '<A HREF="#" onclick="' .
320 % $e->{'onclick'}.'">'
324 % ? '<FONT SIZE="'.uc($e->{'size'}).'">'
327 % ( $e->{'data_style'}
328 % ? '<'. uc($e->{'data_style'}). '>'
332 % ( $e->{'data_style'}
333 % ? '</'. uc($e->{'data_style'}). '>'
336 % ( $e->{'size'} ? '</FONT>' : '' ).
337 % ( $e->{'link'} || $e->{'onclick'}
355 % if ( ref($_) eq 'CODE' ) {
357 % } elsif ( ref($row) eq 'ARRAY' and
359 % # for the 'straight SQL' case: specify fields
361 % encode_entities($row->[$_]);
363 % encode_entities($row->$_());
370 %# my $class = ( $field =~ /^<TABLE/i ) ? 'inv' : 'grid';
371 % my $class = 'grid';
373 % my $align = $aligns ? shift @$aligns : '';
374 % $align = " ALIGN=$align" if $align;
378 % my $link = shift @$links;
379 % my $onclick = shift @$onclicks;
380 % my $tooltip = shift @$tooltips;
382 % if ( ! $opt{'agent_virt'}
383 % || ( $null_link && ! $row->agentnum )
384 % || grep { $row->agentnum == $_ }
388 % $link = &{$link}($row)
389 % if ref($link) eq 'CODE';
391 % $onclick = &{$onclick}($row)
392 % if ref($onclick) eq 'CODE';
393 % $onclick = qq( onClick="$onclick") if $onclick;
395 % $tooltip = &{$tooltip}($row)
396 % if ref($tooltip) eq 'CODE';
397 % $tooltip = qq! id="a$id" !.
398 % qq! onmouseover="return overlib(!.
399 % $m->interp->apply_escapes($tooltip, 'h', 'js_string').
400 % qq!, FGCLASS, 'tooltip', REF, 'a$id', !.
401 % qq!REFC, 'LL', REFP, 'UL')"! if $tooltip;
404 % my( $url, $method ) = @{$link};
405 % if ( ref($method) eq 'CODE' ) {
406 % $a = $url. &{$method}($row);
408 % $a = $url. $row->$method();
410 % $a = qq(<A HREF="$a"$onclick$tooltip>);
412 % elsif ( $onclick ) {
413 % $a = qq(<A HREF="javascript:void(0);"$onclick>);
415 % elsif ( $tooltip ) {
416 % $a = qq(<A $tooltip>);
425 % my $color = shift @$colors;
426 % $color = &{$color}($row) if ref($color) eq 'CODE';
427 % my $size = shift @$sizes;
428 % $size = &{$size}($row) if ref($size) eq 'CODE';
429 % if ( $color || $size ) {
431 % ( $color ? "COLOR=#$color " : '' ).
432 % ( $size ? qq(SIZE="$size" ) : '' ).
436 % my($s, $es) = ( '', '' );
437 % my $style = shift @$styles;
438 % $style = &{$style}($row) if ref($style) eq 'CODE';
440 % $s = join( '', map "<$_>", split('', $style) );
441 % $es = join( '', map "</$_>", split('', $style) );
444 % my $cstyle = shift @$cstyles;
445 % $cstyle = &{$cstyle}($row) if ref($cstyle) eq 'CODE';
446 % $cstyle = qq(STYLE="$cstyle")
449 <TD CLASS="<% $class %>" BGCOLOR="<% $bgcolor %>" <% $align %> <% $cstyle %>><% $a %><% $font %><% $s %><% $field %><% $es %><% $font ? '</FONT>' : '' %><% $a ? '</A>' : '' %></TD>
455 % foreach ( @$row ) {
456 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $_ %></TD>
465 % if ( $opt{'footer'} ) {
469 % foreach my $footer ( @{ $opt{'footer'} } ) {
470 % $footer = &{$footer}() if ref($footer) eq 'CODE';
471 <TD CLASS="grid" BGCOLOR="#dddddd" STYLE="border-top: dashed 1px black;"><i><% $footer %></i></TD>
486 % if ( $type eq 'html-print' ) {
487 % unless ( $opt{nohtmlheader} ) {
494 <% defined($opt{'html_foot'})
495 ? ( ref($opt{'html_foot'})
496 ? &{$opt{'html_foot'}}()
502 <% $opt{nohtmlheader}
504 : include( '/elements/footer.html' )
512 my $curuser = $FS::CurrentUser::CurrentUser;
515 my $type = $args{'type'};
516 my $header = $args{'header'};
517 my $rows = $args{'rows'};
518 my @link_agentnums = @{ $args{'link_agentnums'} };
519 my $null_link = $args{'null_link'};
520 my $confmax = $args{'confmax'};
521 my $maxrecords = $args{'maxrecords'};
522 my $offset = $args{'offset'};
523 my %opt = %{ $args{'opt'} };
524 my $self_url = $opt{'url'} || $cgi->url('-path_info' => 1, '-full' =>1);
526 my $count_sth = dbh->prepare($opt{'count_query'})
527 or die "Error preparing $opt{'count_query'}: ". dbh->errstr;
529 or die "Error executing $opt{'count_query'}: ". $count_sth->errstr;
530 my $count_arrayref = $count_sth->fetchrow_arrayref;
531 my $total = $count_arrayref->[0];