X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fsearch%2Felements%2Fsearch.html;h=12ab83ba52e20429910fd604893048c10b0f2de4;hp=fbedcaa26a5711d2a3860144b7116ec2bdd975d8;hb=d8ff6db2dbaec9cc8daad2d4af0254f167aa7a66;hpb=eb9668a6f3181ee02cb335272c5ee4616e61fd09
diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html
index fbedcaa26..12ab83ba5 100644
--- a/httemplate/search/elements/search.html
+++ b/httemplate/search/elements/search.html
@@ -1,9 +1,14 @@
<%
- my %opt = @_;
+ my(%opt) = @_;
+
+ if ( ref($opt{'query'}) ) {
+
+ }
+
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;
+ s/^\s*SELECT\s*(.*?)\s+FROM\s/SELECT COUNT(*) FROM /i;
}
my $conf = new FS::Conf;
@@ -18,18 +23,43 @@
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 $count_arrayref = $count_sth->fetchrow_arrayref;
+ my $total = $count_arrayref->[0];
+
+ #warn join(' / ', map { "$_ => $opt{$_}" } keys %opt ). "\n";
+
+ 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",
+ ) ];
+ } 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;
- 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;
- #can get # of rows without fetching them all?
- my $rows = $sth->fetchall_arrayref;
+ $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),
@@ -37,23 +67,60 @@
'maxrecords' => $maxrecords,
);
%>
-
-<%= $total %> total <%= $opt{'name'} %>
<%= $pager %>
-<%= include( '/elements/table.html' ) %>
-