my(%opt) = @_;
- if ( ref($opt{'query'}) ) {
+ my %align = (
+ 'l' => 'left',
+ 'r' => 'right',
+ 'c' => 'center',
+ ' ' => '',
+ '.' => '',
+ );
+ $opt{align} = [ map $align{$_}, split(//, $opt{align}) ],
+ unless !$opt{align} || ref($opt{align});
- }
+ #if ( ref($opt{'query'}) ) {
+ #
+ #}
unless (exists($opt{'count_query'}) && length($opt{'count_query'})) {
( $opt{'count_query'} = $opt{'query'} ) =~
$opt{'query'}->{'hashref'} || {},
$opt{'query'}->{'select'},
$opt{'query'}->{'extra_sql'}. " $limit",
+ '',
+ (exists($opt{'query'}->{'addl_from'}) ? $opt{'query'}->{'addl_from'} : '')
) ];
} else {
my $sth = dbh->prepare("$opt{'query'} $limit")
$header ||= $sth->{NAME};
}
- if ( exists($opt{'redirect'}) && scalar(@$rows) == 1 ) {
+ if ( exists($opt{'redirect'}) && scalar(@$rows) == 1 && $total == 1 ) {
my( $url, $method ) = @{$opt{'redirect'}};
redirect( $url. $rows->[0]->$method() );
} else {
-
+ $opt{'name'} =~ s/s$// if $total == 1;
%>
<%= include( '/elements/header.html', $opt{'title'},
include( '/elements/menubar.html', 'Main menu' => $p )
'maxrecords' => $maxrecords,
);
%>
-<%= $total %> total <%= $opt{'name'} %><BR>
-<% if ( $opt{'count_addl'} ) { %>
- <% my $n=0; foreach my $count ( @{$opt{'count_addl'}} ) { %>
- <%= sprintf( $count, $count_arrayref->[++$n] ) %><BR>
+<% unless ( $total ) { %>
+ No matching <%= $opt{'name'} %> found.<BR>
+<% } else { %>
+ <%= $total %> total <%= $opt{'name'} %><BR>
+ <% if ( $opt{'count_addl'} ) { %>
+ <% my $n=0; foreach my $count ( @{$opt{'count_addl'}} ) { %>
+ <%= sprintf( $count, $count_arrayref->[++$n] ) %><BR>
+ <% } %>
<% } %>
-<% } %>
-<BR><%= $pager %>
-<%= include( '/elements/table.html' ) %>
- <TR>
- <% foreach my $header ( @$header ) { %>
- <TH><%= $header %></TH>
- <% } %>
- </TR>
- <% foreach my $row ( @$rows ) { %>
- <TR>
- <% if ( $opt{'fields'} ) { %>
- <% my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : ''; %>
- <% foreach my $field ( @{$opt{'fields'}} ) { %>
- <% my $a = ''; %>
- <% if ( $links ) {
- my( $url, $method ) = @{shift @$links};
- $a = $url. $row->$method();
- $a = qq(<A HREF="$a">);
- }
- %>
- <% if ( ref($field) eq 'CODE' ) { %>
- <TD><%= $a %><%= &{$field}($row) %><%= $a ? '</A>' : '' %></TD>
- <% } else { %>
- <TD><%= $a %><%= $row->$field() %><%= $a ? '</A>' : '' %></TD>
+ <BR><%= $pager %>
+ <%= include( '/elements/table.html' ) %>
+ <TR>
+ <% foreach my $header ( @$header ) { %>
+ <TH><%= $header %></TH>
+ <% } %>
+ </TR>
+ <% foreach my $row ( @$rows ) { %>
+ <TR>
+ <% if ( $opt{'fields'} ) {
+ my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : '';
+ my $aligns = $opt{'align'} ? [ @{$opt{'align'}} ] : '';
+ foreach my $field ( @{$opt{'fields'}} ) {
+ my $align = $aligns ? shift @$aligns : '';
+ $align = " ALIGN=$align" if $align;
+ my $a = '';
+ if ( $links ) {
+ my $link = shift @$links;
+ $link = &{$link}($row) if ref($link) eq 'CODE';
+ if ( $link ) {
+ my( $url, $method ) = @{$link};
+ if ( ref($method) eq 'CODE' ) {
+ $a = $url. &{$method}($row);
+ } else {
+ $a = $url. $row->$method();
+ }
+ $a = qq(<A HREF="$a">);
+ }
+ }
+ %>
+ <% if ( ref($field) eq 'CODE' ) { %>
+ <TD<%= $align %>><%= $a %><%= &{$field}($row) %><%= $a ? '</A>' : '' %></TD>
+ <% } else { %>
+ <TD<%= $align %>><%= $a %><%= $row->$field() %><%= $a ? '</A>' : '' %></TD>
+ <% } %>
+ <% } %>
+ <% } else { %>
+ <% foreach ( @$row ) { %>
+ <TD><%= $_ %></TD>
<% } %>
<% } %>
- <% } else { %>
- <% foreach ( @$row ) { %>
- <TD><%= $_ %></TD>
- <% } %>
- <% } %>
- </TR>
- <% } %>
-
-</TABLE>
-<%= $pager %>
+ </TR>
+ <% } %>
+
+ </TABLE>
+ <%= $pager %>
+<% } %>
</BODY>
</HTML>
<% } %>
+