form 477 improvements #6499
[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 %      
31 <% $csv->string %>\
32 %
33 % }
34 <%init>
35
36 my %args = @_;
37 my $header = $args{'header'};
38 my $rows   = $args{'rows'};
39 my %opt    = %{ $args{'opt'} };
40
41 #http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes
42 http_header('Content-Type' => 'text/plain' );
43
44 my $quote_char = '"';
45 $quote_char = $opt{csv_quote} if exists($opt{csv_quote});
46
47 my $csv = new Text::CSV_XS { 'always_quote' => $opt{avoid_quote} ? 0 : 1,
48                              'eol'          => "\n", #"\015\012", #"\012"
49                            };
50
51 </%init>