4 use vars qw( @ISA @pw_set $conf );
6 use FS::Record qw( qsearch qsearchs );
10 @ISA = qw( FS::svc_Common );
13 @pw_set = ( 'a'..'k', 'm','n', 'p-z', 'A'..'N', 'P'..'Z' , '2'..'9' );
15 #ask FS::UID to run this stuff for us later
16 $FS::UID::callback{'FS::svc_acct'} = sub {
22 FS::svc_phone - Object methods for svc_phone records
28 $record = new FS::svc_phone \%hash;
29 $record = new FS::svc_phone { 'column' => 'value' };
31 $error = $record->insert;
33 $error = $new_record->replace($old_record);
35 $error = $record->delete;
37 $error = $record->check;
39 $error = $record->suspend;
41 $error = $record->unsuspend;
43 $error = $record->cancel;
47 An FS::svc_phone object represents a phone number. FS::svc_phone inherits
48 from FS::Record. The following fields are currently supported:
76 Creates a new phone number. To add the number to the database, see L<"insert">.
78 Note that this stores the hash reference, not a distinct copy of the hash it
79 points to. You can ask the object for a copy with the I<hash> method.
83 # the new method can be inherited from FS::Record, if a table method is defined
87 'name' => 'Phone number',
88 'sorts' => 'phonenum',
89 'display_weight' => 60,
90 'cancel_weight' => 80,
92 'countrycode' => { label => 'Country code',
94 disable_inventory => 1,
97 'phonenum' => 'Phone number',
98 'pin' => { label => 'Personal Identification Number',
100 disable_inventory => 1,
103 'sip_password' => 'SIP password',
109 sub table { 'svc_phone'; }
111 sub table_dupcheck_fields { ( 'countrycode', 'phonenum' ); }
113 =item search_sql STRING
115 Class method which returns an SQL fragment to search for the given string.
120 my( $class, $string ) = @_;
121 $class->search_sql_field('phonenum', $string );
126 Returns the phone number.
132 my $phonenum = $self->phonenum; #XXX format it better
133 my $label = $phonenum;
134 $label .= ' ('.$self->phone_name.')' if $self->phone_name;
140 Adds this record to the database. If there is an error, returns the error,
141 otherwise returns false.
145 # the insert method can be inherited from FS::Record
149 Delete this record from the database.
153 # the delete method can be inherited from FS::Record
155 =item replace OLD_RECORD
157 Replaces the OLD_RECORD with this one in the database. If there is an error,
158 returns the error, otherwise returns false.
162 # the replace method can be inherited from FS::Record
166 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
170 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
174 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
178 Checks all fields to make sure this is a valid phone number. If there is
179 an error, returns the error, otherwise returns false. Called by the insert
184 # the check method should currently be supplied - FS::Record contains some
185 # data checking routines
190 my $conf = new FS::Conf;
192 my $phonenum = $self->phonenum;
193 my $phonenum_check_method;
194 if ( $conf->exists('svc_phone-allow_alpha_phonenum') ) {
195 $phonenum =~ s/\W//g;
196 $phonenum_check_method = 'ut_alpha';
198 $phonenum =~ s/\D//g;
199 $phonenum_check_method = 'ut_number';
201 $self->phonenum($phonenum);
204 $self->ut_numbern('svcnum')
205 || $self->ut_numbern('countrycode')
206 || $self->$phonenum_check_method('phonenum')
207 || $self->ut_anything('sip_password')
208 || $self->ut_numbern('pin')
209 || $self->ut_textn('phone_name')
211 return $error if $error;
213 $self->countrycode(1) unless $self->countrycode;
215 unless ( length($self->sip_password) ) {
218 join('', map $pw_set[ int(rand $#pw_set) ], (0..16) )
226 =item _check duplicate
228 Internal method to check for duplicate phone numers.
232 #false laziness w/svc_acct.pm's _check_duplicate.
233 sub _check_duplicate {
236 my $global_unique = $conf->config('global_unique-phonenum') || 'none';
237 return '' if $global_unique eq 'disabled';
242 grep { !$self->svcnum || $_->svcnum != $self->svcnum }
243 qsearch( 'svc_phone', {
244 'countrycode' => $self->countrycode,
245 'phonenum' => $self->phonenum,
248 return gettext('phonenum_in_use')
249 if $global_unique eq 'countrycode+phonenum' && @dup_ccphonenum;
251 my $part_svc = qsearchs('part_svc', { 'svcpart' => $self->svcpart } );
252 unless ( $part_svc ) {
253 return 'unknown svcpart '. $self->svcpart;
256 if ( @dup_ccphonenum ) {
258 my $exports = FS::part_export::export_info('svc_phone');
259 my %conflict_ccphonenum_svcpart = ( $self->svcpart => 'SELF', );
261 foreach my $part_export ( $part_svc->part_export ) {
263 #this will catch to the same exact export
264 my @svcparts = map { $_->svcpart } $part_export->export_svc;
266 $conflict_ccphonenum_svcpart{$_} = $part_export->exportnum
271 foreach my $dup_ccphonenum ( @dup_ccphonenum ) {
272 my $dup_svcpart = $dup_ccphonenum->cust_svc->svcpart;
273 if ( exists($conflict_ccphonenum_svcpart{$dup_svcpart}) ) {
274 return "duplicate phone number ".
275 $self->countrycode. ' '. $self->phonenum.
276 ": conflicts with svcnum ". $dup_ccphonenum->svcnum.
277 " via exportnum ". $conflict_ccphonenum_svcpart{$dup_svcpart};
289 Checks the supplied PIN against the PIN in the database. Returns true for a
290 sucessful authentication, false if no match.
295 my($self, $check_pin) = @_;
296 length($self->pin) && $check_pin eq $self->pin;
305 #XXX Session-Timeout! holy shit, need rlm_perl to ask for this in realtime
317 my $conf = new FS::Conf;
319 $check{'User-Password'} = $conf->config('svc_phone-radius-default_password');
334 L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
335 L<FS::cust_pkg>, schema.html from the base documentation.