X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Felements%2Fsearch.html;h=140e15f45616aa9e90031d22479d81fb970c194a;hb=f2ccd32479007116f0008ffe67e933300b763b33;hp=712d63a915500906fedf4e6f6f986023a3fda7a1;hpb=b1fc20ef3b68a8536163fbb17c57bca15555f3c4;p=freeside.git
diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html
index 712d63a91..140e15f45 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);
- 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;
- }
+ if ( $cgi->param('_type') =~ /^(csv|\w*\.xls)$/ ) {
+
+ $type = $1;
- my $conf = new FS::Conf;
- my $maxrecords = $conf->config('maxsearchrecordsperpage');
+ } else { #setup some pagination things if we're in html mode
- my $limit = $maxrecords ? "LIMIT $maxrecords" : '';
+ 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 $offset = $cgi->param('offset') || 0;
- $limit .= " OFFSET $offset" if $offset;
+ my $conf = new FS::Conf;
+ $maxrecords = $conf->config('maxsearchrecordsperpage');
- 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];
+ $limit = $maxrecords ? "LIMIT $maxrecords" : '';
- #warn join(' / ', map { "$_ => $opt{$_}" } keys %opt ). "\n";
+ $offset = $cgi->param('offset') || 0;
+ $limit .= " OFFSET $offset" if $offset;
+
+ 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;
@@ -62,80 +71,216 @@
$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' ) %>
-