2 To be called from part_svc.cgi.
3 <& elements/part_svc_column.html,
6 'part_svc' => $part_svc, # the existing part_svc to edit
7 'clone' => 0, # or a svcpart to clone from
12 # the semantics of this could be better
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',
22 sub { $_[0]->{disable_default } }
24 'F' => { 'desc' => 'Fixed (unchangeable)',
26 sub { $_[0]->{disable_fixed} },
28 'S' => { 'desc' => 'Selectable Choice',
30 sub { $_[0]->{disable_select} },
32 'M' => { 'desc' => 'Manual selection from inventory',
33 'condition' => $inv_sub,
35 'A' => { 'desc' => 'Automatically fill in from inventory',
36 'condition' => $inv_sub,
38 'H' => { 'desc' => 'Select from hardware class',
39 'condition' => sub { $_[0]->{type} ne 'select-hardware' },
41 'X' => { 'desc' => 'Excluded',
42 'condition' => sub { 1 }, # obsolete
46 # the semantics of this could be much better
49 not &{ $flag{$f}->{'condition'} }(@_);
52 my %communigate_fields = (
53 'svc_acct' => { map { $_=>1 }
54 qw( file_quota file_maxnum file_maxsize
55 password_selfchange password_recover
57 grep /^cgp_/, fields('svc_acct')
59 'svc_domain' => { map { $_=>1 }
60 qw( max_accounts trailer parent_svcnum ),
61 grep /^(cgp|acct_def)_/, fields('svc_domain')
65 <INPUT TYPE="hidden" NAME="svcdb" VALUE="<% $svcdb %>">
67 %# include export selection
69 part_svc => $part_svc,
73 <FONT CLASS="fsinnerbox-title">Fields</FONT>
74 <& /elements/table-grid.html, cellpadding => 4 &>
76 <TH BGCOLOR="#cccccc">Field</TH>
77 <TH BGCOLOR="#cccccc">Label</TH>
78 <TH BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>
79 <TH BGCOLOR="#cccccc"><% $manual_require ? 'Required?' : '' %></TH>
81 % $part_svc->set('svcpart' => $opt{'clone'}) if $opt{'clone'}; # for now
83 % foreach my $field (@fields) {
84 % my $def = shift @defs;
85 % my $part_svc_column = $part_svc->part_svc_column($field);
86 % my $flag = $part_svc_column->columnflag;
87 % my $formatter = $def->{'format'} || sub { shift };
88 % my $value = &{$formatter}($part_svc_column->columnvalue);
89 <TR CLASS="row<%$i%>">
90 <TD ROWSPAN=2 CLASS="grid" ALIGN="right">
91 <% $def->{'label'} || $field %>
93 <TD ROWSPAN=2 CLASS="grid">
94 <INPUT NAME="<% $svcdb %>__<% $field %>_label"
95 STYLE="text-align: right"
96 VALUE="<% $part_svc_column->columnlabel || $def->{'label'} |h %>">
99 <TD ROWSPAN=1 CLASS="grid">
101 % if ( $def->{'type'} eq 'disabled' ) {
105 % my $name = $svcdb.'__'.$field.'_flag';
106 <SELECT NAME="<%$name%>"
109 onchange="flag_changed(this)">
110 % foreach my $f (keys %flag) {
111 % if ( flag_condition($f, $def, $svcdb, $field) ) {
112 <OPTION VALUE="<%$f%>"<% $flag eq $f ? ' SELECTED' : ''%>>
113 <% $flag{$f}->{desc} %>
118 % } # if $def->{'type'} eq 'disabled'
121 % # value entry/selection
122 % my $name = $svcdb.'__'.$field;
123 % # These are all MANDATORY SELECT types. Regardless of the flag value,
124 % # there will never be a text input (either in svc_* or in part_svc) for
126 % if ( $def->{'type'} eq 'checkbox' ) {
127 <& /elements/checkbox.html,
129 'curr_value' => $value,
132 % } elsif ( $def->{'type'} eq 'select' ) {
134 % if ( $def->{'select_table'} ) {
135 % # set the 'select_svc' flag to enable two-step selection of services
136 % my $comp = '/elements/select-table.html';
137 % $comp = '/elements/select-svc.html' if $def->{'select_svc'};
140 'id' => $name.'_select',
141 'table' => $def->{'select_table'},
142 'name_col' => $def->{'select_label'},
143 'value_col' => $def->{'select_key'},
144 'order_by' => dbdef->table($def->{'select_table'})->primary_key,
145 'multiple' => $def->{'multiple'},
146 'disable_empty' => $def->{'select_allow_empty'} ? undef : 1,
147 'empty_label' => $def->{'select_allow_empty'} ? ' ' : undef,
148 'curr_value' => $value,
149 # these can be switched between multiple and singular,
150 # so put the complete curr_value in an attribute
151 'element_etc' => 'default="'.encode_entities($value).'"',
154 % my (@options, %labels);
155 % if ( $def->{'select_list'} ) {
156 % @options = @{ $def->{'select_list'} };
157 % @labels{@options} = @options;
158 % } elsif ( $def->{'select_hash'} ) {
159 % if ( ref($def->{'select_hash'}) eq 'ARRAY' ) {
160 % tie my %hash, 'Tie::IxHash', @{ $def->{'select_hash'} };
161 % $def->{'select_hash'} = \%hash;
163 % @options = keys( %{ $def->{'select_hash'} } );
164 % %labels = %{ $def->{'select_hash'} };
166 <& /elements/select.html,
168 'id' => $name.'_select',
169 'options' => \@options,
170 'labels' => \%labels,
171 'multiple' => $def->{'multiple'},
172 'curr_value' => $value,
175 % } elsif ( $def->{'type'} =~ /^select-(.*?)(.html)?$/ && $1 ne 'hardware' ) {
176 <& "/elements/select-$1.html",
178 'id' => $name.'_select',
179 'multiple' => $def->{'multiple'},
180 'curr_value' => $value,
182 % } elsif ( $def->{'type'} eq 'communigate_pro-accessmodes' ) {
183 <& /elements/communigate_pro-accessmodes.html,
184 'element_name_prefix' => $name.'_',
185 'curr_value' => $value,
187 % } elsif ( $def->{'type'} eq 'textarea' ) {
189 <TEXTAREA NAME="<%$name%>"><% $value |h %></TEXTAREA>
190 % } elsif ( $def->{'type'} eq 'disabled' ) {
191 <INPUT TYPE="hidden" NAME="<%$name%>" VALUE="">
193 % # the normal case: a text input, and a _select which is an inventory
194 % # or hardware class
199 % my $mode = 'inventory';
201 % if ( $def->{'type'} eq 'select-hardware' ) {
202 % $mode = 'hardware';
205 <& /elements/select-table.html,
206 'field' => $name.'_classnum',
207 'id' => $name.'_select',
208 'table' => $mode.'_class',
209 'name_col' => 'classname',
210 'curr_value' => $value,
211 'empty_label' => "Select $mode class",
212 'multiple' => $multiple,
217 % if ($manual_require &&
218 % (!$def->{'type'} || !(grep {$_ eq $def->{'type'}} ('checkbox','disabled')))
220 <INPUT ID="<% $name.'_required' %>" TYPE="checkbox" NAME="<% $svcdb %>__<% $field %>_required" VALUE="Y"
221 <% ($part_svc_column->required || $def->{'required'}) ? 'CHECKED' : '' %>
222 <% $def->{'required'} ? 'DISABLED' : '' %>
227 <TR CLASS="row<%$i%>">
228 <TD COLSPAN=3 CLASS="def_info">
229 % if ( $def->{def_info} ) {
230 (<% $def->{def_info} %>)
235 % } # foreach my $field
237 % # special case: svc_acct password edit ACL
238 % if ( $svcdb eq 'svc_acct' ) {
239 % push @fields, 'restrict_edit_password';
241 <TD COLSPAN=3 ALIGN="right">
242 <% emt('Require "Provision" access right to edit password') %>
245 <INPUT TYPE="checkbox" NAME="restrict_edit_password" VALUE="Y" \
246 <% $part_svc->restrict_edit_password ? 'CHECKED' : '' %>>
250 % # special case: services with attached routers (false laziness...)
251 % if ( $svcdb eq 'svc_acct'
252 % or $svcdb eq 'svc_broadband'
253 % or $svcdb eq 'svc_dsl'
254 % or $svcdb eq 'svc_circuit' ) {
255 % push @fields, 'has_router';
257 <TD COLSPAN=3 ALIGN="right">
258 <% emt('This service has an attached router') %>
261 <INPUT TYPE="checkbox" NAME="has_router" VALUE="Y" \
262 <% $part_svc->has_router ? 'CHECKED' : '' %>>
267 <& /elements/progress-init.html,
269 [ # form fields to send
271 # qw(svc svcpart classnum selfservice_access disabled preserve exportnum),
274 'process/part_svc.cgi', # target
275 $p.'browse/part_svc.cgi', # redirect landing
278 % $svcpart = '' if $opt{clone};
282 VALUE="<% emt($svcpart ? 'Apply changes' : 'Add service') %>"
283 onclick="fixup_submit('<%$svcdb%>')"
290 my $conf = FS::Conf->new;
292 my $part_svc = $opt{'part_svc'} || FS::part_svc->new;
294 # see if there are communigate exports configured
295 if ( exists $communigate_fields{$svcdb} ) {
296 $communigate = FS::part_export->count("exporttype like 'communigate%'");
299 my $svcpart = $opt{'clone'} || $part_svc->svcpart;
302 if ( defined( dbdef->table($svcdb) ) ) { # when is it ever not defined?
305 and ( $communigate || ! $communigate_fields{$svcdb}->{$_} )
306 and ( !FS::part_svc->svc_table_fields($svcdb)->{$_}->{disable_part_svc_column}
307 || $part_svc->part_svc_column($_)->columnflag )
310 if ( $svcdb eq 'svc_acct'
311 or ( $svcdb eq 'svc_broadband' and $conf->exists('svc_broadband-radius') )
314 push @fields, 'usergroup';
317 my @defs = map { FS::part_svc->svc_table_fields($svcdb)->{$_} } @fields;
318 my $manual_require = FS::part_svc->svc_table_info($svcdb)->{'manual_require'};