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