4 use vars qw( @ISA @pw_set $conf );
6 use FS::Record qw( qsearch qsearchs );
7 use FS::Msgcat qw(gettext);
11 @ISA = qw( FS::svc_Common );
14 @pw_set = ( 'a'..'k', 'm','n', 'p-z', 'A'..'N', 'P'..'Z' , '2'..'9' );
16 #ask FS::UID to run this stuff for us later
17 $FS::UID::callback{'FS::svc_acct'} = sub {
23 FS::svc_phone - Object methods for svc_phone records
29 $record = new FS::svc_phone \%hash;
30 $record = new FS::svc_phone { 'column' => 'value' };
32 $error = $record->insert;
34 $error = $new_record->replace($old_record);
36 $error = $record->delete;
38 $error = $record->check;
40 $error = $record->suspend;
42 $error = $record->unsuspend;
44 $error = $record->cancel;
48 An FS::svc_phone object represents a phone number. FS::svc_phone inherits
49 from FS::Record. The following fields are currently supported:
77 Creates a new phone number. To add the number to the database, see L<"insert">.
79 Note that this stores the hash reference, not a distinct copy of the hash it
80 points to. You can ask the object for a copy with the I<hash> method.
84 # the new method can be inherited from FS::Record, if a table method is defined
88 'name' => 'Phone number',
89 'sorts' => 'phonenum',
90 'display_weight' => 60,
91 'cancel_weight' => 80,
93 'countrycode' => { label => 'Country code',
95 disable_inventory => 1,
98 'phonenum' => 'Phone number',
99 'pin' => { label => 'Personal Identification Number',
101 disable_inventory => 1,
104 'sip_password' => 'SIP password',
110 sub table { 'svc_phone'; }
112 sub table_dupcheck_fields { ( 'countrycode', 'phonenum' ); }
114 =item search_sql STRING
116 Class method which returns an SQL fragment to search for the given string.
121 my( $class, $string ) = @_;
122 $class->search_sql_field('phonenum', $string );
127 Returns the phone number.
133 my $phonenum = $self->phonenum; #XXX format it better
134 my $label = $phonenum;
135 $label .= ' ('.$self->phone_name.')' if $self->phone_name;
141 Adds this record to the database. If there is an error, returns the error,
142 otherwise returns false.
146 # the insert method can be inherited from FS::Record
150 Delete this record from the database.
154 # the delete method can be inherited from FS::Record
156 =item replace OLD_RECORD
158 Replaces the OLD_RECORD with this one in the database. If there is an error,
159 returns the error, otherwise returns false.
163 # the replace method can be inherited from FS::Record
167 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
171 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
175 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
179 Checks all fields to make sure this is a valid phone number. If there is
180 an error, returns the error, otherwise returns false. Called by the insert
185 # the check method should currently be supplied - FS::Record contains some
186 # data checking routines
191 my $conf = new FS::Conf;
193 my $phonenum = $self->phonenum;
194 my $phonenum_check_method;
195 if ( $conf->exists('svc_phone-allow_alpha_phonenum') ) {
196 $phonenum =~ s/\W//g;
197 $phonenum_check_method = 'ut_alpha';
199 $phonenum =~ s/\D//g;
200 $phonenum_check_method = 'ut_number';
202 $self->phonenum($phonenum);
205 $self->ut_numbern('svcnum')
206 || $self->ut_numbern('countrycode')
207 || $self->$phonenum_check_method('phonenum')
208 || $self->ut_anything('sip_password')
209 || $self->ut_numbern('pin')
210 || $self->ut_textn('phone_name')
212 return $error if $error;
214 $self->countrycode(1) unless $self->countrycode;
216 unless ( length($self->sip_password) ) {
219 join('', map $pw_set[ int(rand $#pw_set) ], (0..16) )
227 =item _check duplicate
229 Internal method to check for duplicate phone numers.
233 #false laziness w/svc_acct.pm's _check_duplicate.
234 sub _check_duplicate {
237 my $global_unique = $conf->config('global_unique-phonenum') || 'none';
238 return '' if $global_unique eq 'disabled';
243 grep { !$self->svcnum || $_->svcnum != $self->svcnum }
244 qsearch( 'svc_phone', {
245 'countrycode' => $self->countrycode,
246 'phonenum' => $self->phonenum,
249 return gettext('phonenum_in_use')
250 if $global_unique eq 'countrycode+phonenum' && @dup_ccphonenum;
252 my $part_svc = qsearchs('part_svc', { 'svcpart' => $self->svcpart } );
253 unless ( $part_svc ) {
254 return 'unknown svcpart '. $self->svcpart;
257 if ( @dup_ccphonenum ) {
259 my $exports = FS::part_export::export_info('svc_phone');
260 my %conflict_ccphonenum_svcpart = ( $self->svcpart => 'SELF', );
262 foreach my $part_export ( $part_svc->part_export ) {
264 #this will catch to the same exact export
265 my @svcparts = map { $_->svcpart } $part_export->export_svc;
267 $conflict_ccphonenum_svcpart{$_} = $part_export->exportnum
272 foreach my $dup_ccphonenum ( @dup_ccphonenum ) {
273 my $dup_svcpart = $dup_ccphonenum->cust_svc->svcpart;
274 if ( exists($conflict_ccphonenum_svcpart{$dup_svcpart}) ) {
275 return "duplicate phone number ".
276 $self->countrycode. ' '. $self->phonenum.
277 ": conflicts with svcnum ". $dup_ccphonenum->svcnum.
278 " via exportnum ". $conflict_ccphonenum_svcpart{$dup_svcpart};
290 Checks the supplied PIN against the PIN in the database. Returns true for a
291 sucessful authentication, false if no match.
296 my($self, $check_pin) = @_;
297 length($self->pin) && $check_pin eq $self->pin;
306 #XXX Session-Timeout! holy shit, need rlm_perl to ask for this in realtime
318 my $conf = new FS::Conf;
320 $check{'User-Password'} = $conf->config('svc_phone-radius-default_password');
335 L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
336 L<FS::cust_pkg>, schema.html from the base documentation.