From: mark Date: Tue, 16 Aug 2011 02:09:53 +0000 (+0000) Subject: reliably start batch download, #947 X-Git-Tag: freeside_2_3_1~329 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=35540b0694faa387546391a3e5f8d67b17244188 reliably start batch download, #947 --- diff --git a/httemplate/elements/progress-init.html b/httemplate/elements/progress-init.html index 9f17370db..2ec248e32 100644 --- a/httemplate/elements/progress-init.html +++ b/httemplate/elements/progress-init.html @@ -54,7 +54,10 @@ sub process_whatever { #class method ) %> -<% include('/elements/init_overlib.html') %> +% if (!$noinit) { +<& /elements/init_overlib.html &> +% $noinit = 1; +% } +<%once> +my $noinit = 0; + <%init> my( $formname, $fields, $action, $url_or_message, $key ) = @_; @@ -126,6 +132,7 @@ if ( ref($url_or_message) ) { #its a message or something if $url_or_message->{'url'}; $url_or_message_link = 'popup_url=' .uri_escape( $url_or_message->{'popup_url'} ) if $url_or_message->{'popup_url'}; + } else { $url_or_message_link = "url=$url_or_message"; } diff --git a/httemplate/misc/download-bill_batch.html b/httemplate/misc/download-bill_batch.html index 70e3003ce..9b5f1efa8 100644 --- a/httemplate/misc/download-bill_batch.html +++ b/httemplate/misc/download-bill_batch.html @@ -12,10 +12,15 @@ $m->clear_buffer; $r->content_type('application/pdf'); $r->headers_out->add( 'Content-Disposition' => 'attachment;filename="invoice_batch_'.$batchnum.'.pdf"'); +my $cookie = CGI::Cookie->new( + -name => "bill_batch_download", + -value => $batchnum, + -expires => '+1d', +); +$r->headers_out->add( 'Set-Cookie' => $cookie->as_string ); $m->print($content); -#$batch->pdf(''); -#my $error = $batch->replace; -# warn "error deleting cached PDF: '$error'\n" if $error; -#} +$batch->pdf(''); +my $error = $batch->replace; +warn "error deleting cached PDF: '$error'\n" if $error; diff --git a/httemplate/search/bill_batch.cgi b/httemplate/search/bill_batch.cgi index cbd7f270a..b6676f261 100755 --- a/httemplate/search/bill_batch.cgi +++ b/httemplate/search/bill_batch.cgi @@ -1,18 +1,31 @@ % my $batchnum = $cgi->param('download'); % if ( $batchnum =~ /^\d+$/ ) { -% $cgi->delete('download'); +% my $download = $p."misc/download-bill_batch.html?$batchnum"; Starting download... - + + + +
+Click here if your download does not start +
<& /elements/footer.html &> % } % else { +%# delete existing download cookie +% my $cookie = CGI::Cookie->new( +% -name => 'bill_batch_download', +% -value => 0, +% -expires => '-1d', +% ); +% $r->headers_out->add( 'Set-Cookie' => $cookie->as_string ); <% include( 'elements/search.html', 'title' => 'Invoice Batches', 'name_singular' => 'batch', @@ -52,11 +65,30 @@ function refreshParent() { 'agent_virt' => 1, 'agent_null_right' => [ 'Process global invoice batches', 'Configuration' ], 'agent_pos' => 1, + 'html_foot' => include('.foot'), ) %> %} +<%def .foot> + + <%init> my $curuser = $FS::CurrentUser::CurrentUser; @@ -76,8 +108,6 @@ my $count_query = "SELECT COUNT(*) FROM bill_batch WHERE". # $extra_sql AND " #my $extra_sql = ''; # may add something here later my $link = [ "${p}view/bill_batch.cgi?batchnum=", 'batchnum' ]; -my $download_id = int(rand(1000000)); - sub download_link { my $batch = shift; my $batchnum = $batch->batchnum; @@ -90,10 +120,10 @@ sub download_link { "Download$batchnum", [ 'batchnum', 'close' ], $p.'misc/process/bill_batch-print.html', - { url => $p."search/bill_batch.cgi?download=$batchnum" }, + { popup_url => $p."search/bill_batch.cgi?download=$batchnum" }, "batch$batchnum" #key ); - $html .= '' . + $html .= '' . ($batch->status eq 'O' ? 'Download and close' : 'Download'); $html .= ''; return $html;