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>
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' => 1,
144 'curr_value' => $value,
145 # these can be switched between multiple and singular,
146 # so put the complete curr_value in an attribute
147 'element_etc' => 'default="'.encode_entities($value).'"',
150 % my (@options, %labels);
151 % if ( $def->{'select_list'} ) {
152 % @options = @{ $def->{'select_list'} };
153 % @labels{@options} = @options;
154 % } elsif ( $def->{'select_hash'} ) {
155 % if ( ref($def->{'select_hash'}) eq 'ARRAY' ) {
156 % tie my %hash, 'Tie::IxHash', @{ $def->{'select_hash'} };
157 % $def->{'select_hash'} = \%hash;
159 % @options = keys( %{ $def->{'select_hash'} } );
160 % %labels = %{ $def->{'select_hash'} };
162 <& /elements/select.html,
164 'id' => $name.'_select',
165 'options' => \@options,
166 'labels' => \%labels,
167 'multiple' => $def->{'multiple'},
168 'curr_value' => $value,
171 % } elsif ( $def->{'type'} =~ /^select-(.*?)(.html)?$/ && $1 ne 'hardware' ) {
172 <& "/elements/select-$1.html",
174 'id' => $name.'_select',
175 'multiple' => $def->{'multiple'},
176 'curr_value' => $value,
178 % } elsif ( $def->{'type'} eq 'communigate_pro-accessmodes' ) {
179 <& /elements/communigate_pro-accessmodes.html,
180 'element_name_prefix' => $name.'_',
181 'curr_value' => $value,
183 % } elsif ( $def->{'type'} eq 'textarea' ) {
185 <TEXTAREA NAME="<%$name%>"><% $value |h %></TEXTAREA>
186 % } elsif ( $def->{'type'} eq 'disabled' ) {
187 <INPUT TYPE="hidden" NAME="<%$name%>" VALUE="">
189 % # the normal case: a text input, and a _select which is an inventory
190 % # or hardware class
195 % my $mode = 'inventory';
197 % if ( $def->{'type'} eq 'select-hardware' ) {
198 % $mode = 'hardware';
201 <& /elements/select-table.html,
202 'field' => $name.'_classnum',
203 'id' => $name.'_select',
204 'table' => $mode.'_class',
205 'name_col' => 'classname',
206 'curr_value' => $value,
207 'empty_label' => "Select $mode class",
208 'multiple' => $multiple,
213 <TR CLASS="row<%$i%>">
214 <TD COLSPAN=2 CLASS="def_info">
215 % if ( $def->{def_info} ) {
216 (<% $def->{def_info} %>)
221 % } # foreach my $field
223 % # special case: svc_acct password edit ACL
224 % if ( $svcdb eq 'svc_acct' ) {
225 % push @fields, 'restrict_edit_password';
227 <TD COLSPAN=3 ALIGN="right">
228 <% emt('Require "Provision" access right to edit password') %>
231 <INPUT TYPE="checkbox" NAME="restrict_edit_password" VALUE="Y" \
232 <% $part_svc->restrict_edit_password ? 'CHECKED' : '' %>>
236 % # special case: services with attached routers (false laziness...)
237 % if ( $svcdb eq 'svc_acct'
238 % or $svcdb eq 'svc_broadband'
239 % or $svcdb eq 'svc_dsl'
240 % or $svcdb eq 'svc_circuit' ) {
241 % push @fields, 'has_router';
243 <TD COLSPAN=3 ALIGN="right">
244 <% emt('This service has an attached router') %>
247 <INPUT TYPE="checkbox" NAME="has_router" VALUE="Y" \
248 <% $part_svc->has_router ? 'CHECKED' : '' %>>
253 <& /elements/progress-init.html,
255 [ # form fields to send
256 qw(svc svcpart classnum selfservice_access disabled preserve exportnum),
259 'process/part_svc.cgi', # target
260 $p.'browse/part_svc.cgi', # redirect landing
263 % $svcpart = '' if $opt{clone};
267 VALUE="<% emt($svcpart ? 'Apply changes' : 'Add service') %>"
268 onclick="fixup_submit('<%$svcdb%>')"
275 my $conf = FS::Conf->new;
277 my $part_svc = $opt{'part_svc'} || FS::part_svc->new;
279 # see if there are communigate exports configured
280 if ( exists $communigate_fields{$svcdb} ) {
281 $communigate = FS::part_export->count("exporttype like 'communigate%'");
284 my $svcpart = $opt{'clone'} || $part_svc->svcpart;
287 if ( defined( dbdef->table($svcdb) ) ) { # when is it ever not defined?
290 and ( $communigate || ! $communigate_fields{$svcdb}->{$_} )
291 and ( !FS::part_svc->svc_table_fields($svcdb)->{$_}->{disable_part_svc_column}
292 || $part_svc->part_svc_column($_)->columnflag )
295 if ( $svcdb eq 'svc_acct'
296 or ( $svcdb eq 'svc_broadband' and $conf->exists('svc_broadband-radius') )
299 push @fields, 'usergroup';
302 my @defs = map { FS::part_svc->svc_table_fields($svcdb)->{$_} } @fields;