- };
-
- my $customer_format = sub {
- my( $unused, $session ) = @_;
- return ' ' unless exists $user2svc_acct{$session->{'username'}};
- my $svc_acct = $user2svc_acct{$session->{'username'}};
- my $cust_pkg = $svc_acct->cust_svc->cust_pkg;
- return ' ' unless $cust_pkg;
- my $cust_main = $cust_pkg->cust_main;
-
- qq!<A HREF="${p}view/cust_main.cgi?!. $cust_main->custnum. '">'.
- $cust_pkg->cust_main->name. '</A>';
- };
-
- my $time_format = sub {
- my $time = shift;
- return ' ' if $time == 0;
- my $pretty = time2str('%T%P %a %b %o %Y', $time );
- $pretty =~ s/ (\d)(st|dn|rd|th)/ $1$2/;
- };
-
- my $duration_format = sub {
- my $seconds = shift;
- my $hour = int($seconds/3600);
- my $min = int( ($seconds%3600) / 60 );
- my $sec = $seconds%60;
- '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>'.
- '<TR><TD ALIGN="right">'.
- ( $hour ? "<B>$hour</B>h" : ' ' ).
- '</TD><TD ALIGN="right">'.
- ( ( $hour || $min ) ? "<B>$min</B>m" : ' ' ).
- '</TD><TD ALIGN="right">'.
- "<B>$sec</B>s".
- '</TD></TR></TABLE>';
- };
-
- my $octets_format = sub {
- my $octets = shift;
- my $megs = $octets / 1048576;
- sprintf('<B>%.3f</B> megs', $megs);
- #my $gigs = $octets / 1073741824
- #sprintf('<B>%.3f</B> gigabytes', $gigs);
- };
-
- ###
- # the fields
- ###
-
- tie my %fields, 'Tie::IxHash',
- 'username' => {
- name => 'User',
- attrib => 'UserName',
- fmt => $user_format,
- },
- 'realm' => {
- name => 'Realm',
- attrib => 'Realm',
- },
- 'dummy' => {
- name => 'Customer',
- attrib => '',
- fmt => $customer_format,
- },
- 'framedipaddress' => {
- name => 'IP Address',
- attrib => 'Framed-IP-Address',
- fmt => sub { my $ip = shift;
- length($ip) ? $ip : ' ';
- },
- },
- 'acctstarttime' => {
- name => 'Start time',
- attrib => 'Acct-Start-Time',
- fmt => $time_format,
- },
- 'acctstoptime' => {
- name => 'End time',
- attrib => 'Acct-Stop-Time',
- fmt => $time_format,
- },
- 'acctsessiontime' => {
- name => 'Duration',
- attrib => 'Acct-Session-Time',
- fmt => $duration_format,
- },
- 'acctinputoctets' => {
- name => 'Upload', # (from user)',
- attrib => 'Acct-Input-Octets',
- fmt => $octets_format,
- },
- 'acctoutputoctets' => {
- name => 'Download', # (to user)',
- attrib => 'Acct-Output-Octets',
- fmt => $octets_format,
- },
- ;
- $fields{$_}->{fmt} ||= sub { length($_[0]) ? shift : ' '; }
- foreach keys %fields;
-
- ###
- # and finally, display the thing
- ###
-
- foreach my $part_export ( map $_->rebless,
- qsearch( 'part_export', { 'exporttype' => 'sqlradius' } ),
- qsearch( 'part_export', { 'exporttype' => 'sqlradius_withdomain' } )
- ) {
- %user2svc_acct = ();
-%>
-
-<%= $part_export->exporttype %> to <%= $part_export->machine %><BR>
-<%= include( '/elements/table.html' ) %>
-<TR>
- <% foreach my $field ( keys %fields ) { %>
- <TH>
- <%= $fields{$field}->{name} %><BR>
- <FONT SIZE=-2><%= $fields{$field}->{attrib} %></FONT>
- </TH>
- <% } %>
-</TR>
-<% foreach my $session (
- @{ $part_export->usage_sessions( $beginning, $ending, $cgi_svc_acct, $ip ) }
-) { %>
- <TR>
- <% foreach my $field ( keys %fields ) { %>
- <TD ALIGN="right">
- <%= &{ $fields{$field}->{fmt} }( $session->{$field},
- $session,
- $part_export,
- )
- %>
- </TD>
- <% } %>
- </TR>
-<% } %>