1 <& /elements/header.html, "$action Service Definition",
2 menubar('View all service definitions' => "${p}browse/part_svc.cgi"),
3 #" onLoad=\"visualize()\""
6 <& /elements/init_overlib.html &>
12 <FONT CLASS="fsinnerbox-title">Service Part #<% $part_svc->svcpart ? $part_svc->svcpart : "(NEW)" %></FONT>
13 <TABLE CLASS="fsinnerbox">
15 <TD ALIGN="right">Service</TD>
16 <TD><INPUT TYPE="text" NAME="svc" VALUE="<% $hashref->{svc} %>"></TD>
19 <& /elements/tr-select-part_svc_class.html, curr_value=>$hashref->{classnum} &>
22 <TD ALIGN="right">Self-service access</TD>
24 <SELECT NAME="selfservice_access">
25 % tie my %selfservice_access, 'Tie::IxHash', #false laziness w/browse/part_svc
27 % 'hidden' => 'Hidden',
28 % 'readonly' => 'Read-only',
30 % for (keys %selfservice_access) {
31 <OPTION VALUE="<% $_ %>"
32 <% $_ eq $hashref->{'selfservice_access'} ? 'SELECTED' : '' %>
33 ><% $selfservice_access{$_} %>
41 <TD ALIGN="right">Disable new orders</TD>
42 <TD><INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>></TD>
46 <TD ALIGN="right">Preserve this service on package cancellation</TD>
47 <TD><INPUT TYPE="checkbox" NAME="preserve" VALUE="Y"<% $hashref->{'preserve'} eq 'Y' ? ' CHECKED' : '' %>> </TD>
52 <INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $hashref->{svcpart} %>">
57 % #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm
58 % # and generalize the subs
59 % # condition sub is tested to see whether to disable display of this choice
60 % # params: ( $def, $layer, $field ) (see SUB below)
62 % $_[0]->{disable_inventory}
63 % || $_[0]->{'type'} ne 'text'
65 % tie my %flag, 'Tie::IxHash',
66 % '' => { 'desc' => 'No default', },
67 % 'D' => { 'desc' => 'Default',
69 % sub { $_[0]->{disable_default} },
71 % 'F' => { 'desc' => 'Fixed (unchangeable)',
73 % sub { $_[0]->{disable_fixed} },
75 % 'S' => { 'desc' => 'Selectable Choice',
77 % sub { !ref($_[0]) || $_[0]->{disable_select} },
79 % 'M' => { 'desc' => 'Manual selection from inventory',
80 % 'condition' => $inv_sub,
82 % 'A' => { 'desc' => 'Automatically fill in from inventory',
83 % 'condition' => $inv_sub,
85 % 'H' => { 'desc' => 'Select from hardware class',
86 % 'condition' => sub { $_[0]->{type} ne 'select-hardware' },
88 % 'X' => { 'desc' => 'Excluded',
90 % sub { ! $vfields{$_[1]}->{$_[2]} },
95 % my @dbs = $hashref->{svcdb}
96 % ? ( $hashref->{svcdb} )
97 % : FS::part_svc->svc_tables();
100 % unless ( $hashref->{svcpart} ) {
102 % include('/elements/popup_link.html',
103 % 'action' => $p.'docs/part_svc-table.html',
105 % 'actionlabel' => 'Service table help',
111 % tie my %svcdb, 'Tie::IxHash', map { $_=>$_ } grep dbdef->table($_), @dbs;
112 % my $widget = new HTML::Widgets::SelectLayers(
113 % #'selected_layer' => $p_svcdb,
114 % 'selected_layer' => $hashref->{svcdb} || 'svc_acct',
115 % 'options' => \%svcdb,
116 % 'form_name' => 'dummy',
117 % #'form_action' => 'process/part_svc.cgi',
118 % 'form_action' => 'part_svc.cgi', #self
119 % 'form_elements' => [qw( svc svcpart classnum selfservice_access
122 % 'html_between' => $help,
123 % 'layer_callback' => sub {
126 % my $html = qq!<INPUT TYPE="hidden" NAME="svcdb" VALUE="$layer">!;
128 % #$html .= $svcdb_info;
132 % my $communigate = 0;
134 % map { qsearch( 'part_export', {exporttype => $_ } ) }
135 % keys %{FS::part_export::export_info($layer)};
136 % $html .= '<BR><BR>'. include('/elements/table.html') .
137 % "<TR><TH COLSPAN=$columns>Exports</TH></TR><TR>";
138 % foreach my $part_export ( @part_export ) {
139 % $communigate++ if $part_export->exporttype =~ /^communigate/;
140 % $html .= '<TD><INPUT TYPE="checkbox"'.
141 % ' NAME="exportnum'. $part_export->exportnum. '" VALUE="1" ';
143 % if ( $clone || $part_svc->svcpart ) #null svcpart search causing error
144 % && qsearchs( 'export_svc', {
145 % exportnum => $part_export->exportnum,
146 % svcpart => $clone || $part_svc->svcpart });
147 % $html .= '>'. $part_export->label_html. '</TD>';
149 % $html .= '</TR><TR>' unless $count % $columns;
151 % $html .= '</TR></TABLE><BR><BR>'. $mod_info;
153 % $html .= include('/elements/table-grid.html', 'cellpadding' => 4 ).
155 % '<TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>'.
156 % '<TH CLASS="grid" BGCOLOR="#cccccc">Label</TH>'.
157 % '<TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>'.
160 % my $bgcolor1 = '#eeeeee';
161 % my $bgcolor2 = '#ffffff';
166 % if ( defined( dbdef->table($layer) ) ) {
169 % && ( $communigate || !$communigate_fields{$layer}->{$_} )
170 % && ( !FS::part_svc->svc_table_fields($layer)
171 % ->{$_}->{disable_part_svc_column}
172 % || $part_svc->part_svc_column($_)->columnflag
176 % push @fields, 'usergroup'
177 % if $layer eq 'svc_acct'
178 % or ( $layer eq 'svc_broadband' and
179 % $conf->exists('svc_broadband-radius') ); # double kludge
180 % # (but we do want to check the config, right?)
181 % $part_svc->svcpart($clone) if $clone; #haha, undone below
184 % foreach my $field (@fields) {
186 % #a few lines of false laziness w/browse/part_svc.cgi
187 % my $def = FS::part_svc->svc_table_fields($layer)->{$field};
188 % my $def_info = $def->{'def_info'};
189 % my $formatter = $def->{'format'} || sub { shift };
191 % my $part_svc_column = $part_svc->part_svc_column($field);
192 % my $label = $part_svc_column->columnlabel || $def->{'label'};
193 % my $value = &$formatter($part_svc_column->columnvalue);
194 % my $flag = $part_svc_column->columnflag;
196 % if ( $bgcolor eq $bgcolor1 ) {
197 % $bgcolor = $bgcolor2;
199 % $bgcolor = $bgcolor1;
202 % $html .= qq!<TR><TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">!.
203 % ( $def->{'label'} || $field ).
206 % $html .= qq!<TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor"><INPUT NAME="${layer}__${field}_label" VALUE="!. encode_entities($label). '" STYLE="text-align:right"></TD>';
208 % $flag = '' if $def->{type} eq 'disabled';
210 % $html .= qq!<TD CLASS="grid" BGCOLOR="$bgcolor">!;
212 % if ( $def->{type} eq 'disabled' ) {
214 % $html .= 'No default';
218 % $html .= qq!<SELECT NAME="${layer}__${field}_flag"!.
219 % qq! onChange="${layer}__${field}_flag_changed(this)">!;
221 % foreach my $f ( keys %flag ) {
223 % # need to template-ize more httemplate/edit/svc_* first
224 % next if $f eq 'M' and $layer !~ /^svc_(broadband|external|phone|dish)$/;
226 % #here is where the SUB from above is called, to skip some choices
227 % next if $flag{$f}->{condition}
228 % && &{ $flag{$f}->{condition} }( $def, $layer, $field );
230 % $html .= qq!<OPTION VALUE="$f"!.
231 % ' SELECTED'x($flag eq $f ).
232 % '>'. $flag{$f}->{desc};
236 % $html .= '</SELECT>';
238 % $html .= join("\n",
240 % " function ${layer}__${field}_flag_changed(what) {",
241 % ' var f = what.options[what.selectedIndex].value;',
242 % ' if ( f == "" || f == "X" ) { //disable',
243 % " what.form.${layer}__${field}.disabled = true;".
244 % " what.form.${layer}__${field}.style.backgroundColor = '#dddddd';".
245 % " if ( what.form.${layer}__${field}_classnum ) {".
246 % " what.form.${layer}__${field}_classnum.disabled = true;".
247 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#dddddd';".
249 % ' } else if ( f == "D" || f == "F" || f =="S" ) { //enable, text box',
250 % " what.form.${layer}__${field}.disabled = false;".
251 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
252 % " if ( f == 'S' || '${field}' == 'usergroup' ) {". # kludge
253 % " what.form.${layer}__${field}.multiple = true;".
255 % " what.form.${layer}__${field}.multiple = false;".
257 % " what.form.${layer}__${field}.style.display = '';".
258 % " if ( what.form.${layer}__${field}_classnum ) {".
259 % " what.form.${layer}__${field}_classnum.disabled = false;".
260 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
261 % " what.form.${layer}__${field}_classnum.style.display = 'none';".
263 % ' } else if ( f == "M" || f == "A" || f == "H" ) { '.
264 % '//enable, inventory',
265 % " what.form.${layer}__${field}.disabled = false;".
266 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
267 % " what.form.${layer}__${field}.style.display = 'none';".
268 % " if ( what.form.${layer}__${field}_classnum ) {".
269 % " what.form.${layer}__${field}_classnum.disabled = false;".
270 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
271 % " what.form.${layer}__${field}_classnum.style.display = '';".
280 % $html .= qq!</TD><TD CLASS="grid" BGCOLOR="$bgcolor">!;
282 % my $disabled = $flag ? ''
283 % : 'DISABLED STYLE="background-color: #dddddd"';
284 % my $nodisplay = ' STYLE="display:none"';
286 % if ( !$def->{type} || $def->{type} eq 'text' ) {
288 % my $is_inv = ( $flag =~ /^[MA]$/ );
291 % qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value" !.
293 % ( $is_inv ? $nodisplay : $disabled ).
296 % $html .= include('/elements/select-table.html',
297 % 'element_name' => "${layer}__${field}_classnum",
298 % 'id' => "${layer}__${field}_classnum",
299 % 'element_etc' => ( $is_inv
303 % 'table' => 'inventory_class',
304 % 'name_col' => 'classname',
306 % 'empty_label' => 'Select inventory class',
309 % } elsif ( $def->{type} eq 'checkbox' ) {
311 % $html .= include('/elements/checkbox.html',
312 % 'field' => $layer.'__'.$field,
313 % 'curr_value' => $value,
317 % } elsif ( $def->{type} eq 'select' ) {
319 % $html .= qq!<SELECT NAME="${layer}__${field}" $disabled!;
320 % $html .= ' MULTIPLE' if $flag eq 'S';
322 % $html .= '<OPTION> </OPTION>' unless $value;
323 % if ( $def->{select_table} ) {
324 % foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
325 % my $rvalue = $record->getfield($def->{select_key});
326 % my $select_label = $def->{select_label};
327 % $html .= qq!<OPTION VALUE="$rvalue"!.
328 % (grep(/^$rvalue$/, split(',',$value)) ? ' SELECTED>' : '>' ).
329 % $record->$select_label(). '</OPTION>';
331 % } elsif ( $def->{select_list} ) {
332 % foreach my $item ( @{$def->{select_list}} ) {
333 % $html .= qq!<OPTION VALUE="$item"!.
334 % (grep(/^$item$/, split(',',$value)) ? ' SELECTED>' : '>' ).
335 % $item. '</OPTION>';
337 % } elsif ( $def->{select_hash} ) {
338 % if ( ref($def->{select_hash}) eq 'ARRAY' ) {
339 % tie my %hash, 'Tie::IxHash', @{ $def->{select_hash} };
340 % $def->{select_hash} = \%hash;
342 % foreach my $key ( keys %{$def->{select_hash}} ) {
343 % $html .= qq!<OPTION VALUE="$key"!.
344 % (grep(/^$key$/, split(',',$value)) ? ' SELECTED>' : '>' ).
345 % $def->{select_hash}{$key}. '</OPTION>';
348 % $html .= '</SELECT>';
350 % } elsif ( $def->{type} eq 'textarea' ) {
353 % qq!<TEXTAREA NAME="${layer}__${field}">!. encode_entities($value).
356 % } elsif ( $def->{type} =~ /select-(.*?).html/ ) {
358 % $html .= include("/elements/".$def->{type},
359 % 'curr_value' => $value,
360 % 'element_name' => "${layer}__${field}",
361 % 'element_etc' => $disabled,
362 % 'multiple' => ($def->{multiple} ||
364 % # allow the table def to force 'multiple'
367 % } elsif ( $def->{type} eq 'communigate_pro-accessmodes' ) {
369 % $html .= include('/elements/communigate_pro-accessmodes.html',
370 % 'element_name_prefix' => "${layer}__${field}_",
371 % 'curr_value' => $value,
372 % #doesn't work#'element_etc' => $disabled,
375 % } elsif ( $def->{type} eq 'select-hardware' ) {
377 % $html .= qq!<INPUT TYPE="text" NAME="${layer}__${field}" $disabled>!;
378 % $html .= include('/elements/select-hardware_class.html',
379 % 'curr_value' => $value,
380 % 'element_name' => "${layer}__${field}_classnum",
381 % 'id' => "${layer}__${field}_classnum",
382 % 'element_etc' => $flag ne 'H' && $nodisplay,
383 % 'empty_label' => 'Select hardware class',
386 % } elsif ( $def->{type} eq 'disabled' ) {
389 % qq!<INPUT TYPE="hidden" NAME="${layer}__${field}" VALUE="">!;
393 % $html .= '<font color="#ff0000">unknown type '. $def->{type};
397 % $html .= "</TD></TR>\n";
399 % $def_info = "($def_info)" if $def_info;
402 % qq! <TD COLSPAN=2 BGCOLOR="$bgcolor" ALIGN="center" !.
403 % qq! STYLE="padding:0; border-top: none">!.
404 % qq! <FONT SIZE="-1"><I>$def_info</I></FONT>!.
408 % } #foreach my $field (@fields) {
410 % $part_svc->svcpart('') if $clone; #undone
411 % $html .= "</TABLE>";
413 % $html .= include('/elements/progress-init.html',
415 % [ qw(svc svcpart classnum selfservice_access
419 % 'process/part_svc.cgi',
420 % $p.'browse/part_svc.cgi',
423 % $html .= '<BR><INPUT NAME="submit" TYPE="button" VALUE="'.
424 % ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '" '.
425 % ' onClick="document.'. "$layer.submit.disabled=true; ".
426 % "fixup(document.$layer); $layer". 'process();">';
428 % #$html .= '<BR><INPUT TYPE="submit" VALUE="'.
429 % # ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '">';
437 Table <% $widget->html %>
439 <% include('/elements/footer.html') %>
444 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
446 my $conf = FS::Conf->new;
449 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {#clone
450 #$cgi->param('clone') =~ /^(\d+)$/ or die "malformed query: $query";
451 $part_svc = qsearchs('part_svc', { 'svcpart'=>$1 } )
452 or die "unknown svcpart: $1";
453 $clone = $part_svc->svcpart;
454 $part_svc->svcpart('');
455 } elsif ( $cgi->keywords ) { #edit
456 my($query) = $cgi->keywords;
457 $query =~ /^(\d+)$/ or die "malformed query: $query";
458 $part_svc=qsearchs('part_svc', { 'svcpart'=>$1 } )
459 or die "unknown svcpart: $1";
461 $part_svc = new FS::part_svc {};
464 my $action = $part_svc->svcpart ? 'Edit' : 'Add';
465 my $hashref = $part_svc->hashref;
466 # my $p_svcdb = $part_svc->svcdb || 'svc_acct';
468 my %communigate_fields = (
469 'svc_acct' => { map { $_=>1 }
470 qw( file_quota file_maxnum file_maxsize
471 password_selfchange password_recover
473 grep /^cgp_/, fields('svc_acct')
475 'svc_domain' => { map { $_=>1 }
476 qw( max_accounts trailer parent_svcnum ),
477 grep /^(cgp|acct_def)_/, fields('svc_domain')
479 #'svc_forward' => { map { $_=>1 } qw( ) },
480 #'svc_mailinglist' => { map { $_=>1 } qw( ) },
481 #'svc_cert' => { map { $_=>1 } qw( ) },
485 For the selected table, you can give fields default or fixed (unchangable)
486 values, or select an inventory class to manually or automatically fill in