default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / FS / FS / svc_conferencing.pm
1 package FS::svc_conferencing;
2 use base qw( FS::svc_Common );
3
4 use strict;
5 use Tie::IxHash;
6 #use FS::Record qw( qsearch qsearchs );
7
8 =head1 NAME
9
10 FS::svc_conferencing - Object methods for svc_conferencing records
11
12 =head1 SYNOPSIS
13
14   use FS::svc_conferencing;
15
16   $record = new FS::svc_conferencing \%hash;
17   $record = new FS::svc_conferencing { 'column' => 'value' };
18
19   $error = $record->insert;
20
21   $error = $new_record->replace($old_record);
22
23   $error = $record->delete;
24
25   $error = $record->check;
26
27 =head1 DESCRIPTION
28
29 An FS::svc_conferencing object represents a conferencing service.
30 FS::svc_conferencing inherits from FS::Record.  The following fields are
31 currently supported:
32
33 =over 4
34
35 =item svcnum
36
37 primary key
38
39 =item conf_id
40
41 conf_id
42
43 =item conf_name
44
45 conf_name
46
47 =item conf_password
48
49 conf_password
50
51 =item access_code
52
53 access_code
54
55 =item duration
56
57 duration
58
59 =item participants
60
61 participants
62
63 =item conftypenum
64
65 conftypenum
66
67 =item confqualitynum
68
69 confqualitynum
70
71 =item opt_recording
72
73 opt_recording
74
75 =item opt_sip
76
77 opt_sip
78
79 =item opt_phone
80
81 opt_phone
82
83
84 =back
85
86 =head1 METHODS
87
88 =over 4
89
90 =item new HASHREF
91
92 Creates a new record.  To add the record to the database, see L<"insert">.
93
94 Note that this stores the hash reference, not a distinct copy of the hash it
95 points to.  You can ask the object for a copy with the I<hash> method.
96
97 =cut
98
99 sub table { 'svc_conferencing'; }
100
101 sub table_info {
102
103   my %opts = ( 'type' => 'text', 
104                'disable_select' => 1,
105                'disable_inventory' => 1,
106              );
107
108   tie my %fields, 'Tie::IxHash',
109     'svcnum'         => { label => 'Service' },
110     'conf_id'        => { label => 'Conference ID', %opts, },
111     'conf_name'      => { label     => 'Conference Name',
112                           size      => 31,
113                           maxlength => 30,
114                           %opts,
115                         },
116     'conf_password'  => { label     => 'Password',
117                           size      => 31,
118                           maxlength => 30,
119                           %opts,
120                         },
121     'access_code'    => { label     => 'Access code' ,
122                           size      => 17,
123                           maxlength => 16,
124                           %opts,
125                         },
126     'duration'       => { label => 'Duration',
127                           type  => 'duration',
128                           disable_select    => 1,
129                           disable_inventory => 1,
130                           value_callback    => sub {
131                             my $min = shift->duration;
132                             int($min/60)."h".
133                             sprintf("%02d",$min%60)."m";
134                           },
135                         },
136     'participants'   => { label => 'Num. participants', size=>5, %opts },
137     'conftypenum'    => { label             => 'Conference type',
138                           type              => 'select-conferencing_type',
139                           disable_select    => 1,
140                           disable_inventory => 1,
141                           value_callback    => sub {
142                             shift->conferencing_type->typename;
143                           },
144                         },
145     'confqualitynum' => { label             => 'Quality',
146                           type              => 'select-conferencing_quality',
147                           disable_select    => 1,
148                           disable_inventory => 1,
149                           value_callback    => sub {
150                             shift->conferencing_quality->qualityname;
151                           },
152                         },
153     'opt_recording'  => { label             => 'Recording',
154                           type              => 'checkbox',
155                           value             => 'Y',
156                           disable_select    => 1,
157                           disable_inventory => 1,
158                         },
159     'opt_sip'        => { label             => 'SIP participation',
160                           type              => 'checkbox',
161                           value             => 'Y',
162                           disable_select    => 1,
163                           disable_inventory => 1,
164                         },
165     'opt_phone'      => { label             => 'Phone participation',
166                           type              => 'checkbox',
167                           value             => 'Y',
168                           disable_select    => 1,
169                           disable_inventory => 1,
170                         },
171   ;
172
173   {
174     'name'                => 'Conferencing', # service',
175     #'name_plural'     => '', #optional,
176     #'longname_plural' => '', #optional
177     'fields'              => \%fields,
178     'addl_process_fields' => [ 'duration_units' ],
179     'sorts'               => [ 'conf_id', 'conf_name' ],
180     'display_weight'      => 57,
181     'cancel_weight'       => 70, #?  no deps, so
182   };
183
184 }
185
186 sub label {
187   my $self = shift;
188   $self->conf_id.': '. $self->conf_name;
189 }
190
191 =item insert
192
193 Adds this record to the database.  If there is an error, returns the error,
194 otherwise returns false.
195
196 =item delete
197
198 Delete this record from the database.
199
200 =item replace OLD_RECORD
201
202 Replaces the OLD_RECORD with this one in the database.  If there is an error,
203 returns the error, otherwise returns false.
204
205 =item check
206
207 Checks all fields to make sure this is a valid record.  If there is
208 an error, returns the error, otherwise returns false.  Called by the insert
209 and replace methods.
210
211 =cut
212
213 sub check {
214   my $self = shift;
215
216   if ( $self->duration_units && $self->duration_units > 1 ) {
217     $self->duration( int( ($self->duration * $self->duration_units) + .5) );
218    
219     $self->duration_units(1);
220   }
221
222   my $error = 
223     $self->ut_numbern('svcnum')
224     || $self->ut_numbern('conf_id')
225     || $self->ut_text('conf_name')
226     || $self->ut_text('conf_password')
227     || $self->ut_text('access_code')
228     || $self->ut_number('duration')
229     || $self->ut_number('participants')
230     || $self->ut_number('conftypenum')
231     || $self->ut_number('confqualitynum')
232     || $self->ut_enum('opt_recording', [ '', 'Y' ])
233     || $self->ut_enum('opt_sip',       [ '', 'Y' ])
234     || $self->ut_enum('opt_phone',     [ '', 'Y' ])
235   ;
236   return $error if $error;
237
238   return 'Meeting name must be at least 4 characters'
239     unless length($self->conf_name) >= 4;
240   return 'Password must be at least 4 characters'
241     unless length($self->conf_password) >= 4;
242   return 'Access code must be at least 4 digits'
243     unless length($self->access_code) >= 4;
244
245
246   $self->SUPER::check;
247 }
248
249 =back
250
251 =head1 BUGS
252
253 =head1 SEE ALSO
254
255 L<FS::Record>
256
257 =cut
258
259 1;
260