X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Felements%2Fsearch.html;h=636885edc45bab08f96580ddd1a1d5c4410673ac;hb=f1cd7f98b487e74aa60b6c41d3377cc60f7ac25a;hp=cbf0887a6a910fecc4b914d769d5ac11c4aef125;hpb=3ce7691203a7737406bf2d4442f7fd84b81f847e;p=freeside.git diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index cbf0887a6..636885edc 100644 --- a/httemplate/search/elements/search.html +++ b/httemplate/search/elements/search.html @@ -1,535 +1,407 @@ +<%doc> + +Example: + + include( 'elements/search.html', + + ### + # required + ### + + 'title' => 'Page title', + + 'name_singular' => 'item', #singular name for the records returned + #OR# # (preferred, will be pluralized automatically) + 'name' => 'items', #plural name for the records returned + # (deprecated, will be singularlized + # simplisticly) + + #literal SQL query string (deprecated?) or qsearch hashref or arrayref + #of qsearch hashrefs for a union of qsearches + 'query' => { + 'table' => 'tablename', + #everything else is optional... + 'hashref' => { 'field' => 'value', + 'field' => { 'op' => '<', + 'value' => '54', + }, + }, + 'select' => '*', + 'addl_from' => '', #'LEFT JOIN othertable USING ( key )', + 'extra_sql' => '', #'AND otherstuff', #'WHERE onlystuff', + 'order_by' => 'ORDER BY something', + + }, + # "select * from tablename"; + + #required unless 'query' is an SQL query string (shouldn't be...) + 'count_query' => 'SELECT COUNT(*) FROM tablename', + + ### + # recommended / common + ### + + #listref of column labels,
- <% $total %> total <% $opt{'name'} %>
- <% defined($opt{'html_posttotal'})
- ? ( ref($opt{'html_posttotal'})
- ? &{$opt{'html_posttotal'}}()
- : $opt{'html_posttotal'}
- )
- : ''
- %>
- -% if ( $opt{'count_addl'} ) { -% my $n=0; foreach my $count ( @{$opt{'count_addl'}} ) { - - <% sprintf( $count, $count_arrayref->[++$n] ) %> -% } +%> +% % } +<%init> - |
-% unless ( $opt{'disable_download'} ) {
+my(%opt) = @_;
+#warn join(' / ', map { "$_ => $opt{$_}" } keys %opt ). "\n";
-
-% $cgi->param('_type', "$xlsname.xls" );
+my $curuser = $FS::CurrentUser::CurrentUser;
- Download full results - as Excel spreadsheet -% $cgi->param('_type', 'csv'); +my $type = $cgi->param('_type') =~ /^(csv|\w*\.xls|select|html(-print)?)$/ + ? $1 : 'html' ; - as CSV file - |
-% }
+my %align = (
+ 'l' => 'left',
+ 'r' => 'right',
+ 'c' => 'center',
+ ' ' => '',
+ '.' => '',
+);
+$opt{align} = [ map $align{$_}, split(//, $opt{align}) ],
+ unless !$opt{align} || ref($opt{align});
- ||
- <% $pager %> +if($type =~ /csv|xls/) { + my $h = $opt{'header'}; + my @del; + my $i = 0; + do { + if( ref($h->[$i]) and exists($h->[$i]->{'nodownload'}) ) { + splice(@{$opt{$_}}, $i, 1) foreach + qw(header footer fields links link_onclicks + align color size style cell_style xls_format); + } + else { + $i++; + } + } while ( exists($h->[$i]) ); +} - <% include('/elements/table-grid.html') %> +$opt{disable_download} = 0 + if $opt{disable_download} && $curuser->access_right('Configuration download'); - | |||
<% $header %> | -% } + @link_agentnums = $curuser->agentnums; + $null_link = $curuser->access_right( $opt{'agent_null_right_link'} + || $opt{'agent_null_right'} ); -|||
---|---|---|---|
{'align'} -% ? ' ALIGN="'. $element->{'align'}. '"' -% : '' -% ). '>'. -% ( $element->{'link'} -% ? '' -% : '' -% ). -% $element->{'data'}. -% ( $element->{'link'} -% ? '' -% : '' -% ). -% ' | '; -% -% } @$rowref ). -% -% '
><% $font %><% $a %><% $s %><% $field %><% $es %><% $a ? '' : '' %><% $font ? '' : '' %> | -% } -% } else { -% foreach ( @$row ) { + $opt{'query'}{'extra_sql'} .= + ( $opt{'query'}{'extra_sql'} =~ /WHERE/i || keys %{$opt{'query'}{'hashref'}} + ? ' AND ' + : ' WHERE ' ). $agentnums_sql; -<% $_ %> | -% } -% } + $opt{'count_query'} .= + ( $opt{'count_query'} =~ /WHERE/i ? ' AND ' : ' WHERE ' ). $agentnums_sql; - -% } -% if ( $opt{'footer'} ) { + if ( $opt{'agent_pos'} || $opt{'agent_pos'} eq '0' + and scalar($curuser->agentnums) > 1 ) { + #false laziness w/statuspos above + my $pos = $opt{'agent_pos'}; -
<% $footer %> -% } + splice @{ $opt{'header'} }, $pos, 0, 'Agent'; + splice @{ $opt{'align'} }, $pos, 0, 'c'; + splice @{ $opt{'style'} }, $pos, 0, ''; + splice @{ $opt{'size'} }, $pos, 0, ''; + splice @{ $opt{'fields'} }, $pos, 0, + sub { $_[0]->agentnum ? $_[0]->agent->agent : '(global)'; }; + splice @{ $opt{'color'} }, $pos, 0, ''; + splice @{ $opt{'links'} }, $pos, 0, '' #[ 'agent link?', 'agentnum' ] + if $opt{'links'}; + splice @{ $opt{'link_onclicks'} }, $pos, 0, '' + if $opt{'link_onclicks'}; - |