From ef7bb336cc67f127fb1d77532ad3da1369c0ae36 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 8 Aug 2003 02:02:41 +0000 Subject: - fix Mason profiling to pass-through images (for graph/) - fix graph/money-time.cgi use of $m interfering with Mason - fix graph/money-time-graph.cgi to set content-type in a Mason/ASP-independant fashion - (beginning of) includes! - (beginning of) moving SQL search to including generic elements/search.html - fix global.asa typo - fix masonize to not prepend an extraneous blank line (breaking graph/money-time-graph.cgi) --- httemplate/search/elements/search.html | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 httemplate/search/elements/search.html (limited to 'httemplate/search/elements/search.html') diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html new file mode 100644 index 000000000..fba8ee815 --- /dev/null +++ b/httemplate/search/elements/search.html @@ -0,0 +1,8 @@ +<% + +my $conf = new FS::Conf; +my $maxrecords = $conf->config('maxsearchrecordsperpage'); + +my $limit = $maxrecords ? "LIMIT $maxrecords" : ''; + +%> -- cgit v1.2.1 From e283ab567e6890727e4d8e35c1d8097398678753 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 8 Aug 2003 05:42:13 +0000 Subject: - (finish) includes! (closes: Bug#551) - (finish) moving SQL search to including generic elements/search.html - new elements: menubar.html, header.html, pager.html and table.html - have masonize process .html files also --- httemplate/search/elements/search.html | 57 ++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) (limited to 'httemplate/search/elements/search.html') diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index fba8ee815..fbedcaa26 100644 --- a/httemplate/search/elements/search.html +++ b/httemplate/search/elements/search.html @@ -1,8 +1,59 @@ <% -my $conf = new FS::Conf; -my $maxrecords = $conf->config('maxsearchrecordsperpage'); + 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 $limit = $maxrecords ? "LIMIT $maxrecords" : ''; + 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' ) %> + + <% foreach ( @{$sth->{NAME}} ) { %> + <%= $_ %> + <% } %> + + <% foreach my $row ( @$rows ) { %> + + <% foreach ( @$row ) { %> + <%= $_ %> + <% } %> + + <% } %> + + +<%= $pager %> + + -- cgit v1.2.1 From 5cd995865b91204f7ce9233a8ba4d5eee62f9be4 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 23 Apr 2004 02:32:38 +0000 Subject: working templated invoice search! --- httemplate/search/elements/search.html | 86 +++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 16 deletions(-) (limited to 'httemplate/search/elements/search.html') diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index fbedcaa26..37a3718ce 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 $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 $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; - #can get # of rows without fetching them all? - my $rows = $sth->fetchall_arrayref; + #can get # of rows without fetching them all? + $rows = $sth->fetchall_arrayref; + $header ||= $sth->{NAME}; + } + + if ( exists($opt{'redirect'}) && scalar(@$rows) == 1 ) { + my( $url, $method ) = @{$opt{'redirect'}}; + redirect( $url. $rows->[0]->$method() ); + } else { + +%> +<%= 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,18 +67,41 @@ 'maxrecords' => $maxrecords, ); %> - -<%= $total %> total <%= $opt{'name'} %>

<%= $pager %> +<%= $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' ) %> - <% foreach ( @{$sth->{NAME}} ) { %> - <%= $_ %> + <% foreach my $header ( @$header ) { %> + <%= $header %> <% } %> <% foreach my $row ( @$rows ) { %> - <% foreach ( @$row ) { %> - <%= $_ %> + <% 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(); + } + %> + <% if ( ref($field) eq 'CODE' ) { %> + <%= $a %><%= &{$field}($row) %><%= $a ? '' : '' %> + <% } else { %> + <%= $a %><%= $row->$field() %><%= $a ? '' : '' %> + <% } %> + <% } %> + <% } else { %> + <% foreach ( @$row ) { %> + <%= $_ %> + <% } %> <% } %> <% } %> @@ -57,3 +110,4 @@ <%= $pager %> +<% } %> -- cgit v1.2.1 From 87227cd405166484ca7b791b2bd3c8829ce8d969 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 23 Apr 2004 12:19:40 +0000 Subject: credit report, add some links to sales/credits/receipts summary, move payment search to template --- httemplate/search/elements/search.html | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'httemplate/search/elements/search.html') diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index 37a3718ce..226c4f784 100644 --- a/httemplate/search/elements/search.html +++ b/httemplate/search/elements/search.html @@ -50,11 +50,11 @@ $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 ) @@ -87,9 +87,16 @@ <% foreach my $field ( @{$opt{'fields'}} ) { %> <% my $a = ''; %> <% if ( $links ) { - my( $url, $method ) = @{shift @$links}; - $a = $url. $row->$method(); - $a = qq(); + my $link = shift @$links; + if ( $link ) { + my( $url, $method ) = @{$link}; + if ( ref($method) eq 'CODE' ) { + $a = $url. &{$method}($row); + } else { + $a = $url. $row->$method(); + } + $a = qq(); + } } %> <% if ( ref($field) eq 'CODE' ) { %> -- cgit v1.2.1 From 0f5028bc5a7789429a41bca886e5a38ed0fa099f Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 1 May 2004 22:49:09 +0000 Subject: don't display links to missing customers --- httemplate/search/elements/search.html | 1 + 1 file changed, 1 insertion(+) (limited to 'httemplate/search/elements/search.html') diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index 226c4f784..e739afb1d 100644 --- a/httemplate/search/elements/search.html +++ b/httemplate/search/elements/search.html @@ -88,6 +88,7 @@ <% 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' ) { -- cgit v1.2.1 From d8ff6db2dbaec9cc8daad2d4af0254f167aa7a66 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 28 May 2004 10:38:00 +0000 Subject: show a better message when no results are found --- httemplate/search/elements/search.html | 93 ++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 44 deletions(-) (limited to 'httemplate/search/elements/search.html') diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index e739afb1d..12ab83ba5 100644 --- a/httemplate/search/elements/search.html +++ b/httemplate/search/elements/search.html @@ -67,55 +67,60 @@ 'maxrecords' => $maxrecords, ); %> -<%= $total %> total <%= $opt{'name'} %>
-<% if ( $opt{'count_addl'} ) { %> - <% my $n=0; foreach my $count ( @{$opt{'count_addl'}} ) { %> - <%= sprintf( $count, $count_arrayref->[++$n] ) %>
+<% 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' ) %> - - <% foreach my $header ( @$header ) { %> - <%= $header %> - <% } %> - - <% foreach my $row ( @$rows ) { %> - - <% if ( $opt{'fields'} ) { %> - <% my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : ''; %> - <% foreach my $field ( @{$opt{'fields'}} ) { %> - <% 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(); +
<%= $pager %> + <%= include( '/elements/table.html' ) %> + + <% foreach my $header ( @$header ) { %> + <%= $header %> + <% } %> + + <% foreach my $row ( @$rows ) { %> + + <% if ( $opt{'fields'} ) { %> + <% my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : ''; %> + <% foreach my $field ( @{$opt{'fields'}} ) { %> + <% 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 = qq(); } - } - %> - <% if ( ref($field) eq 'CODE' ) { %> - <%= $a %><%= &{$field}($row) %><%= $a ? '' : '' %> - <% } else { %> - <%= $a %><%= $row->$field() %><%= $a ? '' : '' %> + %> + <% if ( ref($field) eq 'CODE' ) { %> + <%= $a %><%= &{$field}($row) %><%= $a ? '' : '' %> + <% } else { %> + <%= $a %><%= $row->$field() %><%= $a ? '' : '' %> + <% } %> + <% } %> + <% } else { %> + <% foreach ( @$row ) { %> + <%= $_ %> <% } %> <% } %> - <% } else { %> - <% foreach ( @$row ) { %> - <%= $_ %> - <% } %> - <% } %> - - <% } %> - - -<%= $pager %> + + <% } %> + + + <%= $pager %> +<% } %> <% } %> + -- cgit v1.2.1 From 19ca51b6b215fc76757812b5b4d2bea6dd6e4cf7 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 19 Aug 2004 00:22:29 +0000 Subject: add customer # to payment reports, add table cell alignment option to general search component --- httemplate/search/elements/search.html | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'httemplate/search/elements/search.html') diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index 12ab83ba5..566ea8391 100644 --- a/httemplate/search/elements/search.html +++ b/httemplate/search/elements/search.html @@ -2,6 +2,16 @@ my(%opt) = @_; + 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'}) ) { } @@ -85,11 +95,14 @@ <% foreach my $row ( @$rows ) { %> - <% if ( $opt{'fields'} ) { %> - <% my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : ''; %> - <% foreach my $field ( @{$opt{'fields'}} ) { %> - <% my $a = ''; %> - <% if ( $links ) { + <% 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 ) { @@ -104,9 +117,9 @@ } %> <% if ( ref($field) eq 'CODE' ) { %> - <%= $a %><%= &{$field}($row) %><%= $a ? '' : '' %> + ><%= $a %><%= &{$field}($row) %><%= $a ? '' : '' %> <% } else { %> - <%= $a %><%= $row->$field() %><%= $a ? '' : '' %> + ><%= $a %><%= $row->$field() %><%= $a ? '' : '' %> <% } %> <% } %> <% } else { %> -- cgit v1.2.1