2 % if ( exists($opt{'redirect'}) && 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 % if ( $type eq 'html-print' ) {
34 <% include( '/elements/header-popup.html', $opt{'title'} ) %>
36 % } elsif ( $type eq 'select' ) {
38 <% include( '/elements/header-popup.html', $opt{'title'} ) %>
39 <% defined($opt{'html_init'})
40 ? ( ref($opt{'html_init'})
41 ? &{$opt{'html_init'}}()
50 % if ( $opt{'menubar'} ) {
51 % @menubar = @{ $opt{'menubar'} };
53 % # @menubar = ( 'Main menu' => $p );
56 <% include( '/elements/header.html', $opt{'title'},
57 include( '/elements/menubar.html', @menubar )
61 <% defined($opt{'html_init'})
62 ? ( ref($opt{'html_init'})
63 ? &{$opt{'html_init'}}()
72 % unless ( $opt{'disable_nonefound'} ) {
73 No matching <% $opt{'name'} %> found.<BR>
77 % if ( $total || $opt{'disableable'} ) { #hmm... and there *are* ones to show??
86 % if (! $opt{'disable_total'}) {
87 <% $total %> total <% $opt{'name'} %>
90 % if ( $confmax && $total > $confmax
91 % && ! $opt{'disable_maxselect'}
92 % && $type ne 'html-print' )
94 % $cgi->delete('maxrecords');
95 % $cgi->param('_dummy', 1);
97 ( show <SELECT NAME="maxrecords" onChange="window.location = '<% $cgi->self_url %>;maxrecords=' + this.options[this.selectedIndex].value;">
99 % foreach my $max ( map { $_ * $confmax } qw( 1 5 10 25 ) ) {
100 <OPTION VALUE="<% $max %>" <% ( $maxrecords == $max ) ? 'SELECTED' : '' %>><% $max %></OPTION>
105 % $cgi->param('maxrecords', $maxrecords);
108 % if ( defined($opt{'html_posttotal'}) && $type ne 'html-print' ) {
109 <% ref($opt{'html_posttotal'})
110 ? &{$opt{'html_posttotal'}}()
111 : $opt{'html_posttotal'}
116 % if ( $opt{'count_addl'} ) {
118 % foreach my $count ( @{$opt{'count_addl'}} ) {
119 % my $data = $count_arrayref->[++$n];
120 % if ( ref($count) ) {
121 <% &{ $count }( $data ) %>
123 <% sprintf( $count, $data ) %><BR>
131 % unless ( $opt{'disable_download'} || $type eq 'html-print' ) {
135 Download full results<BR>
137 % $cgi->param('_type', "$xlsname.xls" );
138 as <A HREF="<% $cgi->self_url %>">Excel spreadsheet</A><BR>
140 % $cgi->param('_type', 'csv');
141 as <A HREF="<% $cgi->self_url %>">CSV file</A><BR>
143 % $cgi->param('_type', 'html-print');
144 as <A HREF="<% $cgi->self_url %>">printable copy</A>
146 <% $opt{'extra_choices_callback'}
147 ? &{$opt{'extra_choices_callback'}}($cgi->query_string)
152 % $cgi->param('_type', "html" );
160 % unless ( $type eq 'html_print' ) {
162 <% $pager = include( '/elements/pager.html',
164 'num_rows' => scalar(@$rows),
166 'maxrecords' => $maxrecords,
170 <% defined($opt{'html_form'})
171 ? ( ref($opt{'html_form'})
172 ? &{$opt{'html_form'}}()
180 <% include('/elements/table-grid.html') %>
184 % foreach my $header ( @{ $opt{header} } ) {
185 % my $label = ref($header) ? $header->{label} : $header;
188 % if ( $opt{header2} ) {
189 % if ( !length($opt{header2}->[$h2]) ) {
191 % splice @{ $opt{header2} }, $h2, 1;
194 % $style = 'STYLE="border-bottom: none"'
199 ROWSPAN = "<% $rowspan %>"
208 % if ( $opt{header2} ) {
210 % foreach my $header ( @{ $opt{header2} } ) {
211 % my $label = ref($header) ? $header->{label} : $header;
212 <TH CLASS="grid" BGCOLOR="#cccccc">
213 <FONT SIZE="-1"><% $label %></FONT>
219 % my $bgcolor1 = '#eeeeee';
220 % my $bgcolor2 = '#ffffff';
223 % foreach my $row ( @$rows ) {
225 % if ( $bgcolor eq $bgcolor1 ) {
226 % $bgcolor = $bgcolor2;
228 % $bgcolor = $bgcolor1;
233 % if ( $opt{'fields'} ) {
235 % my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : '';
236 % my $onclicks = $opt{'link_onclicks'} ? [ @{$opt{'link_onclicks'}} ] : [];
237 % my $aligns = $opt{'align'} ? [ @{$opt{'align'}} ] : '';
238 % my $colors = $opt{'color'} ? [ @{$opt{'color'}} ] : [];
239 % my $sizes = $opt{'size'} ? [ @{$opt{'size'}} ] : [];
240 % my $styles = $opt{'style'} ? [ @{$opt{'style'}} ] : [];
241 % my $cstyles = $opt{'cell_style'} ? [ @{$opt{'cell_style'}} ] : [];
243 % foreach my $field (
246 % if ( ref($_) eq 'ARRAY' ) {
250 % '<TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0 WIDTH="100%">'.
264 % uc($_).'="'. $e->{$_}. '"';
266 % grep exists($e->{$_}),
267 % qw( align bgcolor colspan rowspan
268 % style valign width )
273 % ? '<A HREF="'. $e->{'link'}. '">'
277 % ? '<FONT SIZE="'.uc($e->{'size'}).'">'
280 % ( $e->{'data_style'}
281 % ? '<'. uc($e->{'data_style'}). '>'
285 % ( $e->{'data_style'}
286 % ? '</'. uc($e->{'data_style'}). '>'
289 % ( $e->{'size'} ? '</FONT>' : '' ).
290 % ( $e->{'link'} ? '</A>' : '' ).
306 % if ( ref($_) eq 'CODE' ) {
316 % my $class = ( $field =~ /^<TABLE/i ) ? 'inv' : 'grid';
318 % my $align = $aligns ? shift @$aligns : '';
319 % $align = " ALIGN=$align" if $align;
323 % my $link = shift @$links;
324 % my $onclick = shift @$onclicks;
326 % if ( ! $opt{'agent_virt'}
327 % || ( $null_link && ! $row->agentnum )
328 % || grep { $row->agentnum == $_ }
332 % $link = &{$link}($row)
333 % if ref($link) eq 'CODE';
335 % $onclick = &{$onclick}($row)
336 % if ref($onclick) eq 'CODE';
337 % $onclick = qq( onClick="$onclick") if $onclick;
340 % my( $url, $method ) = @{$link};
341 % if ( ref($method) eq 'CODE' ) {
342 % $a = $url. &{$method}($row);
344 % $a = $url. $row->$method();
346 % $a = qq(<A HREF="$a"$onclick>);
354 % my $color = shift @$colors;
355 % $color = &{$color}($row) if ref($color) eq 'CODE';
356 % my $size = shift @$sizes;
357 % $size = &{$size}($row) if ref($size) eq 'CODE';
358 % if ( $color || $size ) {
360 % ( $color ? "COLOR=#$color " : '' ).
361 % ( $size ? qq(SIZE="$size" ) : '' ).
365 % my($s, $es) = ( '', '' );
366 % my $style = shift @$styles;
367 % $style = &{$style}($row) if ref($style) eq 'CODE';
369 % $s = join( '', map "<$_>", split('', $style) );
370 % $es = join( '', map "</$_>", split('', $style) );
373 % my $cstyle = shift @$cstyles;
374 % $cstyle = &{$cstyle}($row) if ref($cstyle) eq 'CODE';
375 % $cstyle = qq(STYLE="$cstyle")
378 <TD CLASS="<% $class %>" BGCOLOR="<% $bgcolor %>" <% $align %> <% $cstyle %>><% $font %><% $a %><% $s %><% $field %><% $es %><% $a ? '</A>' : '' %><% $font ? '</FONT>' : '' %></TD>
384 % foreach ( @$row ) {
385 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $_ %></TD>
394 % if ( $opt{'footer'} ) {
398 % foreach my $footer ( @{ $opt{'footer'} } ) {
399 <TD CLASS="grid" BGCOLOR="#dddddd" STYLE="border-top: dashed 1px black;"><i><% $footer %></i></TD>
414 % if ( $type eq 'html-print' ) {
420 <% defined($opt{'html_foot'})
421 ? ( ref($opt{'html_foot'})
422 ? &{$opt{'html_foot'}}()
428 <% include( '/elements/footer.html' ) %>
436 my $type = $args{'type'};
437 my $header = $args{'header'};
438 my $rows = $args{'rows'};
439 my @link_agentnums = @{ $args{'link_agentnums'} };
440 my $null_link = $args{'null_link'};
441 my $confmax = $args{'confmax'};
442 my $maxrecords = $args{'maxrecords'};
443 my $offset = $args{'offset'};
444 my %opt = %{ $args{'opt'} };
446 my $count_sth = dbh->prepare($opt{'count_query'})
447 or die "Error preparing $opt{'count_query'}: ". dbh->errstr;
449 or die "Error executing $opt{'count_query'}: ". $count_sth->errstr;
450 my $count_arrayref = $count_sth->fetchrow_arrayref;
451 my $total = $count_arrayref->[0];