2 % if ( exists($opt{'redirect'}) && $opt{'redirect'}
3 % && scalar(@$rows) == 1 && $total == 1
4 % && $type ne 'html-print'
6 % my $redirect = $opt{'redirect'};
7 % $redirect = &{$redirect}($rows->[0], $cgi) if ref($redirect) eq 'CODE';
8 % my( $url, $method ) = @$redirect;
9 % redirect( $url. $rows->[0]->$method() );
10 % } elsif ( exists($opt{'redirect_empty'}) && ! scalar(@$rows) && $total == 0
11 % && $type ne 'html-print'
12 % && $opt{'redirect_empty'}
13 % && ( ref($opt{'redirect_empty'}) ne 'CODE'
14 % || &{$opt{'redirect_empty'}}($cgi) )
16 % my $redirect = $opt{'redirect_empty'};
17 % $redirect = &{$redirect}($cgi) if ref($redirect) eq 'CODE';
18 % redirect( $redirect );
20 % if ( $opt{'name_singular'} ) {
21 % $opt{'name'} = PL($opt{'name_singular'});
23 % ( my $xlsname = $opt{'name'} ) =~ s/\W//g;
24 % if ( $total == 1 ) {
25 % if ( $opt{'name_singular'} ) {
26 % $opt{'name'} = $opt{'name_singular'}
28 % #$opt{'name'} =~ s/s$// if $total == 1;
29 % $opt{'name'} =~ s/((s)e)?s$/$2/ if $total == 1;
33 % if ( $type eq 'html-print' ) {
35 <% include( '/elements/header-popup.html', $opt{'title'} ) %>
37 % } elsif ( $type eq 'select' ) {
39 <% include( '/elements/header-popup.html', $opt{'title'} ) %>
40 <% defined($opt{'html_init'})
41 ? ( ref($opt{'html_init'})
42 ? &{$opt{'html_init'}}()
51 % if ( $opt{'menubar'} ) {
52 % @menubar = @{ $opt{'menubar'} };
54 % # @menubar = ( 'Main menu' => $p );
57 <% include( '/elements/header.html', $opt{'title'},
58 include( '/elements/menubar.html', @menubar )
62 <% defined($opt{'html_init'})
63 ? ( ref($opt{'html_init'})
64 ? &{$opt{'html_init'}}()
73 % unless ( $opt{'disable_nonefound'} ) {
74 No matching <% $opt{'name'} %> found.<BR>
78 % if ( $total || $opt{'disableable'} ) { #hmm... and there *are* ones to show??
87 % if (! $opt{'disable_total'}) {
88 <% $total %> total <% $opt{'name'} %>
91 % if ( $confmax && $total > $confmax
92 % && ! $opt{'disable_maxselect'}
93 % && $type ne 'html-print' )
95 % $cgi->delete('maxrecords');
96 % $cgi->param('_dummy', 1);
98 ( show <SELECT NAME="maxrecords" onChange="window.location = '<% $cgi->self_url %>;maxrecords=' + this.options[this.selectedIndex].value;">
100 % foreach my $max ( map { $_ * $confmax } qw( 1 5 10 25 ) ) {
101 <OPTION VALUE="<% $max %>" <% ( $maxrecords == $max ) ? 'SELECTED' : '' %>><% $max %></OPTION>
106 % $cgi->param('maxrecords', $maxrecords);
109 % if ( defined($opt{'html_posttotal'}) && $type ne 'html-print' ) {
110 <% ref($opt{'html_posttotal'})
111 ? &{$opt{'html_posttotal'}}()
112 : $opt{'html_posttotal'}
117 % if ( $opt{'count_addl'} ) {
119 % foreach my $count ( @{$opt{'count_addl'}} ) {
120 % my $data = $count_arrayref->[++$n];
121 % if ( ref($count) ) {
122 <% &{ $count }( $data ) %>
124 <% sprintf( $count, $data ) %><BR>
132 % unless ( $opt{'disable_download'} || $type eq 'html-print' ) {
136 Download full results<BR>
138 % $cgi->param('_type', "$xlsname.xls" );
139 as <A HREF="<% $cgi->self_url %>">Excel spreadsheet</A><BR>
141 % $cgi->param('_type', 'csv');
142 as <A HREF="<% $cgi->self_url %>">CSV file</A><BR>
144 % $cgi->param('_type', 'html-print');
145 as <A HREF="<% $cgi->self_url %>">printable copy</A>
147 <% $opt{'extra_choices_callback'}
148 ? &{$opt{'extra_choices_callback'}}($cgi->query_string)
153 % $cgi->param('_type', "html" );
161 % unless ( $type eq 'html_print' ) {
163 <% $pager = include( '/elements/pager.html',
165 'num_rows' => scalar(@$rows),
167 'maxrecords' => $maxrecords,
171 <% defined($opt{'html_form'})
172 ? ( ref($opt{'html_form'})
173 ? &{$opt{'html_form'}}()
181 <% include('/elements/table-grid.html') %>
185 % foreach my $header ( @{ $opt{header} } ) {
186 % my $label = ref($header) ? $header->{label} : $header;
189 % if ( $opt{header2} ) {
190 % if ( !length($opt{header2}->[$h2]) ) {
192 % splice @{ $opt{header2} }, $h2, 1;
195 % $style = 'STYLE="border-bottom: none"'
200 ROWSPAN = "<% $rowspan %>"
209 % if ( $opt{header2} ) {
211 % foreach my $header ( @{ $opt{header2} } ) {
212 % my $label = ref($header) ? $header->{label} : $header;
213 <TH CLASS="grid" BGCOLOR="#cccccc">
214 <FONT SIZE="-1"><% $label %></FONT>
220 % my $bgcolor1 = '#eeeeee';
221 % my $bgcolor2 = '#ffffff';
224 % foreach my $row ( @$rows ) {
226 % if ( $bgcolor eq $bgcolor1 ) {
227 % $bgcolor = $bgcolor2;
229 % $bgcolor = $bgcolor1;
234 % if ( $opt{'fields'} ) {
236 % my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : '';
237 % my $onclicks = $opt{'link_onclicks'} ? [ @{$opt{'link_onclicks'}} ] : [];
238 % my $aligns = $opt{'align'} ? [ @{$opt{'align'}} ] : '';
239 % my $colors = $opt{'color'} ? [ @{$opt{'color'}} ] : [];
240 % my $sizes = $opt{'size'} ? [ @{$opt{'size'}} ] : [];
241 % my $styles = $opt{'style'} ? [ @{$opt{'style'}} ] : [];
242 % my $cstyles = $opt{'cell_style'} ? [ @{$opt{'cell_style'}} ] : [];
244 % foreach my $field (
247 % if ( ref($_) eq 'ARRAY' ) {
251 % '<TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0 WIDTH="100%">'.
265 % uc($_).'="'. $e->{$_}. '"';
267 % grep exists($e->{$_}),
268 % qw( align bgcolor colspan rowspan
269 % style valign width )
274 % ? '<A HREF="'. $e->{'link'}. '">'
278 % ? '<FONT SIZE="'.uc($e->{'size'}).'">'
281 % ( $e->{'data_style'}
282 % ? '<'. uc($e->{'data_style'}). '>'
286 % ( $e->{'data_style'}
287 % ? '</'. uc($e->{'data_style'}). '>'
290 % ( $e->{'size'} ? '</FONT>' : '' ).
291 % ( $e->{'link'} ? '</A>' : '' ).
307 % if ( ref($_) eq 'CODE' ) {
317 % my $class = ( $field =~ /^<TABLE/i ) ? 'inv' : 'grid';
319 % my $align = $aligns ? shift @$aligns : '';
320 % $align = " ALIGN=$align" if $align;
324 % my $link = shift @$links;
325 % my $onclick = shift @$onclicks;
327 % if ( ! $opt{'agent_virt'}
328 % || ( $null_link && ! $row->agentnum )
329 % || grep { $row->agentnum == $_ }
333 % $link = &{$link}($row)
334 % if ref($link) eq 'CODE';
336 % $onclick = &{$onclick}($row)
337 % if ref($onclick) eq 'CODE';
338 % $onclick = qq( onClick="$onclick") if $onclick;
341 % my( $url, $method ) = @{$link};
342 % if ( ref($method) eq 'CODE' ) {
343 % $a = $url. &{$method}($row);
345 % $a = $url. $row->$method();
347 % $a = qq(<A HREF="$a"$onclick>);
349 % elsif ( $onclick ) {
350 % $a = qq(<A HREF="javascript:void(0);"$onclick>);
357 % my $color = shift @$colors;
358 % $color = &{$color}($row) if ref($color) eq 'CODE';
359 % my $size = shift @$sizes;
360 % $size = &{$size}($row) if ref($size) eq 'CODE';
361 % if ( $color || $size ) {
363 % ( $color ? "COLOR=#$color " : '' ).
364 % ( $size ? qq(SIZE="$size" ) : '' ).
368 % my($s, $es) = ( '', '' );
369 % my $style = shift @$styles;
370 % $style = &{$style}($row) if ref($style) eq 'CODE';
372 % $s = join( '', map "<$_>", split('', $style) );
373 % $es = join( '', map "</$_>", split('', $style) );
376 % my $cstyle = shift @$cstyles;
377 % $cstyle = &{$cstyle}($row) if ref($cstyle) eq 'CODE';
378 % $cstyle = qq(STYLE="$cstyle")
381 <TD CLASS="<% $class %>" BGCOLOR="<% $bgcolor %>" <% $align %> <% $cstyle %>><% $font %><% $a %><% $s %><% $field %><% $es %><% $a ? '</A>' : '' %><% $font ? '</FONT>' : '' %></TD>
387 % foreach ( @$row ) {
388 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $_ %></TD>
397 % if ( $opt{'footer'} ) {
401 % foreach my $footer ( @{ $opt{'footer'} } ) {
402 <TD CLASS="grid" BGCOLOR="#dddddd" STYLE="border-top: dashed 1px black;"><i><% $footer %></i></TD>
417 % if ( $type eq 'html-print' ) {
423 <% defined($opt{'html_foot'})
424 ? ( ref($opt{'html_foot'})
425 ? &{$opt{'html_foot'}}()
431 <% include( '/elements/footer.html' ) %>
439 my $type = $args{'type'};
440 my $header = $args{'header'};
441 my $rows = $args{'rows'};
442 my @link_agentnums = @{ $args{'link_agentnums'} };
443 my $null_link = $args{'null_link'};
444 my $confmax = $args{'confmax'};
445 my $maxrecords = $args{'maxrecords'};
446 my $offset = $args{'offset'};
447 my %opt = %{ $args{'opt'} };
449 my $count_sth = dbh->prepare($opt{'count_query'})
450 or die "Error preparing $opt{'count_query'}: ". dbh->errstr;
452 or die "Error executing $opt{'count_query'}: ". $count_sth->errstr;
453 my $count_arrayref = $count_sth->fetchrow_arrayref;
454 my $total = $count_arrayref->[0];