default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / FS / FS / svc_broadband.pm
index b5012ca..d05ae72 100755 (executable)
@@ -2,9 +2,11 @@ package FS::svc_broadband;
 use base qw(
   FS::svc_Radius_Mixin
   FS::svc_Tower_Mixin
+  FS::svc_Torrus_Mixin
   FS::svc_IP_Mixin 
+  FS::MAC_Mixin
   FS::svc_Common
-  );
+);
 
 use strict;
 use vars qw($conf);
@@ -94,6 +96,8 @@ points to.  You can ask the object for a copy with the I<hash> method.
 =cut
 
 sub table_info {
+  my $conf = new FS::Conf;
+  my $ip_addr_required = $conf->exists('svc_broadband-allow_null_ip_addr') ? '' : '1';
   {
     'name' => 'Wireless broadband',
     'name_plural' => 'Wireless broadband services',
@@ -101,18 +105,30 @@ sub table_info {
     'display_weight' => 50,
     'cancel_weight'  => 70,
     'ip_field' => 'ip_addr',
+    'manual_require' => 1,
     'fields' => {
       'svcnum'      => 'Service',
       'description' => 'Descriptive label',
-      'speed_down'  => 'Download speed (Kbps)',
-      'speed_up'    => 'Upload speed (Kbps)',
-      'ip_addr'     => 'IP address',
-      'blocknum'    => 
-      { 'label' => 'Address block',
-                         'type'  => 'select',
-                         'select_table' => 'addr_block',
-                          'select_key'   => 'blocknum',
-                         'select_label' => 'cidr',
+      'speed_up'    => {
+                         'label'    => 'Upload speed (Kbps)',
+                         'type'     => 'fcc_477_speed',
+                         'def_info' => 'both upload and download speed must be set to FCC 477 information if using that modifier',
+                       },
+      'speed_down'  => {
+                         'label'    => 'Download speed (Kbps)',
+                         'type'     => 'fcc_477_speed',
+                         'def_info' => 'both upload and download speed must be set to FCC 477 information if using that modifier',
+                       },
+      'ip_addr'     => {
+                         'label' => 'IP address',
+                         'required' => $ip_addr_required,
+                       },
+      'blocknum'    => {
+                         'label'             => 'Address block',
+                         'type'              => 'select',
+                         'select_table'      => 'addr_block',
+                          'select_key'       => 'blocknum',
+                         'select_label'      => 'cidr',
                          'disable_inventory' => 1,
                        },
      'plan_id' => 'Service Plan Id',
@@ -131,6 +147,7 @@ sub table_info {
                          #select_table => 'radius_group',
                          #select_key   => 'groupnum',
                          #select_label => 'groupname',
+                         disable_select => 1,
                          disable_inventory => 1,
                          multiple => 1,
                        },
@@ -143,6 +160,10 @@ sub table_info {
                              type              => 'search-svc_broadband',
                              disable_inventory => 1,
                            },
+      'serviceid' => 'Torrus serviceid', #but is should be hidden
+      'speed_test_up'      => { 'label' => 'Speed test upload (Kbps)' },
+      'speed_test_down'    => { 'label' => 'Speed test download (Kbps)' },
+      'speed_test_latency' => 'Speed test latency (ms)',
     },
   };
 }
@@ -234,10 +255,11 @@ sub search_sql {
   my( $class, $string ) = @_;
   if ( $string =~ /^(\d{1,3}\.){3}\d{1,3}$/ ) {
     $class->search_sql_field('ip_addr', $string );
-  } elsif ( $string =~ /^([a-fA-F0-9]{12})$/ ) {
+  } elsif ( $string =~ /^([A-F0-9]{12})$/i ) {
     $class->search_sql_field('mac_addr', uc($string));
-  } elsif ( $string =~ /^(([a-fA-F0-9]{1,2}:){5}([a-fA-F0-9]{1,2}))$/ ) {
-    $class->search_sql_field('mac_addr', uc("$2$3$4$5$6$7") );
+  } elsif ( $string =~ /^(([A-F0-9]{2}:){5}([A-F0-9]{2}))$/i ) {
+    $string =~ s/://g;
+    $class->search_sql_field('mac_addr', uc($string) );
   } elsif ( $string =~ /^(\d+)$/ ) {
     my $table = $class->table;
     "$table.svcnum = $1";
@@ -261,7 +283,7 @@ sub smart_search {
 
 =item label
 
-Returns the IP address.
+Returns the IP address, MAC address and description.
 
 =cut
 
@@ -347,6 +369,8 @@ sub check {
     || $self->ut_textn('description')
     || $self->ut_numbern('speed_up')
     || $self->ut_numbern('speed_down')
+    || $self->ut_numbern('speed_test_up')
+    || $self->ut_numbern('speed_test_down')
     || $self->ut_ipn('ip_addr')
     || $self->ut_hexn('mac_addr')
     || $self->ut_hexn('auth_key')
@@ -361,6 +385,7 @@ sub check {
     || $self->ut_snumbern('rssi')
     || $self->ut_numbern('suid')
     || $self->ut_foreign_keyn('shared_svcnum', 'svc_broadband', 'svcnum')
+    || $self->ut_textn('serviceid') #too lenient?
   ;
   return $error if $error;
 
@@ -418,22 +443,6 @@ sub _check_duplicate {
   '';
 }
 
-=item mac_addr_formatted CASE DELIMITER
-
-Format the MAC address (for use by exports).  If CASE starts with "l"
-(for "lowercase"), it's returned in lowercase.  DELIMITER is inserted
-between octets.
-
-=cut
-
-sub mac_addr_formatted {
-  my $self = shift;
-  my ($case, $delim) = @_;
-  my $addr = $self->mac_addr;
-  $addr = lc($addr) if $case =~ /^l/i;
-  join( $delim || '', $addr =~ /../g );
-}
-
 #class method
 sub _upgrade_data {
   my $class = shift;
@@ -511,6 +520,11 @@ sub _upgrade_data {
     #next SVC;
   }
 
+  require FS::Misc::FixIPFormat;
+  FS::Misc::FixIPFormat::fix_bad_addresses_in_table(
+      'svc_broadband', 'svcnum', 'ip_addr',
+  );
+
   '';
 }
 
@@ -533,4 +547,3 @@ FS::part_svc, schema.html from the base documentation.
 =cut
 
 1;
-