that should fix the new sip_password field, i hope
[freeside.git] / FS / FS / svc_phone.pm
1 package FS::svc_phone;
2
3 use strict;
4 use vars qw( @ISA );
5 #use FS::Record qw( qsearch qsearchs );
6 use FS::svc_Common;
7
8 @ISA = qw( FS::svc_Common );
9
10 =head1 NAME
11
12 FS::svc_phone - Object methods for svc_phone records
13
14 =head1 SYNOPSIS
15
16   use FS::svc_phone;
17
18   $record = new FS::svc_phone \%hash;
19   $record = new FS::svc_phone { 'column' => 'value' };
20
21   $error = $record->insert;
22
23   $error = $new_record->replace($old_record);
24
25   $error = $record->delete;
26
27   $error = $record->check;
28
29   $error = $record->suspend;
30
31   $error = $record->unsuspend;
32
33   $error = $record->cancel;
34
35 =head1 DESCRIPTION
36
37 An FS::svc_phone object represents a phone number.  FS::svc_phone inherits
38 from FS::Record.  The following fields are currently supported:
39
40 =over 4
41
42 =item svcnum
43
44 primary key
45
46 =item countrycode
47
48 =item phonenum
49
50 =item sip_password
51
52 =item pin
53
54 Voicemail PIN
55
56 =back
57
58 =head1 METHODS
59
60 =over 4
61
62 =item new HASHREF
63
64 Creates a new phone number.  To add the number to the database, see L<"insert">.
65
66 Note that this stores the hash reference, not a distinct copy of the hash it
67 points to.  You can ask the object for a copy with the I<hash> method.
68
69 =cut
70
71 # the new method can be inherited from FS::Record, if a table method is defined
72 #
73 sub table_info {
74   {
75     'name' => 'Phone number',
76     'sorts' => 'phonenum',
77     'display_weight' => 60,
78     'cancel_weight'  => 80,
79     'fields' => {
80         'countrycode'  => { label => 'Country code',
81                             type  => 'text',
82                             disable_inventory => 1,
83                             disable_select => 1,
84                           },
85         'phonenum'     => 'Phone number',
86         'pin'          => { label => 'Personal Identification Number',
87                             type  => 'text',
88                             disable_inventory => 1,
89                             disable_select => 1,
90                           },
91         'sip_password' => 'SIP password',
92     },
93   };
94 }
95
96 sub table { 'svc_phone'; }
97
98 =item search_sql STRING
99
100 Class method which returns an SQL fragment to search for the given string.
101
102 =cut
103
104 sub search_sql {
105   my( $class, $string ) = @_;
106   $class->search_sql_field('phonenum', $string );
107 }
108
109 =item label
110
111 Returns the phone number.
112
113 =cut
114
115 sub label {
116   my $self = shift;
117   $self->phonenum; #XXX format it better
118 }
119
120 =item insert
121
122 Adds this record to the database.  If there is an error, returns the error,
123 otherwise returns false.
124
125 =cut
126
127 # the insert method can be inherited from FS::Record
128
129 =item delete
130
131 Delete this record from the database.
132
133 =cut
134
135 # the delete method can be inherited from FS::Record
136
137 =item replace OLD_RECORD
138
139 Replaces the OLD_RECORD with this one in the database.  If there is an error,
140 returns the error, otherwise returns false.
141
142 =cut
143
144 # the replace method can be inherited from FS::Record
145
146 =item suspend
147
148 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
149
150 =item unsuspend
151
152 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
153
154 =item cancel
155
156 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
157
158 =item check
159
160 Checks all fields to make sure this is a valid phone number.  If there is
161 an error, returns the error, otherwise returns false.  Called by the insert
162 and replace methods.
163
164 =cut
165
166 # the check method should currently be supplied - FS::Record contains some
167 # data checking routines
168
169 sub check {
170   my $self = shift;
171
172   my $phonenum = $self->phonenum;
173   $phonenum =~ s/\D//g;
174   $self->phonenum($phonenum);
175
176   my $error = 
177     $self->ut_numbern('svcnum')
178     || $self->ut_numbern('countrycode')
179     || $self->ut_number('phonenum')
180     || $self->ut_anythingn('sip_password')
181     || $self->ut_numbern('pin')
182   ;
183   return $error if $error;
184
185   $self->countrycode(1) unless $self->countrycode;
186
187   $self->SUPER::check;
188 }
189
190 =item check_pin
191
192 Checks the supplied PIN against the PIN in the database.  Returns true for a
193 sucessful authentication, false if no match.
194
195 =cut
196
197 sub check_pin {
198   my($self, $check_pin) = @_;
199   $check_pin eq $self->pin;
200 }
201
202 =back
203
204 =head1 BUGS
205
206 =head1 SEE ALSO
207
208 L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
209 L<FS::cust_pkg>, schema.html from the base documentation.
210
211 =cut
212
213 1;
214