ACL for hardware class config, RT#85057
[freeside.git] / FS / FS / msgcat.pm
1 package FS::msgcat;
2
3 use strict;
4 use vars qw( @ISA );
5 use Exporter;
6 use FS::UID;
7 use FS::Record; # qw( qsearchs );
8
9 @ISA = qw(FS::Record);
10
11 =head1 NAME
12
13 FS::msgcat - Object methods for message catalog entries
14
15 =head1 SYNOPSIS
16
17   use FS::msgcat;
18
19   $record = new FS::msgcat \%hash;
20   $record = new FS::msgcat { 'column' => 'value' };
21
22   $error = $record->insert;
23
24   $error = $new_record->replace($old_record);
25
26   $error = $record->delete;
27
28   $error = $record->check;
29
30 =head1 DESCRIPTION
31
32 An FS::msgcat object represents an message catalog entry.  FS::msgcat inherits 
33 from FS::Record.  The following fields are currently supported:
34
35 =over 4
36
37 =item msgnum - primary key
38
39 =item msgcode - Error code
40
41 =item locale - Locale
42
43 =item msg - Message
44
45 =back
46
47 If you just want to B<use> message catalogs, see L<FS::Msgcat>.
48
49 =head1 METHODS
50
51 =over 4
52
53 =item new HASHREF
54
55 Creates a new message catalog entry.  To add the message catalog entry to the
56 database, see L<"insert">.
57
58 Note that this stores the hash reference, not a distinct copy of the hash it
59 points to.  You can ask the object for a copy with the I<hash> method.
60
61 =cut
62
63 # the new method can be inherited from FS::Record, if a table method is defined
64
65 sub table { 'msgcat'; }
66
67 =item insert
68
69 Adds this record to the database.  If there is an error, returns the error,
70 otherwise returns false.
71
72 =cut
73
74 # the insert method can be inherited from FS::Record
75
76 =item delete
77
78 Delete this record from the database.
79
80 =cut
81
82 # the delete method can be inherited from FS::Record
83
84 =item replace OLD_RECORD
85
86 Replaces the OLD_RECORD with this one in the database.  If there is an error,
87 returns the error, otherwise returns false.
88
89 =cut
90
91 # the replace method can be inherited from FS::Record
92
93 =item check
94
95 Checks all fields to make sure this is a valid message catalog entry.  If there
96 is an error, returns the error, otherwise returns false.  Called by the insert
97 and replace methods.
98
99 =cut
100
101 # the check method should currently be supplied - FS::Record contains some
102 # data checking routines
103
104 sub check {
105   my $self = shift;
106
107   my $error =
108     $self->ut_numbern('msgnum')
109     || $self->ut_text('msgcode')
110 #    || $self->ut_text('msg')
111   ;
112   return $error if $error;
113
114   $self->locale =~ /^([\w\@]+)$/ or return "illegal locale: ". $self->locale;
115   $self->locale($1);
116
117   $self->SUPER::check
118 }
119
120
121 sub _upgrade_data { #class method
122   my( $class, %opts) = @_;
123
124   #"repopulate_msgcat", false laziness w/FS::Setup::populate_msgcat
125
126   my %messages = _legacy_messages();
127
128   foreach my $msgcode ( keys %messages ) {
129     foreach my $locale ( keys %{$messages{$msgcode}} ) {
130       my %msgcat = (
131         'msgcode' => $msgcode,
132         'locale'  => $locale,
133         #'msg'     => $messages{$msgcode}{$locale},
134       );
135       #my $msgcat = qsearchs('msgcat', \%msgcat);
136       my $msgcat = FS::Record::qsearchs('msgcat', \%msgcat); #wtf?
137       next if $msgcat;
138
139       $msgcat = new FS::msgcat( {
140         %msgcat,
141         'msg' => $messages{$msgcode}{$locale},
142       } );
143       my $error = $msgcat->insert;
144       die $error if $error;
145     }
146   }
147
148 }
149
150 sub _legacy_messages {
151
152   #  'msgcode' => {
153   #    'en_US' => 'Message',
154   #  },
155
156   (
157
158     'passwords_dont_match' => {
159       'en_US' => "Passwords don't match",
160     },
161
162     'invalid_card' => {
163       'en_US' => 'Invalid credit card number',
164     },
165
166     'unknown_card_type' => {
167       'en_US' => 'Unknown card type',
168     },
169
170     'not_a' => {
171       'en_US' => 'Not a ',
172     },
173
174     'empty_password' => {
175       'en_US' => 'Empty password',
176     },
177
178     'no_access_number_selected' => {
179       'en_US' => 'No access number selected',
180     },
181
182     'illegal_text' => {
183       'en_US' => 'Illegal (text)',
184       #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in field',
185     },
186
187     'illegal_or_empty_text' => {
188       'en_US' => 'Illegal or empty (text)',
189       #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in required field',
190     },
191
192     'illegal_username' => {
193       'en_US' => 'Illegal username',
194     },
195
196     'illegal_password' => {
197       'en_US' => 'Illegal password (',
198     },
199
200     'illegal_password_characters' => {
201       'en_US' => ' characters)',
202     },
203
204     'username_in_use' => {
205       'en_US' => 'Username in use',
206     },
207
208     'phonenum_in_use' => {
209       'en_US' => 'Phone number in use',
210     },
211
212     'illegal_email_invoice_address' => {
213       'en_US' => 'Illegal email invoice address',
214     },
215
216     'illegal_name' => {
217       'en_US' => 'Illegal (name)',
218       #'en_US' => 'Only letters, numbers, spaces and the following punctuation symbols are permitted: , . - \' in field',
219     },
220
221     'illegal_phone' => {
222       'en_US' => 'Illegal (phone)',
223       #'en_US' => '',
224     },
225
226     'illegal_zip' => {
227       'en_US' => 'Illegal (zip)',
228       #'en_US' => '',
229     },
230
231     'expired_card' => {
232       'en_US' => 'Expired card',
233     },
234
235     'daytime' => {
236       'en_US' => 'Day Phone',
237     },
238
239     'night' => {
240       'en_US' => 'Night Phone',
241     },
242
243     'svc_external-id' => {
244       'en_US' => 'External ID',
245     },
246
247     'svc_external-title' => {
248       'en_US' => 'Title',
249     },
250
251     'stateid' => {
252       'en_US' => 'Driver\'s License',
253     },
254
255     'stateid_state' => {
256       'en_US' => 'Driver\'s License State',
257     },
258
259     'invalid_domain' => {
260       'en_US' => 'Invalid domain',
261     },
262
263   );
264 }
265
266 =back
267
268 =head1 BUGS
269
270 i18n/l10n, eek
271
272 =head1 SEE ALSO
273
274 L<FS::Msgcat>, L<FS::Record>, schema.html from the base documentation.
275
276 =cut
277
278 1;
279