4 use vars qw( @ISA @pw_set );
6 #use FS::Record qw( qsearch qsearchs );
9 @ISA = qw( FS::svc_Common );
12 @pw_set = ( 'a'..'k', 'm','n', 'p-z', 'A'..'N', 'P'..'Z' , '2'..'9' );
16 FS::svc_phone - Object methods for svc_phone records
22 $record = new FS::svc_phone \%hash;
23 $record = new FS::svc_phone { 'column' => 'value' };
25 $error = $record->insert;
27 $error = $new_record->replace($old_record);
29 $error = $record->delete;
31 $error = $record->check;
33 $error = $record->suspend;
35 $error = $record->unsuspend;
37 $error = $record->cancel;
41 An FS::svc_phone object represents a phone number. FS::svc_phone inherits
42 from FS::Record. The following fields are currently supported:
70 Creates a new phone number. To add the number to the database, see L<"insert">.
72 Note that this stores the hash reference, not a distinct copy of the hash it
73 points to. You can ask the object for a copy with the I<hash> method.
77 # the new method can be inherited from FS::Record, if a table method is defined
81 'name' => 'Phone number',
82 'sorts' => 'phonenum',
83 'display_weight' => 60,
84 'cancel_weight' => 80,
86 'countrycode' => { label => 'Country code',
88 disable_inventory => 1,
91 'phonenum' => 'Phone number',
92 'pin' => { label => 'Personal Identification Number',
94 disable_inventory => 1,
97 'sip_password' => 'SIP password',
103 sub table { 'svc_phone'; }
105 =item search_sql STRING
107 Class method which returns an SQL fragment to search for the given string.
112 my( $class, $string ) = @_;
113 $class->search_sql_field('phonenum', $string );
118 Returns the phone number.
124 my $phonenum = $self->phonenum; #XXX format it better
125 my $label = $phonenum;
126 $label .= ' ('.$self->phone_name.')' if $self->phone_name;
132 Adds this record to the database. If there is an error, returns the error,
133 otherwise returns false.
137 # the insert method can be inherited from FS::Record
141 Delete this record from the database.
145 # the delete method can be inherited from FS::Record
147 =item replace OLD_RECORD
149 Replaces the OLD_RECORD with this one in the database. If there is an error,
150 returns the error, otherwise returns false.
154 # the replace method can be inherited from FS::Record
158 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
162 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
166 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
170 Checks all fields to make sure this is a valid phone number. If there is
171 an error, returns the error, otherwise returns false. Called by the insert
176 # the check method should currently be supplied - FS::Record contains some
177 # data checking routines
182 my $phonenum = $self->phonenum;
183 $phonenum =~ s/\D//g;
184 $self->phonenum($phonenum);
187 $self->ut_numbern('svcnum')
188 || $self->ut_numbern('countrycode')
189 || $self->ut_number('phonenum')
190 || $self->ut_anything('sip_password')
191 || $self->ut_numbern('pin')
192 || $self->ut_textn('phone_name')
194 return $error if $error;
196 $self->countrycode(1) unless $self->countrycode;
198 unless ( length($self->sip_password) ) {
201 join('', map $pw_set[ int(rand $#pw_set) ], (0..16) )
211 Checks the supplied PIN against the PIN in the database. Returns true for a
212 sucessful authentication, false if no match.
217 my($self, $check_pin) = @_;
218 $check_pin eq $self->pin;
227 #XXX Session-Timeout! holy shit, need rlm_perl to ask for this in realtime
239 my $conf = new FS::Conf;
241 $check{'User-Password'} = $conf->config('svc_phone-radius-default_password');
256 L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
257 L<FS::cust_pkg>, schema.html from the base documentation.