X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fsqlradius.pm;h=db66c39c0ca67839bec6c1f1d361297724b377d5;hb=6bf3df8177a22d2275b1a68045ab5ff2e831af42;hp=58cc5be95df82881fffa9a64540053e538e770e0;hpb=a72a10f754f7465121d6137bb3dcee0a21ea6443;p=freeside.git diff --git a/FS/FS/part_export/sqlradius.pm b/FS/FS/part_export/sqlradius.pm index 58cc5be95..db66c39c0 100644 --- a/FS/FS/part_export/sqlradius.pm +++ b/FS/FS/part_export/sqlradius.pm @@ -597,7 +597,8 @@ New-style: pass a hashref with the following keys: =item stoptime_end - Upper bound for AcctStopTime, as a UNIX timestamp -=item open_sessions - Only show records with no AcctStopTime (typically used without stoptime_* options and with starttime_* options instead) +=item session_status - 'closed' to only show records with AcctStopTime, +'open' to only show records I AcctStopTime, empty to show both. =item starttime_start - Lower bound for AcctStartTime, as a UNIX timestamp @@ -727,17 +728,24 @@ sub usage_sessions { push @where, " CalledStationID LIKE 'sip:$prefix\%'"; } - if ( $start ) { - push @where, "$str2time AcctStopTime ) >= ?"; - push @param, $start; - } - if ( $end ) { - push @where, "$str2time AcctStopTime ) <= ?"; - push @param, $end; + my $acctstoptime = ''; + if ( $opt->{session_status} ne 'open' ) { + if ( $start ) { + $acctstoptime .= "$str2time AcctStopTime ) >= ?"; + push @param, $start; + $acctstoptime .= ' AND ' if $end; + } + if ( $end ) { + $acctstoptime .= "$str2time AcctStopTime ) <= ?"; + push @param, $end; + } } - if ( $opt->{open_sessions} ) { - push @where, 'AcctStopTime IS NULL'; + if ( $opt->{session_status} ne 'closed' ) { + $acctstoptime = "( $acctstoptime ) OR " if $acctstoptime; + $acctstoptime .= 'AcctStopTime IS NULL'; } + push @where, $acctstoptime; + if ( $opt->{starttime_start} ) { push @where, "$str2time AcctStartTime ) >= ?"; push @param, $opt->{starttime_start}; @@ -756,10 +764,14 @@ sub usage_sessions { my $orderby = 'ORDER BY AcctStartTime DESC'; $orderby = '' if $summarize; - my $sth = $dbh->prepare('SELECT '. join(', ', @fields). - " FROM radacct $where $groupby $orderby - ") or die $dbh->errstr; - $sth->execute(@param) or die $sth->errstr; + my $sql = 'SELECT '. join(', ', @fields). + " FROM radacct $where $groupby $orderby"; + if ( $DEBUG ) { + warn $sql; + warn join(',', @param); + } + my $sth = $dbh->prepare($sql) or die $dbh->errstr; + $sth->execute(@param) or die $sth->errstr; [ map { { %$_ } } @{ $sth->fetchall_arrayref({}) } ];