default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / edit / elements / part_svc_column.html
1 <%doc>
2 To be called from part_svc.cgi.
3 <& elements/part_svc_column.html, 
4     'svc_acct',
5     # options...
6     'part_svc'  => $part_svc, # the existing part_svc to edit
7     'clone'     => 0,         # or a svcpart to clone from
8 &>
9
10 </%doc>
11 <%once>
12 # the semantics of this could be better
13
14 # all of these conditions are when NOT to allow that flag choice
15 # don't allow the 'inventory' flags (M, A) to be chosen for 
16 # fields that aren't free-text
17 my $inv_sub = sub { $_[0]->{disable_inventory} || $_[0]->{type} ne 'text' };
18
19 tie my %flag, 'Tie::IxHash',
20   ''  => { 'desc' => 'No default', 'condition' => sub { 0 } },
21   'D' => { 'desc' => 'Default', 
22            'condition' =>
23              sub { $_[0]->{disable_default } }
24          },
25   'F' => { 'desc' => 'Fixed (unchangeable)',
26            'condition' =>
27              sub { $_[0]->{disable_fixed} },
28          },
29   'S' => { 'desc' => 'Selectable Choice',
30            'condition' =>
31              sub { $_[0]->{disable_select} },
32          },
33   'M' => { 'desc' => 'Manual selection from inventory',
34            'condition' => $inv_sub,
35          },
36   'A' => { 'desc' => 'Automatically fill in from inventory',
37            'condition' => $inv_sub,
38          },
39   'H' => { 'desc' => 'Select from hardware class',
40            'condition' => sub { $_[0]->{type} ne 'select-hardware' },
41          },
42   'P' => { 'desc' => 'From package FCC 477 information',
43            'condition' => sub { $_[0]->{type} ne 'fcc_477_speed' }, # get values from package fcc 477 information
44          },
45   'X' => { 'desc' => 'Excluded',
46            'condition' => sub { 1 }, # obsolete
47          },
48 ;
49
50 # the semantics of this could be much better
51 sub flag_condition {
52   my $f = shift;
53   not &{ $flag{$f}->{'condition'} }(@_);
54 }
55
56 my %communigate_fields = (
57   'svc_acct'        => { map { $_=>1 }
58                             qw( file_quota file_maxnum file_maxsize
59                                 password_selfchange password_recover
60                               ),
61                             grep /^cgp_/, fields('svc_acct')
62   },
63   'svc_domain'      => { map { $_=>1 }
64                             qw( max_accounts trailer parent_svcnum ),
65                             grep /^(cgp|acct_def)_/, fields('svc_domain')
66   },
67 );
68 </%once>
69 <INPUT TYPE="hidden" NAME="svcdb" VALUE="<% $svcdb %>">
70 <BR>
71 %# include export selection
72 <& export_svc.html,
73   part_svc => $part_svc,
74   svcdb => $svcdb
75 &>
76
77 <FONT CLASS="fsinnerbox-title">Fields</FONT>
78 <& /elements/table-grid.html, cellpadding => 4 &>
79   <TR>
80     <TH BGCOLOR="#cccccc">Field</TH>
81     <TH BGCOLOR="#cccccc">Label</TH>
82     <TH BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>
83     <TH BGCOLOR="#cccccc"><% $manual_require ? 'Required?' : '' %></TH>
84   </TR>
85 % $part_svc->set('svcpart' => $opt{'clone'}) if $opt{'clone'}; # for now
86 % my $i = 0;
87 % foreach my $field (@fields) {
88 %   my $def = shift @defs;
89 %   my $part_svc_column = $part_svc->part_svc_column($field);
90 %   my $flag = $part_svc_column->columnflag;
91 %   my $formatter = $def->{'format'} || sub { shift };
92 %   my $value = &{$formatter}($part_svc_column->columnvalue);
93   <TR CLASS="row<%$i%>">
94     <TD ROWSPAN=2 CLASS="grid" ALIGN="right">
95       <% $def->{'label'} || $field %>
96     </TD>
97     <TD ROWSPAN=2 CLASS="grid">
98       <INPUT NAME="<% $svcdb %>__<% $field %>_label"
99              STYLE="text-align: right"
100              VALUE="<% $part_svc_column->columnlabel || $def->{'label'} |h %>">
101     </TD>
102
103     <TD ROWSPAN=1 CLASS="grid">
104 %   # flag selection
105 %   if ( $def->{'type'} eq 'disabled' ) {
106 %     $flag = '';
107       No default
108 %   } else {
109 %     my $name = $svcdb.'__'.$field.'_flag';
110       <SELECT NAME="<%$name%>"
111               ID="<%$name%>"
112               STYLE="width:100%"
113               onchange="flag_changed(this)">
114 %     foreach my $f (keys %flag) {
115 %       if ( flag_condition($f, $def, $svcdb, $field) ) {
116           <OPTION VALUE="<%$f%>"<% $flag eq $f ? ' SELECTED' : ''%>>
117             <% $flag{$f}->{desc} %>
118           </OPTION>
119 %       }
120 %     }
121       </SELECT>
122 %   } # if $def->{'type'} eq 'disabled'
123     </TD>
124     <TD CLASS="grid">
125 %   # value entry/selection
126 %   my $name = $svcdb.'__'.$field;
127 %   # These are all MANDATORY SELECT types.  Regardless of the flag value,
128 %   # there will never be a text input (either in svc_* or in part_svc) for
129 %   # these fields.
130 %   if ( $def->{'type'} eq 'checkbox' ) {
131       <& /elements/checkbox.html,
132           'field'       => $name,
133           'curr_value'  => $value,
134           'value'       => 'Y' &>
135 %
136 %   } elsif ( $def->{'type'} eq 'select' ) {
137 %
138 %     if ( $def->{'select_table'} ) {
139 %       # set the 'select_svc' flag to enable two-step selection of services
140 %       my $comp = '/elements/select-table.html';
141 %       $comp = '/elements/select-svc.html' if $def->{'select_svc'};
142       <& $comp,
143           'field'       => $name,
144           'id'          => $name.'_select',
145           'table'       => $def->{'select_table'},
146           'name_col'    => $def->{'select_label'},
147           'value_col'   => $def->{'select_key'},
148           'order_by'    => dbdef->table($def->{'select_table'})->primary_key,
149           'multiple'    => $def->{'multiple'},
150           'disable_empty' => $def->{'select_allow_empty'} ? undef : 1,
151           'empty_label' => $def->{'select_allow_empty'} ? ' ' : undef,
152           'curr_value'  => $value,
153           # these can be switched between multiple and singular,
154           # so put the complete curr_value in an attribute
155           'element_etc' => 'default="'.encode_entities($value).'"',
156       &>
157 %     } else {
158 %       my (@options, %labels);
159 %       if ( $def->{'select_list'} ) {
160 %         @options = @{ $def->{'select_list'} };
161 %         @labels{@options} = @options;
162 %       } elsif ( $def->{'select_hash'} ) {
163 %         if ( ref($def->{'select_hash'}) eq 'ARRAY' ) {
164 %           tie my %hash, 'Tie::IxHash', @{ $def->{'select_hash'} };
165 %           $def->{'select_hash'} = \%hash;
166 %         }
167 %         @options = keys( %{ $def->{'select_hash'} } );
168 %         %labels = %{ $def->{'select_hash'} };
169 %       }
170       <& /elements/select.html,
171           'field'       => $name,
172           'id'          => $name.'_select',
173           'options'     => \@options,
174           'labels'      => \%labels,
175           'multiple'    => $def->{'multiple'},
176           'curr_value'  => $value,
177       &>
178 %     }
179 %   } elsif ( $def->{'type'} =~ /^select-(.*?)(.html)?$/ && $1 ne 'hardware' ) {
180       <& "/elements/select-$1.html",
181           'field'       => $name,
182           'id'          => $name.'_select',
183           'multiple'    => $def->{'multiple'},
184           'curr_value'  => $value,
185       &>
186 %   } elsif ( $def->{'type'} eq 'communigate_pro-accessmodes' ) {
187       <& /elements/communigate_pro-accessmodes.html,
188           'element_name_prefix' => $name.'_',
189           'curr_value'  => $value,
190       &>
191 %   } elsif ( $def->{'type'} eq 'textarea' ) {
192 %   # special cases
193       <TEXTAREA NAME="<%$name%>"><% $value |h %></TEXTAREA>
194 %   } elsif ( $def->{'type'} eq 'disabled' ) {
195       <INPUT TYPE="hidden" NAME="<%$name%>" VALUE="">
196 %   } else {
197 %     # the normal case: a text input, and a _select which is an inventory
198 %     # or hardware class
199       <INPUT TYPE="text"
200              NAME="<%$name%>"
201              ID="<%$name%>" 
202              VALUE="<%$value%>">
203 %     my $mode = 'inventory';
204 %     my $multiple = 1;
205 %     if ( $def->{'type'} eq 'select-hardware' ) {
206 %       $mode = 'hardware';
207 %       $multiple = 0;
208 %     }
209 %
210 %     if ( $def->{'type'} eq 'fcc_477_speed' ) {
211 %       if ($field eq 'speed_up') {
212           <SPAN ID="<% $name %>_select">
213             upstream speed
214             <INPUT TYPE="hidden" ID="<% $name %>_select" NAME="<% $name %>_classnum" VALUE="up">
215           </SPAN>
216 %       } elsif ($field eq 'speed_down') {
217           <SPAN ID="<% $name %>_select">
218             downstream speed
219             <INPUT TYPE="hidden" ID="<% $name %>_select" NAME="<% $name %>_classnum" VALUE="down">
220           </SPAN>
221 %       }
222 %     } else {
223       <& /elements/select-table.html,
224           'field'       => $name.'_classnum',
225           'id'          => $name.'_select',
226           'table'       => $mode.'_class',
227           'name_col'    => 'classname',
228           'curr_value'  => $value,
229           'empty_label' => "Select $mode class",
230           'multiple'    => $multiple,
231       &>
232 %     }
233 %   }
234     </TD>
235     <TD>
236 %   if ($manual_require && 
237 %       (!$def->{'type'} || !(grep {$_ eq $def->{'type'}} ('checkbox','disabled')))
238 %   ) {
239       <INPUT ID="<% $name.'_required' %>" TYPE="checkbox" NAME="<% $svcdb %>__<% $field %>_required" VALUE="Y" 
240         <% ($part_svc_column->required || $def->{'required'}) ? 'CHECKED' : '' %> 
241         <% $def->{'required'} ? 'DISABLED' : '' %>
242        >
243 %   }
244     </TD>
245   </TR>
246   <TR CLASS="row<%$i%>">
247     <TD COLSPAN=3 CLASS="def_info">
248 %   if ( $def->{def_info} ) {
249       (<% $def->{def_info} %>)
250     </TD>
251   </TR>
252 %   }
253 % $i = 1-$i;
254 % } # foreach my $field
255 %
256 % # special case: svc_acct password edit ACL
257 % if ( $svcdb eq 'svc_acct' ) {
258 %   push @fields, 'restrict_edit_password';
259   <TR>
260     <TD COLSPAN=3 ALIGN="right">
261       <% emt('Require "Provision" access right to edit password') %>
262     </TD>
263     <TD COLSPAN=2>
264       <INPUT TYPE="checkbox" NAME="restrict_edit_password" VALUE="Y" \
265       <% $part_svc->restrict_edit_password ? 'CHECKED' : '' %>>
266     </TD>
267   </TR>
268 % }
269 % # special case: services with attached routers (false laziness...)
270 % if ( $svcdb eq 'svc_acct'
271 %      or $svcdb eq 'svc_broadband'
272 %      or $svcdb eq 'svc_dsl'
273 %      or $svcdb eq 'svc_circuit' ) {
274 %   push @fields, 'has_router';
275   <TR>
276     <TD COLSPAN=3 ALIGN="right">
277       <% emt('This service has an attached router') %>
278     </TD>
279     <TD COLSPAN=2>
280       <INPUT TYPE="checkbox" NAME="has_router" VALUE="Y" \
281       <% $part_svc->has_router ? 'CHECKED' : '' %>>
282     </TD>
283   </TR>
284 % }
285 </TABLE>
286 <& /elements/progress-init.html,
287   $svcdb, #form name
288   [ # form fields to send
289     'ALL'
290 #    qw(svc svcpart classnum selfservice_access disabled preserve exportnum),
291 #    @fields
292   ],
293   'process/part_svc.cgi',   # target
294   $p.'browse/part_svc.cgi', # redirect landing
295   $svcdb, #key
296 &>
297 % $svcpart = '' if $opt{clone};
298 <BR>
299 <INPUT NAME="submit"
300        TYPE="button"
301        VALUE="<% emt($svcpart ? 'Apply changes' : 'Add service') %>"
302        onclick="fixup_submit('<%$svcdb%>')"
303 >
304 <%init>
305 my $svcdb = shift;
306 my %opt = @_;
307 my $count = 0;
308 my $communigate = 0;
309 my $conf = FS::Conf->new;
310
311 my $part_svc = $opt{'part_svc'} || FS::part_svc->new;
312
313 # see if there are communigate exports configured
314 if ( exists $communigate_fields{$svcdb} ) {
315   $communigate = FS::part_export->count("exporttype like 'communigate%'");
316 }
317
318 my $svcpart = $opt{'clone'} || $part_svc->svcpart;
319
320 my @fields;
321 if ( defined( dbdef->table($svcdb) ) ) { # when is it ever not defined?
322   @fields = grep {
323     $_ ne 'svcnum'
324       and ( $communigate || ! $communigate_fields{$svcdb}->{$_} )
325       and ( !FS::part_svc->svc_table_fields($svcdb)->{$_}->{disable_part_svc_column}
326             || $part_svc->part_svc_column($_)->columnflag )
327   } fields($svcdb);
328 }
329 if ( $svcdb eq 'svc_acct'
330       or ( $svcdb eq 'svc_broadband' and $conf->exists('svc_broadband-radius') )
331    )
332 {
333   push @fields, 'usergroup';
334 }
335
336 my @defs = map { FS::part_svc->svc_table_fields($svcdb)->{$_} } @fields;
337 my $manual_require = FS::part_svc->svc_table_info($svcdb)->{'manual_require'};
338 </%init>