[freeside-commits] branch master updated. ac541a006ca3b90039d21dca39c76cee34092553

Mark Wells mark at 420.am
Thu Sep 8 14:40:27 PDT 2016


The branch, master has been updated
       via  ac541a006ca3b90039d21dca39c76cee34092553 (commit)
      from  88904ee5a5529f7e80811f1e68216c92b028e7e9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ac541a006ca3b90039d21dca39c76cee34092553
Author: Mark Wells <mark at freeside.biz>
Date:   Thu Sep 8 14:40:13 2016 -0700

    add delivery of spreadsheet/CSV reports, #72101

diff --git a/FS/FS/CGI.pm b/FS/FS/CGI.pm
index fc0f652..098cdf0 100644
--- a/FS/FS/CGI.pm
+++ b/FS/FS/CGI.pm
@@ -78,21 +78,17 @@ Sets an http header.
 
 sub http_header {
   my ( $header, $value ) = @_;
-  if (exists $ENV{MOD_PERL}) {
-    if ( defined $HTML::Mason::Commands::r  ) { #Mason
-      ## is this the correct pacakge for $r ???  for 1.0x and 1.1x ?
-      if ( $header =~ /^Content-Type$/ ) {
-        $HTML::Mason::Commands::r->content_type($value);
-      } else {
-        $HTML::Mason::Commands::r->header_out( $header => $value );
-      }
+  if ( defined $HTML::Mason::Commands::r  ) { #Mason + apache
+    if ( $header =~ /^Content-Type$/ ) {
+      $HTML::Mason::Commands::r->content_type($value);
     } else {
-      die "http_header called in unknown environment";
+      $HTML::Mason::Commands::r->header_out( $header => $value );
     }
+  } elsif ( defined $HTML::Mason::Commands::m ) {
+    $HTML::Mason::Commands::m->notes(lc("header-$header"), $value);
   } else {
-    die "http_header called not running under mod_perl";
+    warn "http_header($header, $value) called with no way to set headers\n";
   }
-
 }
 
 =item menubar ITEM, URL, ...
diff --git a/FS/FS/saved_search.pm b/FS/FS/saved_search.pm
index caaf7fe..fd82439 100644
--- a/FS/FS/saved_search.pm
+++ b/FS/FS/saved_search.pm
@@ -242,7 +242,25 @@ sub render {
   <p>' . $_ . '</p>';
   }
 
-  return $outbuf;
+  my %mime = (
+    Data        => $outbuf,
+    Type        => $mason_request->notes('header-content-type')
+                   || 'text/html',
+    Disposition => 'inline',
+  );
+  if (my $disp = $mason_request->notes('header-content-disposition') ) {
+    $disp =~ /^(attachment|inline)\s*;\s*filename=(.*)$/;
+    $mime{Disposition} = $1;
+    my $filename = $2;
+    $filename =~ s/^"(.*)"$/$1/;
+    $mime{Filename} = $filename;
+  }
+  if ($mime{Type} =~ /^text/) {
+    $mime{Encoding} = 'quoted-printable';
+  } else {
+    $mime{Encoding} = 'base64';
+  }
+  return MIME::Entity->build(%mime);
 }
 
 =item send
@@ -265,14 +283,7 @@ sub send {
     return $error;
   }
   $log->debug('Rendering saved search');
-  my $content = $self->render;
-  # XXX come back to this for content-type options
-  my $part = MIME::Entity->build(
-    'Type'        => 'text/html',
-    'Encoding'    => 'quoted-printable', # change this for spreadsheet
-    'Disposition' => 'inline',
-    'Data'        => $content,
-  );
+  my $part = $self->render;
 
   my %email_param = (
     'from'      => $conf->config('invoice_from'),
diff --git a/httemplate/edit/saved_search.html b/httemplate/edit/saved_search.html
index cb6aa45..f8f0333 100644
--- a/httemplate/edit/saved_search.html
+++ b/httemplate/edit/saved_search.html
@@ -23,14 +23,13 @@
       type    => 'fixed-date',
     },
     { field   => 'format',
-      type    => 'hidden', # revisit this later
-#      type    => 'select',
-#      options => [ 'html', 'xls', 'csv' ],
-#      labels => {
-#        'html' => 'webpage',
-#        'xls'  => 'spreadsheet',
-#        'csv'  => 'CSV',
-#      },
+      type    => 'select',
+      options => [ 'html', 'xls', 'csv' ],
+      labels => {
+        'html' => 'webpage',
+        'xls'  => 'spreadsheet',
+        'csv'  => 'CSV',
+      },
     },
     { field => 'disabled', # currently unused
       type  => 'hidden',
diff --git a/httemplate/search/elements/search-xls.html b/httemplate/search/elements/search-xls.html
index c4265e8..f2b0bad 100644
--- a/httemplate/search/elements/search-xls.html
+++ b/httemplate/search/elements/search-xls.html
@@ -22,7 +22,7 @@ http_header('Content-Disposition' => qq!attachment;filename="$filename"! );
  
 #http://support.microsoft.com/kb/812935
 #http://support.microsoft.com/kb/323308
-$HTML::Mason::Commands::r->headers_out->{'Cache-control'} = 'max-age=0';
+http_header('Cache-control' => 'max-age=0');
 
 my $data = '';
 my $XLS = new IO::Scalar \$data;

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/CGI.pm                               |   18 +++++++----------
 FS/FS/saved_search.pm                      |   29 +++++++++++++++++++---------
 httemplate/edit/saved_search.html          |   15 +++++++-------
 httemplate/search/elements/search-xls.html |    2 +-
 4 files changed, 35 insertions(+), 29 deletions(-)




More information about the freeside-commits mailing list