X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Felements%2Fsearch.html;h=7882bbf5695c4eeadabffd99db99b6e35b8ae898;hb=c2f77e3e9f95934545331b62a19579e45c98d403;hp=566ea8391a97ad364bf496c7b678fff2972614d2;hpb=f7fd2a3e34da751cbc02bbf215e99c6dc89adc15;p=freeside.git
diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html
index 566ea8391..7882bbf56 100644
--- a/httemplate/search/elements/search.html
+++ b/httemplate/search/elements/search.html
@@ -1,6 +1,7 @@
<%
my(%opt) = @_;
+ #warn join(' / ', map { "$_ => $opt{$_}" } keys %opt ). "\n";
my %align = (
'l' => 'left',
@@ -12,31 +13,39 @@
$opt{align} = [ map $align{$_}, split(//, $opt{align}) ],
unless !$opt{align} || ref($opt{align});
- if ( ref($opt{'query'}) ) {
+ my $type = '';
+ my $limit = '';
+ my($maxrecords, $total, $offset, $count_arrayref);
- }
+ if ( $cgi->param('_type') =~ /^(csv|\w*\.xls)$/ ) {
+
+ $type = $1;
- unless (exists($opt{'count_query'}) && length($opt{'count_query'})) {
- ( $opt{'count_query'} = $opt{'query'} ) =~
- s/^\s*SELECT\s*(.*?)\s+FROM\s/SELECT COUNT(*) FROM /i;
- }
+ } else { #setup some pagination things if we're in html mode
- my $conf = new FS::Conf;
- my $maxrecords = $conf->config('maxsearchrecordsperpage');
+ unless (exists($opt{'count_query'}) && length($opt{'count_query'})) {
+ ( $opt{'count_query'} = $opt{'query'} ) =~
+ s/^\s*SELECT\s*(.*?)\s+FROM\s/SELECT COUNT(*) FROM /i;
+ }
- my $limit = $maxrecords ? "LIMIT $maxrecords" : '';
+ my $conf = new FS::Conf;
+ $maxrecords = $conf->config('maxsearchrecordsperpage');
- my $offset = $cgi->param('offset') || 0;
- $limit .= " OFFSET $offset" if $offset;
+ $limit = $maxrecords ? "LIMIT $maxrecords" : '';
- my $count_sth = dbh->prepare($opt{'count_query'})
- or die "Error preparing $opt{'count_query'}: ". dbh->errstr;
- $count_sth->execute
- or die "Error executing $opt{'count_query'}: ". $count_sth->errstr;
- my $count_arrayref = $count_sth->fetchrow_arrayref;
- my $total = $count_arrayref->[0];
+ $offset = $cgi->param('offset') || 0;
+ $limit .= " OFFSET $offset" if $offset;
- #warn join(' / ', map { "$_ => $opt{$_}" } keys %opt ). "\n";
+ my $count_sth = dbh->prepare($opt{'count_query'})
+ or die "Error preparing $opt{'count_query'}: ". dbh->errstr;
+ $count_sth->execute
+ or die "Error executing $opt{'count_query'}: ". $count_sth->errstr;
+ $count_arrayref = $count_sth->fetchrow_arrayref;
+ $total = $count_arrayref->[0];
+
+ }
+
+ # run the query
my $header = $opt{'header'};
my $rows;
@@ -47,6 +56,8 @@
$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")
@@ -60,80 +71,326 @@
$header ||= $sth->{NAME};
}
- 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 )
- )
-%>
-<% my $pager = include ( '/elements/pager.html',
- 'offset' => $offset,
- 'num_rows' => scalar(@$rows),
- 'total' => $total,
- 'maxrecords' => $maxrecords,
- );
-%>
-<% unless ( $total ) { %>
- No matching <%= $opt{'name'} %> found.
-<% } else { %>
- <%= $total %> total <%= $opt{'name'} %>
- <% if ( $opt{'count_addl'} ) { %>
- <% my $n=0; foreach my $count ( @{$opt{'count_addl'}} ) { %>
- <%= sprintf( $count, $count_arrayref->[++$n] ) %>
- <% } %>
- <% } %>
-
<%= $pager %>
- <%= include( '/elements/table.html' ) %>
-