X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Felements%2Fsearch.html;h=140e15f45616aa9e90031d22479d81fb970c194a;hb=f2ccd32479007116f0008ffe67e933300b763b33;hp=fbedcaa26a5711d2a3860144b7116ec2bdd975d8;hpb=eb9668a6f3181ee02cb335272c5ee4616e61fd09;p=freeside.git
diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html
index fbedcaa26..140e15f45 100644
--- a/httemplate/search/elements/search.html
+++ b/httemplate/search/elements/search.html
@@ -1,59 +1,286 @@
<%
- my %opt = @_;
- 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(%opt) = @_;
+ #warn join(' / ', map { "$_ => $opt{$_}" } keys %opt ). "\n";
+
+ my %align = (
+ 'l' => 'left',
+ 'r' => 'right',
+ 'c' => 'center',
+ ' ' => '',
+ '.' => '',
+ );
+ $opt{align} = [ map $align{$_}, split(//, $opt{align}) ],
+ unless !$opt{align} || ref($opt{align});
+
+ my $type = '';
+ my $limit = '';
+ my($maxrecords, $total, $offset, $count_arrayref);
+
+ if ( $cgi->param('_type') =~ /^(csv|\w*\.xls)$/ ) {
+
+ $type = $1;
+
+ } else { #setup some pagination things if we're in html mode
+
+ 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 $conf = new FS::Conf;
+ $maxrecords = $conf->config('maxsearchrecordsperpage');
+
+ $limit = $maxrecords ? "LIMIT $maxrecords" : '';
+
+ $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;
+ if ( ref($opt{'query'}) ) {
+ #eval "use FS::$opt{'query'};";
+ $rows = [ qsearch(
+ $opt{'query'}->{'table'},
+ $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")
+ or die "Error preparing $opt{'query'}: ". dbh->errstr;
+ $sth->execute
+ or die "Error executing $opt{'query'}: ". $sth->errstr;
+
+ #can get # of rows without fetching them all?
+ $rows = $sth->fetchall_arrayref;
+
+ $header ||= $sth->{NAME};
}
- my $conf = new FS::Conf;
- my $maxrecords = $conf->config('maxsearchrecordsperpage');
-
- my $limit = $maxrecords ? "LIMIT $maxrecords" : '';
-
- my $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;
- my $total = $count_sth->fetchrow_arrayref->[0];
-
- my $sth = dbh->prepare("$opt{'query'} $limit")
- or die "Error preparing $opt{'query'}: ". dbh->errstr;
- $sth->execute
- or die "Error executing $opt{'query'}: ". $sth->errstr;
-
- #can get # of rows without fetching them all?
- my $rows = $sth->fetchall_arrayref;
-
-%>
-
-<% my $pager = include ( '/elements/pager.html',
- 'offset' => $offset,
- 'num_rows' => scalar(@$rows),
- 'total' => $total,
- 'maxrecords' => $maxrecords,
- );
-%>
-
-<%= $total %> total <%= $opt{'name'} %>
<%= $pager %>
-<%= include( '/elements/table.html' ) %>
-
+ <%= $total %> total <%= $opt{'name'} %> + <% if ( $opt{'count_addl'} ) { %> + <% my $n=0; foreach my $count ( @{$opt{'count_addl'}} ) { %> + <%= sprintf( $count, $count_arrayref->[++$n] ) %> + <% } %> + <% } %> + |
+
+ <% $cgi->param('_type', "$xlsname.xls" ); %>
+ Download full results + as Excel spreadsheet + <% $cgi->param('_type', 'csv'); %> + as CSV file + |
+ ||||
+
+ <%= $pager %>
+
+
|
+