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 % unless ( $opt{'disable_download'} || $type eq 'html-print' ) {
137 Download full results<BR>
139 % $cgi->param('_type', "$xlsname.xls" );
140 as <A HREF="<% "$self_url?". $cgi->query_string %>">Excel spreadsheet</A><BR>
142 % $cgi->param('_type', 'csv');
143 as <A HREF="<% "$self_url?". $cgi->query_string %>">CSV file</A><BR>
145 % if ( defined($opt{xml_elements}) ) {
146 % $cgi->param('_type', 'xml');
147 as <A HREF="<% "$self_url?". $cgi->query_string %>">XML file</A><BR>
150 % $cgi->param('_type', 'html-print');
151 as <A HREF="<% "$self_url?". $cgi->query_string %>">printable copy</A>
154 % $cgi->param('_type', "html" );
162 % unless ( $type eq 'html_print' ) {
164 <% $pager = include( '/elements/pager.html',
166 'num_rows' => scalar(@$rows),
168 'maxrecords' => $maxrecords,
172 <% defined($opt{'html_form'})
173 ? ( ref($opt{'html_form'})
174 ? &{$opt{'html_form'}}()
182 <% include('/elements/table-grid.html') %>
187 % my @fields = @{ $opt{'sort_fields'} || $opt{'fields'} || [] };
188 % my $order_by = $cgi->param('order_by');
189 % foreach my $header ( @{ $opt{header} } ) {
191 % my $field = shift @fields;
193 % $colspan-- if $colspan > 0;
196 % my $label = ref($header) ? $header->{label} : $header;
197 % unless ( ref($field) || !$field ) {
198 % if ( $order_by eq $field ) {
199 % $cgi->param('order_by', "$field DESC");
201 % $cgi->param('order_by', $field);
203 % $label = qq(<A HREF="$self_url?). $cgi->query_string.
207 % $colspan = ref($header) ? $header->{colspan} : 0;
210 % if ( $opt{header2} ) {
211 % if ( !length($opt{header2}->[$h2]) ) {
213 % splice @{ $opt{header2} }, $h2, 1;
216 % $style = 'STYLE="border-bottom: none"'
221 ROWSPAN = "<% $rowspan %>"
222 <% $colspan ? 'COLSPAN = "'.$colspan.'"' : '' %>
231 % if ( $opt{header2} ) {
233 % foreach my $header ( @{ $opt{header2} } ) {
234 % my $label = ref($header) ? $header->{label} : $header;
235 <TH CLASS="grid" BGCOLOR="#cccccc">
236 <FONT SIZE="-1"><% $label %></FONT>
242 % my $bgcolor1 = '#eeeeee';
243 % my $bgcolor2 = '#ffffff';
246 % foreach my $row ( @$rows ) {
248 % if ( $bgcolor eq $bgcolor1 ) {
249 % $bgcolor = $bgcolor2;
251 % $bgcolor = $bgcolor1;
256 % if ( $opt{'fields'} ) {
258 % my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : '';
259 % my $onclicks = $opt{'link_onclicks'} ? [ @{$opt{'link_onclicks'}} ] : [];
260 % my $aligns = $opt{'align'} ? [ @{$opt{'align'}} ] : '';
261 % my $colors = $opt{'color'} ? [ @{$opt{'color'}} ] : [];
262 % my $sizes = $opt{'size'} ? [ @{$opt{'size'}} ] : [];
263 % my $styles = $opt{'style'} ? [ @{$opt{'style'}} ] : [];
264 % my $cstyles = $opt{'cell_style'} ? [ @{$opt{'cell_style'}} ] : [];
266 % foreach my $field (
269 % if ( ref($_) eq 'ARRAY' ) {
273 % '<TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0 WIDTH="100%">'.
287 % uc($_).'="'. $e->{$_}. '"';
289 % grep exists($e->{$_}),
290 % qw( align bgcolor colspan rowspan
291 % style valign width )
296 % ? '<A HREF="'. $e->{'link'}. '">'
300 % ? '<FONT SIZE="'.uc($e->{'size'}).'">'
303 % ( $e->{'data_style'}
304 % ? '<'. uc($e->{'data_style'}). '>'
308 % ( $e->{'data_style'}
309 % ? '</'. uc($e->{'data_style'}). '>'
312 % ( $e->{'size'} ? '</FONT>' : '' ).
313 % ( $e->{'link'} ? '</A>' : '' ).
329 % if ( ref($_) eq 'CODE' ) {
339 % my $class = ( $field =~ /^<TABLE/i ) ? 'inv' : 'grid';
341 % my $align = $aligns ? shift @$aligns : '';
342 % $align = " ALIGN=$align" if $align;
346 % my $link = shift @$links;
347 % my $onclick = shift @$onclicks;
349 % if ( ! $opt{'agent_virt'}
350 % || ( $null_link && ! $row->agentnum )
351 % || grep { $row->agentnum == $_ }
355 % $link = &{$link}($row)
356 % if ref($link) eq 'CODE';
358 % $onclick = &{$onclick}($row)
359 % if ref($onclick) eq 'CODE';
360 % $onclick = qq( onClick="$onclick") if $onclick;
363 % my( $url, $method ) = @{$link};
364 % if ( ref($method) eq 'CODE' ) {
365 % $a = $url. &{$method}($row);
367 % $a = $url. $row->$method();
369 % $a = qq(<A HREF="$a"$onclick>);
371 % elsif ( $onclick ) {
372 % $a = qq(<A HREF="javascript:void(0);"$onclick>);
379 % my $color = shift @$colors;
380 % $color = &{$color}($row) if ref($color) eq 'CODE';
381 % my $size = shift @$sizes;
382 % $size = &{$size}($row) if ref($size) eq 'CODE';
383 % if ( $color || $size ) {
385 % ( $color ? "COLOR=#$color " : '' ).
386 % ( $size ? qq(SIZE="$size" ) : '' ).
390 % my($s, $es) = ( '', '' );
391 % my $style = shift @$styles;
392 % $style = &{$style}($row) if ref($style) eq 'CODE';
394 % $s = join( '', map "<$_>", split('', $style) );
395 % $es = join( '', map "</$_>", split('', $style) );
398 % my $cstyle = shift @$cstyles;
399 % $cstyle = &{$cstyle}($row) if ref($cstyle) eq 'CODE';
400 % $cstyle = qq(STYLE="$cstyle")
403 <TD CLASS="<% $class %>" BGCOLOR="<% $bgcolor %>" <% $align %> <% $cstyle %>><% $font %><% $a %><% $s %><% $field %><% $es %><% $a ? '</A>' : '' %><% $font ? '</FONT>' : '' %></TD>
409 % foreach ( @$row ) {
410 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $_ %></TD>
419 % if ( $opt{'footer'} ) {
423 % foreach my $footer ( @{ $opt{'footer'} } ) {
424 % $footer = &{$footer}() if ref($footer) eq 'CODE';
425 <TD CLASS="grid" BGCOLOR="#dddddd" STYLE="border-top: dashed 1px black;"><i><% $footer %></i></TD>
440 % if ( $type eq 'html-print' ) {
441 % unless ( $opt{nohtmlheader} ) {
448 <% defined($opt{'html_foot'})
449 ? ( ref($opt{'html_foot'})
450 ? &{$opt{'html_foot'}}()
456 <% $opt{nohtmlheader}
458 : include( '/elements/footer.html' )
467 my $type = $args{'type'};
468 my $header = $args{'header'};
469 my $rows = $args{'rows'};
470 my @link_agentnums = @{ $args{'link_agentnums'} };
471 my $null_link = $args{'null_link'};
472 my $confmax = $args{'confmax'};
473 my $maxrecords = $args{'maxrecords'};
474 my $offset = $args{'offset'};
475 my %opt = %{ $args{'opt'} };
476 my $self_url = $opt{'url'} || $cgi->url('-path_info' => 1, '-full' =>1);
478 my $count_sth = dbh->prepare($opt{'count_query'})
479 or die "Error preparing $opt{'count_query'}: ". dbh->errstr;
481 or die "Error executing $opt{'count_query'}: ". $count_sth->errstr;
482 my $count_arrayref = $count_sth->fetchrow_arrayref;
483 my $total = $count_arrayref->[0];