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 % if ( $type eq 'html-print' ) {
36 : include( '/elements/header-popup.html', $opt{'title'} )
39 % } elsif ( $type eq 'select' ) {
43 : include( '/elements/header-popup.html', $opt{'title'} )
45 <% defined($opt{'html_init'})
46 ? ( ref($opt{'html_init'})
47 ? &{$opt{'html_init'}}()
56 % if ( $opt{'menubar'} ) {
57 % @menubar = @{ $opt{'menubar'} };
59 % # @menubar = ( 'Main menu' => $p );
64 : include( '/elements/header.html', $opt{'title'},
65 include( '/elements/menubar.html', @menubar )
69 <% defined($opt{'html_init'})
70 ? ( ref($opt{'html_init'})
71 ? &{$opt{'html_init'}}()
80 % unless ( $opt{'disable_nonefound'} ) {
81 No matching <% $opt{'name'} %> found.<BR>
85 % if ( $total || $opt{'disableable'} ) { #hmm... and there *are* ones to show??
94 % if (! $opt{'disable_total'}) {
95 <% $total %> total <% $opt{'name'} %>
98 % if ( $confmax && $total > $confmax
99 % && ! $opt{'disable_maxselect'}
100 % && $type ne 'html-print' )
102 % $cgi->delete('maxrecords');
103 % $cgi->param('_dummy', 1);
105 ( show <SELECT NAME="maxrecords" onChange="window.location = '<% "$self_url?". $cgi->query_string %>;maxrecords=' + this.options[this.selectedIndex].value;">
107 % foreach my $max ( map { $_ * $confmax } qw( 1 5 10 25 ) ) {
108 <OPTION VALUE="<% $max %>" <% ( $maxrecords == $max ) ? 'SELECTED' : '' %>><% $max %></OPTION>
113 % $cgi->param('maxrecords', $maxrecords);
116 % if ( defined($opt{'html_posttotal'}) && $type ne 'html-print' ) {
117 <% ref($opt{'html_posttotal'})
118 ? &{$opt{'html_posttotal'}}()
119 : $opt{'html_posttotal'}
124 % if ( $opt{'count_addl'} ) {
126 % foreach my $count ( @{$opt{'count_addl'}} ) {
127 % my $data = $count_arrayref->[++$n];
128 % if ( ref($count) ) {
129 <% &{ $count }( $data ) %>
131 <% sprintf( $count, $data ) %><BR>
139 % unless ( $opt{'disable_download'} || $type eq 'html-print' ) {
143 Download full results<BR>
145 % $cgi->param('_type', "$xlsname.xls" );
146 as <A HREF="<% "$self_url?". $cgi->query_string %>">Excel spreadsheet</A><BR>
148 % $cgi->param('_type', 'csv');
149 as <A HREF="<% "$self_url?". $cgi->query_string %>">CSV file</A><BR>
151 % if ( defined($opt{xml_elements}) ) {
152 % $cgi->param('_type', 'xml');
153 as <A HREF="<% "$self_url?". $cgi->query_string %>">XML file</A><BR>
156 % $cgi->param('_type', 'html-print');
157 as <A HREF="<% "$self_url?". $cgi->query_string %>">printable copy</A>
160 % $cgi->param('_type', "html" );
168 % unless ( $type eq 'html_print' ) {
170 <% $pager = include( '/elements/pager.html',
172 'num_rows' => scalar(@$rows),
174 'maxrecords' => $maxrecords,
178 <% defined($opt{'html_form'})
179 ? ( ref($opt{'html_form'})
180 ? &{$opt{'html_form'}}()
188 <% include('/elements/table-grid.html') %>
193 % my @fields = @{ $opt{'sort_fields'} || $opt{'fields'} || [] };
194 % my $order_by = $cgi->param('order_by');
195 % foreach my $header ( @{ $opt{header} } ) {
197 % my $field = shift @fields;
199 % $colspan-- if $colspan > 0;
202 % my $label = ref($header) ? $header->{label} : $header;
203 % unless ( ref($field) || !$field ) {
204 % if ( $order_by eq $field ) {
205 % $cgi->param('order_by', "$field DESC");
207 % $cgi->param('order_by', $field);
209 % $label = qq(<A HREF="$self_url?). $cgi->query_string.
213 % $colspan = ref($header) ? $header->{colspan} : 0;
216 % if ( $opt{header2} ) {
217 % if ( !length($opt{header2}->[$h2]) ) {
219 % splice @{ $opt{header2} }, $h2, 1;
222 % $style = 'STYLE="border-bottom: none"'
227 ROWSPAN = "<% $rowspan %>"
228 <% $colspan ? 'COLSPAN = "'.$colspan.'"' : '' %>
237 % if ( $opt{header2} ) {
239 % foreach my $header ( @{ $opt{header2} } ) {
240 % my $label = ref($header) ? $header->{label} : $header;
241 <TH CLASS="grid" BGCOLOR="#cccccc">
242 <FONT SIZE="-1"><% $label %></FONT>
248 % my $bgcolor1 = '#eeeeee';
249 % my $bgcolor2 = '#ffffff';
252 % foreach my $row ( @$rows ) {
254 % if ( $bgcolor eq $bgcolor1 ) {
255 % $bgcolor = $bgcolor2;
257 % $bgcolor = $bgcolor1;
262 % if ( $opt{'fields'} ) {
264 % my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : '';
265 % my $onclicks = $opt{'link_onclicks'} ? [ @{$opt{'link_onclicks'}} ] : [];
266 % my $aligns = $opt{'align'} ? [ @{$opt{'align'}} ] : '';
267 % my $colors = $opt{'color'} ? [ @{$opt{'color'}} ] : [];
268 % my $sizes = $opt{'size'} ? [ @{$opt{'size'}} ] : [];
269 % my $styles = $opt{'style'} ? [ @{$opt{'style'}} ] : [];
270 % my $cstyles = $opt{'cell_style'} ? [ @{$opt{'cell_style'}} ] : [];
272 % foreach my $field (
275 % if ( ref($_) eq 'ARRAY' ) {
279 % '<TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0 WIDTH="100%">'.
293 % uc($_).'="'. $e->{$_}. '"';
295 % grep exists($e->{$_}),
296 % qw( align bgcolor colspan rowspan
297 % style valign width )
302 % ? '<A HREF="'. $e->{'link'}. '">'
306 % ? '<FONT SIZE="'.uc($e->{'size'}).'">'
309 % ( $e->{'data_style'}
310 % ? '<'. uc($e->{'data_style'}). '>'
314 % ( $e->{'data_style'}
315 % ? '</'. uc($e->{'data_style'}). '>'
318 % ( $e->{'size'} ? '</FONT>' : '' ).
319 % ( $e->{'link'} ? '</A>' : '' ).
335 % if ( ref($_) eq 'CODE' ) {
345 % my $class = ( $field =~ /^<TABLE/i ) ? 'inv' : 'grid';
347 % my $align = $aligns ? shift @$aligns : '';
348 % $align = " ALIGN=$align" if $align;
352 % my $link = shift @$links;
353 % my $onclick = shift @$onclicks;
355 % if ( ! $opt{'agent_virt'}
356 % || ( $null_link && ! $row->agentnum )
357 % || grep { $row->agentnum == $_ }
361 % $link = &{$link}($row)
362 % if ref($link) eq 'CODE';
364 % $onclick = &{$onclick}($row)
365 % if ref($onclick) eq 'CODE';
366 % $onclick = qq( onClick="$onclick") if $onclick;
369 % my( $url, $method ) = @{$link};
370 % if ( ref($method) eq 'CODE' ) {
371 % $a = $url. &{$method}($row);
373 % $a = $url. $row->$method();
375 % $a = qq(<A HREF="$a"$onclick>);
377 % elsif ( $onclick ) {
378 % $a = qq(<A HREF="javascript:void(0);"$onclick>);
385 % my $color = shift @$colors;
386 % $color = &{$color}($row) if ref($color) eq 'CODE';
387 % my $size = shift @$sizes;
388 % $size = &{$size}($row) if ref($size) eq 'CODE';
389 % if ( $color || $size ) {
391 % ( $color ? "COLOR=#$color " : '' ).
392 % ( $size ? qq(SIZE="$size" ) : '' ).
396 % my($s, $es) = ( '', '' );
397 % my $style = shift @$styles;
398 % $style = &{$style}($row) if ref($style) eq 'CODE';
400 % $s = join( '', map "<$_>", split('', $style) );
401 % $es = join( '', map "</$_>", split('', $style) );
404 % my $cstyle = shift @$cstyles;
405 % $cstyle = &{$cstyle}($row) if ref($cstyle) eq 'CODE';
406 % $cstyle = qq(STYLE="$cstyle")
409 <TD CLASS="<% $class %>" BGCOLOR="<% $bgcolor %>" <% $align %> <% $cstyle %>><% $font %><% $a %><% $s %><% $field %><% $es %><% $a ? '</A>' : '' %><% $font ? '</FONT>' : '' %></TD>
415 % foreach ( @$row ) {
416 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $_ %></TD>
425 % if ( $opt{'footer'} ) {
429 % foreach my $footer ( @{ $opt{'footer'} } ) {
430 % $footer = &{$footer}() if ref($footer) eq 'CODE';
431 <TD CLASS="grid" BGCOLOR="#dddddd" STYLE="border-top: dashed 1px black;"><i><% $footer %></i></TD>
446 % if ( $type eq 'html-print' ) {
447 % unless ( $opt{nohtmlheader} ) {
454 <% defined($opt{'html_foot'})
455 ? ( ref($opt{'html_foot'})
456 ? &{$opt{'html_foot'}}()
462 <% $opt{nohtmlheader}
464 : include( '/elements/footer.html' )
473 my $type = $args{'type'};
474 my $header = $args{'header'};
475 my $rows = $args{'rows'};
476 my @link_agentnums = @{ $args{'link_agentnums'} };
477 my $null_link = $args{'null_link'};
478 my $confmax = $args{'confmax'};
479 my $maxrecords = $args{'maxrecords'};
480 my $offset = $args{'offset'};
481 my %opt = %{ $args{'opt'} };
482 my $self_url = $opt{'url'} || $cgi->url('-path_info' => 1, '-full' =>1);
484 my $count_sth = dbh->prepare($opt{'count_query'})
485 or die "Error preparing $opt{'count_query'}: ". dbh->errstr;
487 or die "Error executing $opt{'count_query'}: ". $count_sth->errstr;
488 my $count_arrayref = $count_sth->fetchrow_arrayref;
489 my $total = $count_arrayref->[0];