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 <& /elements/table.html &>
68 <TR><TH COLSPAN=<% $columns %>>Exports</TH></TR>
71 % foreach my $part_export (@part_export) {
73 <INPUT TYPE="checkbox" \
74 NAME="exportnum<% $part_export->exportnum %>" \
76 <% $has_export_svc{$part_export->exportnum} ? 'CHECKED' : '' %>>
77 <% $part_export->label_html %>
80 % if ( $count % $columns == 0 ) {
87 For the selected table, you can give fields default or fixed (unchangeable)
88 values, or select an inventory class to manually or automatically fill in
90 <& /elements/table-grid.html, cellpadding => 4 &>
92 <TH BGCOLOR="#cccccc">Field</TH>
93 <TH BGCOLOR="#cccccc">Label</TH>
94 <TH BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>
96 % $part_svc->set('svcpart' => $opt{'clone'}) if $opt{'clone'}; # for now
98 % foreach my $field (@fields) {
99 % my $def = shift @defs;
100 % my $part_svc_column = $part_svc->part_svc_column($field);
101 % my $flag = $part_svc_column->columnflag;
102 % my $formatter = $def->{'format'} || sub { shift };
103 % my $value = &{$formatter}($part_svc_column->columnvalue);
104 <TR CLASS="row<%$i%>">
105 <TD ROWSPAN=2 CLASS="grid" ALIGN="right">
106 <% $def->{'label'} || $field %>
108 <TD ROWSPAN=2 CLASS="grid">
109 <INPUT NAME="<% $svcdb %>__<% $field %>_label"
110 STYLE="text-align: right"
111 VALUE="<% $part_svc_column->columnlabel || $def->{'label'} |h %>">
114 <TD ROWSPAN=1 CLASS="grid">
116 % if ( $def->{'type'} eq 'disabled' ) {
120 % my $name = $svcdb.'__'.$field.'_flag';
121 <SELECT NAME="<%$name%>"
124 onchange="flag_changed(this)">
125 % foreach my $f (keys %flag) {
126 % if ( flag_condition($f, $def, $svcdb, $field) ) {
127 <OPTION VALUE="<%$f%>"<% $flag eq $f ? ' SELECTED' : ''%>>
128 <% $flag{$f}->{desc} %>
133 % } # if $def->{'type'} eq 'disabled'
136 % # value entry/selection
137 % my $name = $svcdb.'__'.$field;
138 % # These are all MANDATORY SELECT types. Regardless of the flag value,
139 % # there will never be a text input (either in svc_* or in part_svc) for
141 % if ( $def->{'type'} eq 'checkbox' ) {
142 <& /elements/checkbox.html,
144 'curr_value' => $value,
147 % } elsif ( $def->{'type'} eq 'select' ) {
149 % if ( $def->{'select_table'} ) {
150 <& /elements/select-table.html,
152 'id' => $name.'_select',
153 'table' => $def->{'select_table'},
154 'name_col' => $def->{'select_label'},
155 'value_col' => $def->{'select_key'},
156 'order_by' => dbdef->table($def->{'select_table'})->primary_key,
157 'multiple' => $def->{'multiple'},
158 'disable_empty' => 1,
159 'curr_value' => $value,
160 # these can be switched between multiple and singular,
161 # so put the complete curr_value in an attribute
162 'element_etc' => 'default="'.encode_entities($value).'"',
165 % my (@options, %labels);
166 % if ( $def->{'select_list'} ) {
167 % @options = @{ $def->{'select_list'} };
168 % @labels{@options} = @options;
169 % } elsif ( $def->{'select_hash'} ) {
170 % if ( ref($def->{'select_hash'}) eq 'ARRAY' ) {
171 % tie my %hash, 'Tie::IxHash', @{ $def->{'select_hash'} };
172 % $def->{'select_hash'} = \%hash;
174 % @options = keys( %{ $def->{'select_hash'} } );
175 % %labels = %{ $def->{'select_hash'} };
177 <& /elements/select.html,
179 'id' => $name.'_select',
180 'options' => \@options,
181 'labels' => \%labels,
182 'multiple' => $def->{'multiple'},
183 'curr_value' => $value,
186 % } elsif ( $def->{'type'} =~ /^select-(.*?)(.html)?$/ && $1 ne 'hardware' ) {
187 <& "/elements/select-$1.html",
189 'id' => $name.'_select',
190 'multiple' => $def->{'multiple'},
191 'curr_value' => $value,
193 % } elsif ( $def->{'type'} eq 'communigate_pro-accessmodes' ) {
194 <& /elements/communigate_pro-accessmodes.html,
195 'element_name_prefix' => $name.'_',
196 'curr_value' => $value,
198 % } elsif ( $def->{'type'} eq 'textarea' ) {
200 <TEXTAREA NAME="<%$name%>"><% $value |h %></TEXTAREA>
201 % } elsif ( $def->{'type'} eq 'disabled' ) {
202 <INPUT TYPE="hidden" NAME="<%$name%>" VALUE="">
204 % # the normal case: a text input, and a _select which is an inventory
205 % # or hardware class
210 % my $mode = 'inventory';
212 % if ( $def->{'type'} eq 'select-hardware' ) {
213 % $mode = 'hardware';
216 <& /elements/select-table.html,
217 'field' => $name.'_classnum',
218 'id' => $name.'_select',
219 'table' => $mode.'_class',
220 'name_col' => 'classname',
221 'curr_value' => $value,
222 'empty_label' => "Select $mode class",
223 'multiple' => $multiple,
228 <TR CLASS="row<%$i%>">
229 <TD COLSPAN=2 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' or $svcdb eq 'svc_broadband' or $svcdb eq 'svc_dsl' ) {
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%>')"
288 my $conf = FS::Conf->new;
290 my $part_svc = $opt{'part_svc'} || FS::part_svc->new;
293 my $export_info = FS::part_export::export_info($svcdb);
294 foreach (keys %{ $export_info }) {
295 push @part_export, qsearch('part_export', { exporttype => $_ });
297 $communigate = scalar(grep {$_->exporttype =~ /^communigate/} @part_export);
299 my $svcpart = $opt{'clone'} || $part_svc->svcpart;
302 foreach (qsearch('export_svc', { svcpart => $svcpart })) {
303 $has_export_svc{$_->exportnum} = 1;
308 if ( defined( dbdef->table($svcdb) ) ) { # when is it ever not defined?
311 and ( $communigate || ! $communigate_fields{$svcdb}->{$_} )
312 and ( !FS::part_svc->svc_table_fields($svcdb)->{$_}->{disable_part_svc_column}
313 || $part_svc->part_svc_column($_)->columnflag )
316 if ( $svcdb eq 'svc_acct'
317 or ( $svcdb eq 'svc_broadband' and $conf->exists('svc_broadband-radius') )
320 push @fields, 'usergroup';
323 my @defs = map { FS::part_svc->svc_table_fields($svcdb)->{$_} } @fields;