per address block ip auto assignment and auto router selection
[freeside.git] / FS / FS / svc_phone.pm
index fca3369..b91ba65 100644 (file)
@@ -1,12 +1,15 @@
 package FS::svc_phone;
 
 use strict;
-use vars qw( @ISA );
+use vars qw( @ISA @pw_set );
 #use FS::Record qw( qsearch qsearchs );
 use FS::svc_Common;
 
 @ISA = qw( FS::svc_Common );
 
+#avoid l 1 and o O 0
+@pw_set = ( 'a'..'k', 'm','n', 'p-z', 'A'..'N', 'P'..'Z' , '2'..'9' );
+
 =head1 NAME
 
 FS::svc_phone - Object methods for svc_phone records
@@ -39,13 +42,21 @@ from FS::Record.  The following fields are currently supported:
 
 =over 4
 
-=item svcnum - primary key
+=item svcnum
+
+primary key
+
+=item countrycode
+
+=item phonenum
 
-=item countrycode - 
+=item sip_password
 
-=item phonenum - 
+=item pin
 
-=item pin - 
+Voicemail PIN
+
+=item phone_name
 
 =back
 
@@ -63,9 +74,58 @@ points to.  You can ask the object for a copy with the I<hash> method.
 =cut
 
 # the new method can be inherited from FS::Record, if a table method is defined
+#
+sub table_info {
+  {
+    'name' => 'Phone number',
+    'sorts' => 'phonenum',
+    'display_weight' => 60,
+    'cancel_weight'  => 80,
+    'fields' => {
+        'countrycode'  => { label => 'Country code',
+                            type  => 'text',
+                            disable_inventory => 1,
+                            disable_select => 1,
+                          },
+        'phonenum'     => 'Phone number',
+        'pin'          => { label => 'Personal Identification Number',
+                            type  => 'text',
+                            disable_inventory => 1,
+                            disable_select => 1,
+                          },
+        'sip_password' => 'SIP password',
+        'name'         => 'Name',
+    },
+  };
+}
 
 sub table { 'svc_phone'; }
 
+=item search_sql STRING
+
+Class method which returns an SQL fragment to search for the given string.
+
+=cut
+
+sub search_sql {
+  my( $class, $string ) = @_;
+  $class->search_sql_field('phonenum', $string );
+}
+
+=item label
+
+Returns the phone number.
+
+=cut
+
+sub label {
+  my $self = shift;
+  my $phonenum = $self->phonenum; #XXX format it better
+  my $label = $phonenum;
+  $label .= ' ('.$self->phone_name.')' if $self->phone_name;
+  $label;
+}
+
 =item insert
 
 Adds this record to the database.  If there is an error, returns the error,
@@ -118,19 +178,45 @@ and replace methods.
 sub check {
   my $self = shift;
 
+  my $phonenum = $self->phonenum;
+  $phonenum =~ s/\D//g;
+  $self->phonenum($phonenum);
+
   my $error = 
     $self->ut_numbern('svcnum')
     || $self->ut_numbern('countrycode')
     || $self->ut_number('phonenum')
+    || $self->ut_anything('sip_password')
     || $self->ut_numbern('pin')
+    || $self->ut_textn('phone_name')
   ;
   return $error if $error;
 
   $self->countrycode(1) unless $self->countrycode;
 
+  unless ( length($self->sip_password) ) {
+
+    $self->sip_password(
+      join('', map $pw_set[ int(rand $#pw_set) ], (0..16) )
+    );
+
+  }
+
   $self->SUPER::check;
 }
 
+=item check_pin
+
+Checks the supplied PIN against the PIN in the database.  Returns true for a
+sucessful authentication, false if no match.
+
+=cut
+
+sub check_pin {
+  my($self, $check_pin) = @_;
+  $check_pin eq $self->pin;
+}
+
 =back
 
 =head1 BUGS