squid-accounting: create billpreview file as temporary file

This commit is contained in:
Alexander Marx
2014-08-06 15:10:41 +02:00
parent 1cdea84a90
commit a5f5ccfc4f
2 changed files with 9 additions and 4 deletions

View File

@@ -92,15 +92,16 @@ if ($cgiparams{'BILLACTION'} eq "open_preview"){
my $actyear = $now[5]; my $actyear = $now[5];
my ($from,$till)=&ACCT::getmonth($actmonth,$actyear); my ($from,$till)=&ACCT::getmonth($actmonth,$actyear);
my @billar = &ACCT::GetTaValues($from,$till,$rggrp); my @billar = &ACCT::GetTaValues($from,$till,$rggrp);
&ACCT::pdf2(\@billar,$actmonth,$actyear,$mwst,$address_cust,$address_host,$billpos,$rggrp,$cur,"on"); my $tempfile=&ACCT::pdf2(\@billar,$actmonth,$actyear,$mwst,$address_cust,$address_host,$billpos,$rggrp,$cur,"on");
#Show PDF preview #Show PDF preview
open(DLFILE, "</var/ipfire/accounting/bill/tmp.pdf") or die "Unable to open tmp.pdf: $!"; open(DLFILE, "<$tempfile") or die "Unable to open tmp.pdf: $!";
my @fileholder = <DLFILE>; my @fileholder = <DLFILE>;
print "Content-Type:application/pdf\n"; print "Content-Type:application/pdf\n";
my @fileinfo = stat("/var/ipfire/accounting/bill/tmp.pdf"); my @fileinfo = stat($tempfile);
print "Content-Length:$fileinfo[7]\n"; print "Content-Length:$fileinfo[7]\n";
print "Content-Disposition:attachment;filename='tmp.pdf';\n\n"; print "Content-Disposition:attachment;filename='tmp.pdf';\n\n";
print @fileholder; print @fileholder;
unlink ($tempfile);
exit (0); exit (0);
} }

View File

@@ -27,6 +27,7 @@ use PDF::API2;
use utf8; use utf8;
use Encode; use Encode;
use File::Copy; use File::Copy;
use File::Temp qw/ tempfile tempdir /;
############################################################################### ###############################################################################
my $dbh; my $dbh;
@@ -430,7 +431,7 @@ sub pdf2 {
#Check if we are creating a preview or a real bill #Check if we are creating a preview or a real bill
if($preview eq 'on'){ if($preview eq 'on'){
$filename="$path/tmp.pdf"; $filename="$path/".tempfile( SUFFIX => ".pdf", );
} }
#################################################################### ####################################################################
#Prepare DATA from arrays #Prepare DATA from arrays
@@ -791,6 +792,9 @@ sub pdf2 {
if ($preview ne 'on'){ if ($preview ne 'on'){
&fillBill($path.$grp,$name,$no,$grp); &fillBill($path.$grp,$name,$no,$grp);
} }
if($preview eq 'on'){
return $filename;
}
return '0'; return '0';
} }