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 <& /elements/select-table.html,
138 'id' => $name.'_select',
139 'table' => $def->{'select_table'},
140 'name_col' => $def->{'select_label'},
141 'value_col' => $def->{'select_key'},
142 'order_by' => dbdef->table($def->{'select_table'})->primary_key,
143 'multiple' => $def->{'multiple'},
144 'disable_empty' => $def->{'select_allow_empty'} ? undef : 1,
145 'empty_label' => $def->{'select_allow_empty'} ? ' ' : undef,
146 'curr_value' => $value,
147 # these can be switched between multiple and singular,
148 # so put the complete curr_value in an attribute
149 'element_etc' => 'default="'.encode_entities($value).'"',
152 % my (@options, %labels);
153 % if ( $def->{'select_list'} ) {
154 % @options = @{ $def->{'select_list'} };
155 % @labels{@options} = @options;
156 % } elsif ( $def->{'select_hash'} ) {
157 % if ( ref($def->{'select_hash'}) eq 'ARRAY' ) {
158 % tie my %hash, 'Tie::IxHash', @{ $def->{'select_hash'} };
159 % $def->{'select_hash'} = \%hash;
161 % @options = keys( %{ $def->{'select_hash'} } );
162 % %labels = %{ $def->{'select_hash'} };
164 <& /elements/select.html,
166 'id' => $name.'_select',
167 'options' => \@options,
168 'labels' => \%labels,
169 'multiple' => $def->{'multiple'},
170 'curr_value' => $value,
173 % } elsif ( $def->{'type'} =~ /^select-(.*?)(.html)?$/ && $1 ne 'hardware' ) {
174 <& "/elements/select-$1.html",
176 'id' => $name.'_select',
177 'multiple' => $def->{'multiple'},
178 'curr_value' => $value,
180 % } elsif ( $def->{'type'} eq 'communigate_pro-accessmodes' ) {
181 <& /elements/communigate_pro-accessmodes.html,
182 'element_name_prefix' => $name.'_',
183 'curr_value' => $value,
185 % } elsif ( $def->{'type'} eq 'textarea' ) {
187 <TEXTAREA NAME="<%$name%>"><% $value |h %></TEXTAREA>
188 % } elsif ( $def->{'type'} eq 'disabled' ) {
189 <INPUT TYPE="hidden" NAME="<%$name%>" VALUE="">
191 % # the normal case: a text input, and a _select which is an inventory
192 % # or hardware class
197 % my $mode = 'inventory';
199 % if ( $def->{'type'} eq 'select-hardware' ) {
200 % $mode = 'hardware';
203 <& /elements/select-table.html,
204 'field' => $name.'_classnum',
205 'id' => $name.'_select',
206 'table' => $mode.'_class',
207 'name_col' => 'classname',
208 'curr_value' => $value,
209 'empty_label' => "Select $mode class",
210 'multiple' => $multiple,
215 % if ($manual_require &&
216 % (!$def->{'type'} || !(grep {$_ eq $def->{'type'}} ('checkbox','disabled')))
218 <INPUT ID="<% $name.'_required' %>" TYPE="checkbox" NAME="<% $svcdb %>__<% $field %>_required" VALUE="Y"
219 <% ($part_svc_column->required || $def->{'required'}) ? 'CHECKED' : '' %>
220 <% $def->{'required'} ? 'DISABLED' : '' %>
225 <TR CLASS="row<%$i%>">
226 <TD COLSPAN=3 CLASS="def_info">
227 % if ( $def->{def_info} ) {
228 (<% $def->{def_info} %>)
233 % } # foreach my $field
235 % # special case: svc_acct password edit ACL
236 % if ( $svcdb eq 'svc_acct' ) {
237 % push @fields, 'restrict_edit_password';
239 <TD COLSPAN=3 ALIGN="right">
240 <% emt('Require "Provision" access right to edit password') %>
243 <INPUT TYPE="checkbox" NAME="restrict_edit_password" VALUE="Y" \
244 <% $part_svc->restrict_edit_password ? 'CHECKED' : '' %>>
248 % # special case: services with attached routers (false laziness...)
249 % if ( $svcdb eq 'svc_acct'
250 % or $svcdb eq 'svc_broadband'
251 % or $svcdb eq 'svc_dsl'
252 % or $svcdb eq 'svc_circuit' ) {
253 % push @fields, 'has_router';
255 <TD COLSPAN=3 ALIGN="right">
256 <% emt('This service has an attached router') %>
259 <INPUT TYPE="checkbox" NAME="has_router" VALUE="Y" \
260 <% $part_svc->has_router ? 'CHECKED' : '' %>>
265 <& /elements/progress-init.html,
267 [ # form fields to send
268 qw(svc svcpart classnum selfservice_access disabled preserve exportnum),
271 'process/part_svc.cgi', # target
272 $p.'browse/part_svc.cgi', # redirect landing
275 % $svcpart = '' if $opt{clone};
279 VALUE="<% emt($svcpart ? 'Apply changes' : 'Add service') %>"
280 onclick="fixup_submit('<%$svcdb%>')"
287 my $conf = FS::Conf->new;
289 my $part_svc = $opt{'part_svc'} || FS::part_svc->new;
291 # see if there are communigate exports configured
292 if ( exists $communigate_fields{$svcdb} ) {
293 $communigate = FS::part_export->count("exporttype like 'communigate%'");
296 my $svcpart = $opt{'clone'} || $part_svc->svcpart;
299 if ( defined( dbdef->table($svcdb) ) ) { # when is it ever not defined?
302 and ( $communigate || ! $communigate_fields{$svcdb}->{$_} )
303 and ( !FS::part_svc->svc_table_fields($svcdb)->{$_}->{disable_part_svc_column}
304 || $part_svc->part_svc_column($_)->columnflag )
307 if ( $svcdb eq 'svc_acct'
308 or ( $svcdb eq 'svc_broadband' and $conf->exists('svc_broadband-radius') )
311 push @fields, 'usergroup';
314 my @defs = map { FS::part_svc->svc_table_fields($svcdb)->{$_} } @fields;
315 my $manual_require = FS::part_svc->svc_table_info($svcdb)->{'manual_require'};