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,
72 For the selected table, you can give fields default or fixed (unchangeable)
73 values, or select an inventory class to manually or automatically fill in
75 <& /elements/table-grid.html, cellpadding => 4 &>
77 <TH BGCOLOR="#cccccc">Field</TH>
78 <TH BGCOLOR="#cccccc">Label</TH>
79 <TH BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>
80 <TH BGCOLOR="#cccccc"><% $manual_require ? 'Required?' : '' %></TH>
82 % $part_svc->set('svcpart' => $opt{'clone'}) if $opt{'clone'}; # for now
84 % foreach my $field (@fields) {
85 % my $def = shift @defs;
86 % my $part_svc_column = $part_svc->part_svc_column($field);
87 % my $flag = $part_svc_column->columnflag;
88 % my $formatter = $def->{'format'} || sub { shift };
89 % my $value = &{$formatter}($part_svc_column->columnvalue);
90 <TR CLASS="row<%$i%>">
91 <TD ROWSPAN=2 CLASS="grid" ALIGN="right">
92 <% $def->{'label'} || $field %>
94 <TD ROWSPAN=2 CLASS="grid">
95 <INPUT NAME="<% $svcdb %>__<% $field %>_label"
96 STYLE="text-align: right"
97 VALUE="<% $part_svc_column->columnlabel || $def->{'label'} |h %>">
100 <TD ROWSPAN=1 CLASS="grid">
102 % if ( $def->{'type'} eq 'disabled' ) {
106 % my $name = $svcdb.'__'.$field.'_flag';
107 <SELECT NAME="<%$name%>"
110 onchange="flag_changed(this)">
111 % foreach my $f (keys %flag) {
112 % if ( flag_condition($f, $def, $svcdb, $field) ) {
113 <OPTION VALUE="<%$f%>"<% $flag eq $f ? ' SELECTED' : ''%>>
114 <% $flag{$f}->{desc} %>
119 % } # if $def->{'type'} eq 'disabled'
122 % # value entry/selection
123 % my $name = $svcdb.'__'.$field;
124 % # These are all MANDATORY SELECT types. Regardless of the flag value,
125 % # there will never be a text input (either in svc_* or in part_svc) for
127 % if ( $def->{'type'} eq 'checkbox' ) {
128 <& /elements/checkbox.html,
130 'curr_value' => $value,
133 % } elsif ( $def->{'type'} eq 'select' ) {
135 % if ( $def->{'select_table'} ) {
136 % # set the 'select_svc' flag to enable two-step selection of services
137 % my $comp = '/elements/select-table.html';
138 % $comp = '/elements/select-svc.html' if $def->{'select_svc'};
141 'id' => $name.'_select',
142 'table' => $def->{'select_table'},
143 'name_col' => $def->{'select_label'},
144 'value_col' => $def->{'select_key'},
145 'order_by' => dbdef->table($def->{'select_table'})->primary_key,
146 'multiple' => $def->{'multiple'},
147 'disable_empty' => $def->{'select_allow_empty'} ? undef : 1,
148 'empty_label' => $def->{'select_allow_empty'} ? ' ' : undef,
149 'curr_value' => $value,
150 # these can be switched between multiple and singular,
151 # so put the complete curr_value in an attribute
152 'element_etc' => 'default="'.encode_entities($value).'"',
155 % my (@options, %labels);
156 % if ( $def->{'select_list'} ) {
157 % @options = @{ $def->{'select_list'} };
158 % @labels{@options} = @options;
159 % } elsif ( $def->{'select_hash'} ) {
160 % if ( ref($def->{'select_hash'}) eq 'ARRAY' ) {
161 % tie my %hash, 'Tie::IxHash', @{ $def->{'select_hash'} };
162 % $def->{'select_hash'} = \%hash;
164 % @options = keys( %{ $def->{'select_hash'} } );
165 % %labels = %{ $def->{'select_hash'} };
167 <& /elements/select.html,
169 'id' => $name.'_select',
170 'options' => \@options,
171 'labels' => \%labels,
172 'multiple' => $def->{'multiple'},
173 'curr_value' => $value,
176 % } elsif ( $def->{'type'} =~ /^select-(.*?)(.html)?$/ && $1 ne 'hardware' ) {
177 <& "/elements/select-$1.html",
179 'id' => $name.'_select',
180 'multiple' => $def->{'multiple'},
181 'curr_value' => $value,
183 % } elsif ( $def->{'type'} eq 'communigate_pro-accessmodes' ) {
184 <& /elements/communigate_pro-accessmodes.html,
185 'element_name_prefix' => $name.'_',
186 'curr_value' => $value,
188 % } elsif ( $def->{'type'} eq 'textarea' ) {
190 <TEXTAREA NAME="<%$name%>"><% $value |h %></TEXTAREA>
191 % } elsif ( $def->{'type'} eq 'disabled' ) {
192 <INPUT TYPE="hidden" NAME="<%$name%>" VALUE="">
194 % # the normal case: a text input, and a _select which is an inventory
195 % # or hardware class
200 % my $mode = 'inventory';
202 % if ( $def->{'type'} eq 'select-hardware' ) {
203 % $mode = 'hardware';
206 <& /elements/select-table.html,
207 'field' => $name.'_classnum',
208 'id' => $name.'_select',
209 'table' => $mode.'_class',
210 'name_col' => 'classname',
211 'curr_value' => $value,
212 'empty_label' => "Select $mode class",
213 'multiple' => $multiple,
218 % if ($manual_require &&
219 % (!$def->{'type'} || !(grep {$_ eq $def->{'type'}} ('checkbox','disabled')))
221 <INPUT ID="<% $name.'_required' %>" TYPE="checkbox" NAME="<% $svcdb %>__<% $field %>_required" VALUE="Y"
222 <% ($part_svc_column->required || $def->{'required'}) ? 'CHECKED' : '' %>
223 <% $def->{'required'} ? 'DISABLED' : '' %>
228 <TR CLASS="row<%$i%>">
229 <TD COLSPAN=3 CLASS="def_info">
230 % if ( $def->{def_info} ) {
231 (<% $def->{def_info} %>)
236 % } # foreach my $field
238 % # special case: svc_acct password edit ACL
239 % if ( $svcdb eq 'svc_acct' ) {
240 % push @fields, 'restrict_edit_password';
242 <TD COLSPAN=3 ALIGN="right">
243 <% emt('Require "Provision" access right to edit password') %>
246 <INPUT TYPE="checkbox" NAME="restrict_edit_password" VALUE="Y" \
247 <% $part_svc->restrict_edit_password ? 'CHECKED' : '' %>>
251 % # special case: services with attached routers (false laziness...)
252 % if ( $svcdb eq 'svc_acct'
253 % or $svcdb eq 'svc_broadband'
254 % or $svcdb eq 'svc_dsl'
255 % or $svcdb eq 'svc_circuit' ) {
256 % push @fields, 'has_router';
258 <TD COLSPAN=3 ALIGN="right">
259 <% emt('This service has an attached router') %>
262 <INPUT TYPE="checkbox" NAME="has_router" VALUE="Y" \
263 <% $part_svc->has_router ? 'CHECKED' : '' %>>
268 <& /elements/progress-init.html,
270 [ # form fields to send
272 # qw(svc svcpart classnum selfservice_access disabled preserve exportnum),
275 'process/part_svc.cgi', # target
276 $p.'browse/part_svc.cgi', # redirect landing
279 % $svcpart = '' if $opt{clone};
283 VALUE="<% emt($svcpart ? 'Apply changes' : 'Add service') %>"
284 onclick="fixup_submit('<%$svcdb%>')"
291 my $conf = FS::Conf->new;
293 my $part_svc = $opt{'part_svc'} || FS::part_svc->new;
295 # see if there are communigate exports configured
296 if ( exists $communigate_fields{$svcdb} ) {
297 $communigate = FS::part_export->count("exporttype like 'communigate%'");
300 my $svcpart = $opt{'clone'} || $part_svc->svcpart;
303 if ( defined( dbdef->table($svcdb) ) ) { # when is it ever not defined?
306 and ( $communigate || ! $communigate_fields{$svcdb}->{$_} )
307 and ( !FS::part_svc->svc_table_fields($svcdb)->{$_}->{disable_part_svc_column}
308 || $part_svc->part_svc_column($_)->columnflag )
311 if ( $svcdb eq 'svc_acct'
312 or ( $svcdb eq 'svc_broadband' and $conf->exists('svc_broadband-radius') )
315 push @fields, 'usergroup';
318 my @defs = map { FS::part_svc->svc_table_fields($svcdb)->{$_} } @fields;
319 my $manual_require = FS::part_svc->svc_table_info($svcdb)->{'manual_require'};