]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - src/squid-accounting/accounting.cgi
Merge remote-tracking branch 'mfischer/slang' into next
[people/pmueller/ipfire-2.x.git] / src / squid-accounting / accounting.cgi
index a5a93767201ce50ad099ded24ea95432a5e45d1b..1ec9849eb7e3e14aae4c7bccf3b96ce0c1f4376b 100755 (executable)
@@ -92,15 +92,16 @@ if ($cgiparams{'BILLACTION'} eq "open_preview"){
        my $actyear  = $now[5];
        my ($from,$till)=&ACCT::getmonth($actmonth,$actyear);
        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
-       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>;
        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-Disposition:attachment;filename='tmp.pdf';\n\n";
        print @fileholder;
+       unlink ($tempfile);
        exit (0);
 }
 
@@ -906,7 +907,7 @@ sub generatemonthgraph{
        my $sth;
        my $cnt=0;
        #If we want to show Data from within last 2 months, get DATA from ACCT
-       if ( ! $grmon < ($mon+1) && $gryear == ($year+1900)){
+       if ( $grmon == ($mon)+1 && $gryear == ($year+1900)){
                $sth=&ACCT::getmonthgraphdata("ACCT",$from,$till,$grhost);
        }else{
                #If we want to show data from a date older than last two months, use ACCT_HIST
@@ -1958,9 +1959,9 @@ END
 sub viewtablehosts{
        $dbh=&ACCT::connectdb;
        &Header::openbox('100%', 'left', $Lang::tr{'acct hosts'});
-       my $mon=$_[0];
-       my $year=$_[1];
-       my ($from,$till)=&ACCT::getmonth($mon,$year);
+       my $mon1=$_[0];
+       my $year1=$_[1];
+       my ($from,$till)=&ACCT::getmonth($mon1,$year1);
        $count=0;
        #Menu to display another month
        print<<END;
@@ -1985,7 +1986,7 @@ END
                </select></td>
                <td style='text-align: center;'><select name='year'>
 END
-       for (my $j=2014;$j<=($year);$j++){
+       for (my $j=2014;$j<=($year1);$j++){
                if(($_[1]) eq $j){
                        print"<option selected>$j</option>";
                }else{
@@ -2010,7 +2011,12 @@ END
                <th></th>
        </tr>
 END
-       my $res = $dbh->selectall_arrayref("SELECT SUM(BYTES),min(TIME_RUN),max(TIME_RUN),NAME from ACCT where TIME_RUN between ".$from." and ".$till." group by NAME;");
+       my $res;
+       if (($mon)+1 == $mon1 && ($year)+1900 == $year1){
+               $res = $dbh->selectall_arrayref("SELECT SUM(BYTES),min(TIME_RUN),max(TIME_RUN),NAME from ACCT where TIME_RUN between ".$from." and ".$till." group by NAME;");
+       }else{
+               $res = $dbh->selectall_arrayref("SELECT SUM(BYTES),min(strftime('%s',TIME_RUN)),max(strftime('%s',TIME_RUN)),NAME from ACCT_HIST where date(TIME_RUN) > date($from,'unixepoch') and date(TIME_RUN) < date($till,'unixepoch') group by NAME;");
+       }
        my $sumbytes;
        my $type;
        my $lineval;
@@ -2035,8 +2041,8 @@ END
                                        <input type='image' src='/images/utilities-system-monitor.png' alt="$Lang::tr{'status'}" title="$Lang::tr{'status'}" />
                                        <input type='hidden' name='ACTION' value='viewgraph'>
                                        <input type='hidden' name='host' value='$name'>
-                                       <input type='hidden' name='month' value='$mon'>
-                                       <input type='hidden' name='year' value='$year'>
+                                       <input type='hidden' name='month' value='$mon1'>
+                                       <input type='hidden' name='year' value='$year1'>
                                        <input type='hidden' name='traffic' value="$Lang::tr{'acct sum'} $Lang::tr{'acct traffic'} $lineval $type">
                                        </form>