so Search.tsf and Search.rdf work
[freeside.git] / httemplate / search / sqlradius.cgi
index 9cc5958..b84df1a 100644 (file)
     $ip = $1;
   }
 
+  my $prefix = $cgi->param('prefix');
+  $prefix =~ s/\D//g;
+  if ( $prefix =~ /^(\d+)$/ ) {
+    $prefix = $1;
+    $prefix = "011$prefix" unless $prefix =~ /^1/;
+  } else {
+    $prefix = '';
+  }
+
   ###
   # field formatting subroutines
   ###
@@ -64,7 +73,7 @@
       $svc_acct = $user2svc_acct{$user};
     } else {
       my %search = ();
-      if ( $part_export->exporrtype eq 'sqlradius_withdomain' ) {
+      if ( $part_export->exporttype eq 'sqlradius_withdomain' ) {
         my $domain;
         if ( $user =~ /^([^@]+)\@([^@]+)$/ ) {
          $search{'username'} = $1;
@@ -82,7 +91,8 @@
       } elsif ( $part_export->exporttype eq 'sqlradius' ) {
         $search{'username'} = $user;
       } else {
-        die "guru meditation #420";
+        die 'unknown export type '. $part_export->exporttype.
+            " for $part_export\n";
       }
       if ( keys %search ) {
         my @svc_acct =
     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/;
+    $pretty =~ s/ (\d)(st|dn|rd|th)/$1$2/;
+    $pretty;
   };
 
   my $duration_format = sub {
                              name    => 'User',
                              attrib  => 'UserName',
                              fmt     => $user_format,
+                             align   => 'left',
                            },
     'realm'             => {
                              name    => 'Realm',
                              attrib  => 'Realm',
+                             align   => 'left',
                            },
     'dummy'             => {
                              name    => 'Customer',
                              attrib  => '',
                              fmt     => $customer_format,
+                             align   => 'left',
                            },
     'framedipaddress'   => {
-                             name    => 'IP Address',
+                             name    => 'IP Address',
                              attrib  => 'Framed-IP-Address',
                              fmt     => sub { my $ip = shift;
                                               length($ip) ? $ip : '&nbsp';
                                             },
+                             align   => 'right',
                            },
     'acctstarttime'     => {
-                             name    => 'Start time',
+                             name    => 'Start time',
                              attrib  => 'Acct-Start-Time',
                              fmt     => $time_format,
+                             align   => 'left',
                            },
     'acctstoptime'      => {
-                             name    => 'End time',
+                             name    => 'End time',
                              attrib  => 'Acct-Stop-Time',
                              fmt     => $time_format,
+                             align   => 'left',
                            },
     'acctsessiontime'   => {
                              name    => 'Duration',
                              attrib  => 'Acct-Session-Time',
                              fmt     => $duration_format,
+                             align   => 'right',
                            },
     'acctinputoctets'   => {
                              name    => 'Upload', # (from user)',
                              attrib  => 'Acct-Input-Octets',
                              fmt     => $octets_format,
+                             align   => 'right',
                            },
     'acctoutputoctets'  => {
                              name    => 'Download', # (to user)',
                              attrib  => 'Acct-Output-Octets',
                              fmt     => $octets_format,
+                             align   => 'right',
                            },
   ;
   $fields{$_}->{fmt} ||= sub { length($_[0]) ? shift : '&nbsp'; }
   # and finally, display the thing
   ### 
 
-  foreach my $part_export ( map $_->rebless, 
+  foreach my $part_export (
+    #grep $_->can('usage_sessions'), qsearch( 'part_export' )
     qsearch( 'part_export', { 'exporttype' => 'sqlradius' } ),
     qsearch( 'part_export', { 'exporttype' => 'sqlradius_withdomain' } )
   ) {
     %user2svc_acct = ();
+
+    my $efields = tie my %efields, 'Tie::IxHash', %fields;
+    delete $efields{'framedipaddress'} if $part_export->option('hide_ip');
+    if ( $part_export->option('hide_data') ) {
+      delete $efields{$_} foreach qw(acctinputoctets acctoutputoctets);
+    }
+    if ( $part_export->option('show_called_station') ) {
+      $efields->Splice(1, 0,
+        'calledstationid' => {
+                               'name'   => 'Destination',
+                               'attrib' => 'Called-Station-ID',
+                               'fmt'    =>
+                                 sub { length($_[0]) ? shift : '&nbsp'; },
+                               'align'  => 'left',
+                             },
+      );
+    }
+
 %>
 
 <%= $part_export->exporttype %> to <%= $part_export->machine %><BR>
 <%= include( '/elements/table.html' ) %>
 <TR>
-  <% foreach my $field ( keys %fields ) { %>
+  <% foreach my $field ( keys %efields ) { %>
     <TH>
-      <%= $fields{$field}->{name} %><BR>
-      <FONT SIZE=-2><%= $fields{$field}->{attrib} %></FONT>
+      <%= $efields{$field}->{name} %><BR>
+      <FONT SIZE=-2><%= $efields{$field}->{attrib} %></FONT>
     </TH>
   <% } %>
 </TR>
 <% foreach my $session (
-  @{ $part_export->usage_sessions( $beginning, $ending, $cgi_svc_acct, $ip ) }
-) { %>
+     @{ $part_export->usage_sessions(
+          $beginning, $ending, $cgi_svc_acct, $ip, $prefix, ) }
+   ) {
+%>
   <TR>
-    <% foreach my $field ( keys %fields ) { %>
-      <TD ALIGN="right">
-        <%= &{ $fields{$field}->{fmt} }( $session->{$field},
+    <% foreach my $field ( keys %efields ) { %>
+      <TD ALIGN="<%= $efields{$field}->{align} %>">
+        <%= &{ $efields{$field}->{fmt} }( $session->{$field},
                                          $session,
                                          $part_export,
                                        )