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