X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fsearch%2Felements%2Fsearch-csv.html;h=90230e6dca4e153b35a08b414d15009b8943793d;hp=cd4ea63f55e33f9d4f06d7e4ef97a9cf23d95838;hb=HEAD;hpb=b9ec1f7c51efb5122b7dc88ccadb34e9e99a3b6f diff --git a/httemplate/search/elements/search-csv.html b/httemplate/search/elements/search-csv.html index cd4ea63f5..90230e6dc 100644 --- a/httemplate/search/elements/search-csv.html +++ b/httemplate/search/elements/search-csv.html @@ -1,6 +1,6 @@ % $csv->combine(@$header); #or die $csv->status; % -<% $csv->string %>\ +<% $opt{no_csv_header} ? '' : $csv->string %>\ % % foreach my $row ( @$rows ) { % @@ -27,10 +27,21 @@ % $csv->combine(@$row); #or die $csv->status; % } % -% <% $csv->string %>\ % % } +% +% if ( $opt{'footer'} and !$opt{'no_csv_header'} ) { +% my @footer; +% foreach my $item (@{ $opt{'footer'} }) { +% if ( ref($item) eq 'CODE' ) { +% $item = &{$item}(); +% } +% push @footer, $item; +% } +% $csv->combine(@footer); +<% $csv->string %>\ +% } <%init> my %args = @_; @@ -39,9 +50,15 @@ my $rows = $args{'rows'}; my %opt = %{ $args{'opt'} }; #http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes -http_header('Content-Type' => 'text/plain' ); +#http_header('Content-Type' => 'text/plain' ); +http_header('Content-Type' => 'text/csv' ); # So saith RFC 4180 +http_header('Content-Disposition' => + 'attachment;filename="'.($opt{'name'} || PL($opt{'name_singular'}) ).'.csv"'); + +my $quote_char = '"'; +$quote_char = $opt{csv_quote} if exists($opt{csv_quote}); -my $csv = new Text::CSV_XS { 'always_quote' => 1, +my $csv = new Text::CSV_XS { 'always_quote' => $opt{avoid_quote} ? 0 : 1, 'eol' => "\n", #"\015\012", #"\012" };