default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / search / elements / search-csv.html
1 % $csv->combine(@$header); #or die $csv->status;
2 %    
3 <% $opt{no_csv_header} ? '' : $csv->string %>\
4 %
5 % foreach my $row ( @$rows ) {
6 %
7 %   if ( $opt{'fields'} ) {
8 %
9 %     my @line = ();
10 %
11 %     foreach my $field ( @{$opt{'fields'}} ) {
12 %       if ( ref($field) eq 'CODE' ) {
13 %         push @line, map {
14 %                           ref($_) eq 'ARRAY'
15 %                             ? '(N/A)' #unimplemented
16 %                             : $_;
17 %                         }
18 %                         &{$field}($row);
19 %       } else {
20 %         push @line, $row->$field();
21 %       }
22 %     }
23 %
24 %     $csv->combine(@line); #or die $csv->status;
25 %
26 %   } else {
27 %     $csv->combine(@$row); #or die $csv->status;
28 %   }
29 %
30 <% $csv->string %>\
31 %
32 % }
33
34 % if ( $opt{'footer'} and !$opt{'no_csv_header'} ) {
35 %   my @footer;
36 %   foreach my $item (@{ $opt{'footer'} }) {
37 %     if ( ref($item) eq 'CODE' ) {
38 %       $item = &{$item}();
39 %     }
40 %     push @footer, $item;
41 %   }
42 %   $csv->combine(@footer);
43 <% $csv->string %>\
44 % }
45 <%init>
46
47 my %args = @_;
48 my $header = $args{'header'};
49 my $rows   = $args{'rows'};
50 my %opt    = %{ $args{'opt'} };
51
52 #http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes
53 #http_header('Content-Type' => 'text/plain' );
54 http_header('Content-Type' => 'text/csv' ); # So saith RFC 4180
55 http_header('Content-Disposition' => 
56   'attachment;filename="'.($opt{'name'} || PL($opt{'name_singular'}) ).'.csv"');
57
58 my $quote_char = '"';
59 $quote_char = $opt{csv_quote} if exists($opt{csv_quote});
60
61 my $csv = new Text::CSV_XS { 'always_quote' => $opt{avoid_quote} ? 0 : 1,
62                              'eol'          => "\n", #"\015\012", #"\012"
63                            };
64
65 </%init>