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 <& /elements/select-table.html,
137 'id' => $name.'_select',
138 'table' => $def->{'select_table'},
139 'name_col' => $def->{'select_label'},
140 'value_col' => $def->{'select_key'},
141 'order_by' => dbdef->table($def->{'select_table'})->primary_key,
142 'multiple' => $def->{'multiple'},
143 'disable_empty' => $def->{'select_allow_empty'} ? undef : 1,
144 'empty_label' => $def->{'select_allow_empty'} ? ' ' : undef,
145 'curr_value' => $value,
146 # these can be switched between multiple and singular,
147 # so put the complete curr_value in an attribute
148 'element_etc' => 'default="'.encode_entities($value).'"',
151 % my (@options, %labels);
152 % if ( $def->{'select_list'} ) {
153 % @options = @{ $def->{'select_list'} };
154 % @labels{@options} = @options;
155 % } elsif ( $def->{'select_hash'} ) {
156 % if ( ref($def->{'select_hash'}) eq 'ARRAY' ) {
157 % tie my %hash, 'Tie::IxHash', @{ $def->{'select_hash'} };
158 % $def->{'select_hash'} = \%hash;
160 % @options = keys( %{ $def->{'select_hash'} } );
161 % %labels = %{ $def->{'select_hash'} };
163 <& /elements/select.html,
165 'id' => $name.'_select',
166 'options' => \@options,
167 'labels' => \%labels,
168 'multiple' => $def->{'multiple'},
169 'curr_value' => $value,
172 % } elsif ( $def->{'type'} =~ /^select-(.*?)(.html)?$/ && $1 ne 'hardware' ) {
173 <& "/elements/select-$1.html",
175 'id' => $name.'_select',
176 'multiple' => $def->{'multiple'},
177 'curr_value' => $value,
179 % } elsif ( $def->{'type'} eq 'communigate_pro-accessmodes' ) {
180 <& /elements/communigate_pro-accessmodes.html,
181 'element_name_prefix' => $name.'_',
182 'curr_value' => $value,
184 % } elsif ( $def->{'type'} eq 'textarea' ) {
186 <TEXTAREA NAME="<%$name%>"><% $value |h %></TEXTAREA>
187 % } elsif ( $def->{'type'} eq 'disabled' ) {
188 <INPUT TYPE="hidden" NAME="<%$name%>" VALUE="">
190 % # the normal case: a text input, and a _select which is an inventory
191 % # or hardware class
196 % my $mode = 'inventory';
198 % if ( $def->{'type'} eq 'select-hardware' ) {
199 % $mode = 'hardware';
202 <& /elements/select-table.html,
203 'field' => $name.'_classnum',
204 'id' => $name.'_select',
205 'table' => $mode.'_class',
206 'name_col' => 'classname',
207 'curr_value' => $value,
208 'empty_label' => "Select $mode class",
209 'multiple' => $multiple,
214 % if ($manual_require &&
215 % (!$def->{'type'} || !(grep {$_ eq $def->{'type'}} ('checkbox','disabled')))
217 <INPUT ID="<% $name.'_required' %>" TYPE="checkbox" NAME="<% $svcdb %>__<% $field %>_required" VALUE="Y"
218 <% ($part_svc_column->required || $def->{'required'}) ? 'CHECKED' : '' %>
219 <% $def->{'required'} ? 'DISABLED' : '' %>
224 <TR CLASS="row<%$i%>">
225 <TD COLSPAN=3 CLASS="def_info">
226 % if ( $def->{def_info} ) {
227 (<% $def->{def_info} %>)
232 % } # foreach my $field
234 % # special case: svc_acct password edit ACL
235 % if ( $svcdb eq 'svc_acct' ) {
236 % push @fields, 'restrict_edit_password';
238 <TD COLSPAN=3 ALIGN="right">
239 <% emt('Require "Provision" access right to edit password') %>
242 <INPUT TYPE="checkbox" NAME="restrict_edit_password" VALUE="Y" \
243 <% $part_svc->restrict_edit_password ? 'CHECKED' : '' %>>
247 % # special case: services with attached routers (false laziness...)
248 % if ( $svcdb eq 'svc_acct'
249 % or $svcdb eq 'svc_broadband'
250 % or $svcdb eq 'svc_dsl'
251 % or $svcdb eq 'svc_circuit' ) {
252 % push @fields, 'has_router';
254 <TD COLSPAN=3 ALIGN="right">
255 <% emt('This service has an attached router') %>
258 <INPUT TYPE="checkbox" NAME="has_router" VALUE="Y" \
259 <% $part_svc->has_router ? 'CHECKED' : '' %>>
264 <& /elements/progress-init.html,
266 [ # form fields to send
267 qw(svc svcpart classnum selfservice_access disabled preserve exportnum),
270 'process/part_svc.cgi', # target
271 $p.'browse/part_svc.cgi', # redirect landing
274 % $svcpart = '' if $opt{clone};
278 VALUE="<% emt($svcpart ? 'Apply changes' : 'Add service') %>"
279 onclick="fixup_submit('<%$svcdb%>')"
286 my $conf = FS::Conf->new;
288 my $part_svc = $opt{'part_svc'} || FS::part_svc->new;
290 # see if there are communigate exports configured
291 if ( exists $communigate_fields{$svcdb} ) {
292 $communigate = FS::part_export->count("exporttype like 'communigate%'");
295 my $svcpart = $opt{'clone'} || $part_svc->svcpart;
298 if ( defined( dbdef->table($svcdb) ) ) { # when is it ever not defined?
301 and ( $communigate || ! $communigate_fields{$svcdb}->{$_} )
302 and ( !FS::part_svc->svc_table_fields($svcdb)->{$_}->{disable_part_svc_column}
303 || $part_svc->part_svc_column($_)->columnflag )
306 if ( $svcdb eq 'svc_acct'
307 or ( $svcdb eq 'svc_broadband' and $conf->exists('svc_broadband-radius') )
310 push @fields, 'usergroup';
313 my @defs = map { FS::part_svc->svc_table_fields($svcdb)->{$_} } @fields;
314 my $manual_require = FS::part_svc->svc_table_info($svcdb)->{'manual_require'};