1 <% include('/elements/header.html', "$action Service Definition",
2 menubar('View all service definitions' => "${p}browse/part_svc.cgi"),
3 #" onLoad=\"visualize()\""
9 Service Part #<% $part_svc->svcpart ? $part_svc->svcpart : "(NEW)" %>
11 Service <INPUT TYPE="text" NAME="svc" VALUE="<% $hashref->{svc} %>"><BR>
14 <SELECT NAME="selfservice_access">
15 % tie my %selfservice_access, 'Tie::IxHash', #false laziness w/browse/part_svc
17 % 'hidden' => 'Hidden',
18 % 'readonly' => 'Read-only',
20 % for (keys %selfservice_access) {
21 <OPTION VALUE="<% $_ %>"
22 <% $_ eq $hashref->{'selfservice_access'} ? 'SELECTED' : '' %>
23 ><% $selfservice_access{$_} %>
27 <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>> Disable new orders<BR>
29 <INPUT TYPE="checkbox" NAME="preserve" VALUE="Y"<% $hashref->{'preserve'} eq 'Y' ? ' CHECKED' : '' %>> Preserve this service on package cancellation<BR>
32 <INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $hashref->{svcpart} %>">
37 % #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm
38 % # and generalize the subs
39 % # condition sub is tested to see whether to disable display of this choice
40 % # params: ( $def, $layer, $field ) (see SUB below)
42 % $_[0]->{disable_inventory}
43 % || $_[0]->{'type'} ne 'text'
45 % tie my %flag, 'Tie::IxHash',
46 % '' => { 'desc' => 'No default', },
47 % 'D' => { 'desc' => 'Default',
49 % sub { $_[0]->{disable_default} },
51 % 'F' => { 'desc' => 'Fixed (unchangeable)',
53 % sub { $_[0]->{disable_fixed} },
55 % 'S' => { 'desc' => 'Selectable Choice',
57 % sub { !ref($_[0]) || $_[0]->{disable_select} },
59 % 'M' => { 'desc' => 'Manual selection from inventory',
60 % 'condition' => $inv_sub,
62 % 'A' => { 'desc' => 'Automatically fill in from inventory',
63 % 'condition' => $inv_sub,
65 % 'H' => { 'desc' => 'Select from hardware class',
66 % 'condition' => sub { $_[0]->{type} ne 'select-hardware' },
68 % 'X' => { 'desc' => 'Excluded',
70 % sub { ! $vfields{$_[1]}->{$_[2]} },
75 % my @dbs = $hashref->{svcdb}
76 % ? ( $hashref->{svcdb} )
77 % : FS::part_svc->svc_tables();
79 % tie my %svcdb, 'Tie::IxHash', map { $_=>$_ } grep dbdef->table($_), @dbs;
80 % my $widget = new HTML::Widgets::SelectLayers(
81 % #'selected_layer' => $p_svcdb,
82 % 'selected_layer' => $hashref->{svcdb} || 'svc_acct',
83 % 'options' => \%svcdb,
84 % 'form_name' => 'dummy',
85 % #'form_action' => 'process/part_svc.cgi',
86 % 'form_action' => 'part_svc.cgi', #self
87 % 'form_text' => [ qw( svc svcpart ) ],
88 % 'form_select' => [ 'selfservice_access' ],
89 % 'form_checkbox' => [ 'disabled', 'preserve' ],
90 % 'layer_callback' => sub {
93 % my $html = qq!<INPUT TYPE="hidden" NAME="svcdb" VALUE="$layer">!;
95 % $html .= $svcdb_info;
99 % my $communigate = 0;
101 % map { qsearch( 'part_export', {exporttype => $_ } ) }
102 % keys %{FS::part_export::export_info($layer)};
103 % $html .= '<BR><BR>'. include('/elements/table.html') .
104 % "<TR><TH COLSPAN=$columns>Exports</TH></TR><TR>";
105 % foreach my $part_export ( @part_export ) {
106 % $communigate++ if $part_export->exporttype =~ /^communigate/;
107 % $html .= '<TD><INPUT TYPE="checkbox"'.
108 % ' NAME="exportnum'. $part_export->exportnum. '" VALUE="1" ';
110 % if ( $clone || $part_svc->svcpart ) #null svcpart search causing error
111 % && qsearchs( 'export_svc', {
112 % exportnum => $part_export->exportnum,
113 % svcpart => $clone || $part_svc->svcpart });
114 % $html .= '>'.$part_export->exportnum. ': ';
115 % $html .= $part_export->exportname . '<DIV ALIGN="right"><FONT SIZE=-1>'
116 % if ( $part_export->exportname );
117 % $html .= $part_export->exporttype. ' to '. $part_export->machine;
118 % $html .= '</FONT></DIV>' if ( $part_export->exportname );
121 % $html .= '</TR><TR>' unless $count % $columns;
123 % $html .= '</TR></TABLE><BR><BR>'. $mod_info;
125 % $html .= include('/elements/table-grid.html', 'cellpadding' => 4 ).
127 % '<TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>'.
128 % '<TH CLASS="grid" BGCOLOR="#cccccc">Label</TH>'.
129 % '<TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>'.
132 % my $bgcolor1 = '#eeeeee';
133 % my $bgcolor2 = '#ffffff';
138 % if ( defined( dbdef->table($layer) ) ) {
141 % && ( $communigate || !$communigate_fields{$layer}->{$_} )
142 % && ( !FS::part_svc->svc_table_fields($layer)
143 % ->{$_}->{disable_part_svc_column}
144 % || $part_svc->part_svc_column($_)->columnflag
148 % push @fields, 'usergroup'
149 % if $layer eq 'svc_acct'
150 % or ( $layer eq 'svc_broadband' and
151 % $conf->exists('svc_broadband-radius') ); # double kludge
152 % # (but we do want to check the config, right?)
153 % $part_svc->svcpart($clone) if $clone; #haha, undone below
156 % foreach my $field (@fields) {
158 % #a few lines of false laziness w/browse/part_svc.cgi
159 % my $def = FS::part_svc->svc_table_fields($layer)->{$field};
160 % my $def_info = $def->{'def_info'};
161 % my $formatter = $def->{'format'} || sub { shift };
163 % my $part_svc_column = $part_svc->part_svc_column($field);
164 % my $label = $part_svc_column->columnlabel || $def->{'label'};
165 % my $value = &$formatter($part_svc_column->columnvalue);
166 % my $flag = $part_svc_column->columnflag;
168 % if ( $bgcolor eq $bgcolor1 ) {
169 % $bgcolor = $bgcolor2;
171 % $bgcolor = $bgcolor1;
174 % $html .= qq!<TR><TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">!.
175 % ( $def->{'label'} || $field ).
178 % $html .= qq!<TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor"><INPUT NAME="${layer}__${field}_label" VALUE="!. encode_entities($label). '" STYLE="text-align:right"></TD>';
180 % $flag = '' if $def->{type} eq 'disabled';
182 % $html .= qq!<TD CLASS="grid" BGCOLOR="$bgcolor">!;
184 % if ( $def->{type} eq 'disabled' ) {
186 % $html .= 'No default';
190 % $html .= qq!<SELECT NAME="${layer}__${field}_flag"!.
191 % qq! onChange="${layer}__${field}_flag_changed(this)">!;
193 % foreach my $f ( keys %flag ) {
195 % # need to template-ize more httemplate/edit/svc_* first
196 % next if $f eq 'M' and $layer !~ /^svc_(broadband|external|phone|dish)$/;
198 % #here is where the SUB from above is called, to skip some choices
199 % next if $flag{$f}->{condition}
200 % && &{ $flag{$f}->{condition} }( $def, $layer, $field );
202 % $html .= qq!<OPTION VALUE="$f"!.
203 % ' SELECTED'x($flag eq $f ).
204 % '>'. $flag{$f}->{desc};
208 % $html .= '</SELECT>';
210 % $html .= join("\n",
212 % " function ${layer}__${field}_flag_changed(what) {",
213 % ' var f = what.options[what.selectedIndex].value;',
214 % ' if ( f == "" || f == "X" ) { //disable',
215 % " what.form.${layer}__${field}.disabled = true;".
216 % " what.form.${layer}__${field}.style.backgroundColor = '#dddddd';".
217 % " if ( what.form.${layer}__${field}_classnum ) {".
218 % " what.form.${layer}__${field}_classnum.disabled = true;".
219 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#dddddd';".
221 % ' } else if ( f == "D" || f == "F" || f =="S" ) { //enable, text box',
222 % " what.form.${layer}__${field}.disabled = false;".
223 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
224 % " if ( f == 'S' || '${field}' == 'usergroup' ) {". # kludge
225 % " what.form.${layer}__${field}.multiple = true;".
227 % " what.form.${layer}__${field}.multiple = false;".
229 % " what.form.${layer}__${field}.style.display = '';".
230 % " if ( what.form.${layer}__${field}_classnum ) {".
231 % " what.form.${layer}__${field}_classnum.disabled = false;".
232 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
233 % " what.form.${layer}__${field}_classnum.style.display = 'none';".
235 % ' } else if ( f == "M" || f == "A" || f == "H" ) { '.
236 % '//enable, inventory',
237 % " what.form.${layer}__${field}.disabled = false;".
238 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
239 % " what.form.${layer}__${field}.style.display = 'none';".
240 % " if ( what.form.${layer}__${field}_classnum ) {".
241 % " what.form.${layer}__${field}_classnum.disabled = false;".
242 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
243 % " what.form.${layer}__${field}_classnum.style.display = '';".
252 % $html .= qq!</TD><TD CLASS="grid" BGCOLOR="$bgcolor">!;
254 % my $disabled = $flag ? ''
255 % : 'DISABLED STYLE="background-color: #dddddd"';
256 % my $nodisplay = ' STYLE="display:none"';
258 % if ( !$def->{type} || $def->{type} eq 'text' ) {
260 % my $is_inv = ( $flag =~ /^[MA]$/ );
263 % qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value" !.
265 % ( $is_inv ? $nodisplay : $disabled ).
268 % $html .= include('/elements/select-table.html',
269 % 'element_name' => "${layer}__${field}_classnum",
270 % 'element_etc' => ( $is_inv
274 % 'table' => 'inventory_class',
275 % 'name_col' => 'classname',
277 % 'empty_label' => 'Select inventory class',
280 % } elsif ( $def->{type} eq 'checkbox' ) {
282 % $html .= include('/elements/checkbox.html',
283 % 'field' => $layer.'__'.$field,
284 % 'curr_value' => $value,
288 % } elsif ( $def->{type} eq 'select' ) {
290 % $html .= qq!<SELECT NAME="${layer}__${field}" $disabled!;
291 % $html .= ' MULTIPLE' if $flag eq 'S';
293 % $html .= '<OPTION> </OPTION>' unless $value;
294 % if ( $def->{select_table} ) {
295 % foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
296 % my $rvalue = $record->getfield($def->{select_key});
297 % my $select_label = $def->{select_label};
298 % $html .= qq!<OPTION VALUE="$rvalue"!.
299 % (grep(/^$rvalue$/, split(',',$value)) ? ' SELECTED>' : '>' ).
300 % $record->$select_label(). '</OPTION>';
302 % } elsif ( $def->{select_list} ) {
303 % foreach my $item ( @{$def->{select_list}} ) {
304 % $html .= qq!<OPTION VALUE="$item"!.
305 % (grep(/^$item$/, split(',',$value)) ? ' SELECTED>' : '>' ).
306 % $item. '</OPTION>';
308 % } elsif ( $def->{select_hash} ) {
309 % if ( ref($def->{select_hash}) eq 'ARRAY' ) {
310 % tie my %hash, 'Tie::IxHash', @{ $def->{select_hash} };
311 % $def->{select_hash} = \%hash;
313 % foreach my $key ( keys %{$def->{select_hash}} ) {
314 % $html .= qq!<OPTION VALUE="$key"!.
315 % (grep(/^$key$/, split(',',$value)) ? ' SELECTED>' : '>' ).
316 % $def->{select_hash}{$key}. '</OPTION>';
319 % $html .= '</SELECT>';
321 % } elsif ( $def->{type} eq 'textarea' ) {
324 % qq!<TEXTAREA NAME="${layer}__${field}">!. encode_entities($value).
327 % } elsif ( $def->{type} =~ /select-(.*?).html/ ) {
329 % $html .= include("/elements/".$def->{type},
330 % 'curr_value' => $value,
331 % 'element_name' => "${layer}__${field}",
332 % 'element_etc' => $disabled,
333 % 'multiple' => ($def->{multiple} ||
335 % # allow the table def to force 'multiple'
338 % } elsif ( $def->{type} eq 'communigate_pro-accessmodes' ) {
340 % $html .= include('/elements/communigate_pro-accessmodes.html',
341 % 'element_name_prefix' => "${layer}__${field}_",
342 % 'curr_value' => $value,
343 % #doesn't work#'element_etc' => $disabled,
346 % } elsif ( $def->{type} eq 'select-hardware' ) {
348 % $html .= qq!<INPUT TYPE="text" NAME="${layer}__${field}" $disabled>!;
349 % $html .= include('/elements/select-hardware_class.html',
350 % 'curr_value' => $value,
351 % 'element_name' => "${layer}__${field}_classnum",
352 % 'element_etc' => $flag ne 'H' && $nodisplay,
353 % 'empty_label' => 'Select hardware class',
356 % } elsif ( $def->{type} eq 'disabled' ) {
359 % qq!<INPUT TYPE="hidden" NAME="${layer}__${field}" VALUE="">!;
363 % $html .= '<font color="#ff0000">unknown type '. $def->{type};
367 % $html .= "</TD></TR>\n";
369 % $def_info = "($def_info)" if $def_info;
372 % qq! <TD COLSPAN=2 BGCOLOR="$bgcolor" ALIGN="center" !.
373 % qq! STYLE="padding:0; border-top: none">!.
374 % qq! <FONT SIZE="-1"><I>$def_info</I></FONT>!.
378 % } #foreach my $field (@fields) {
380 % $part_svc->svcpart('') if $clone; #undone
381 % $html .= "</TABLE>";
383 % $html .= include('/elements/progress-init.html',
385 % [ qw(svc svcpart selfservice_access disabled preserve
388 % 'process/part_svc.cgi',
389 % $p.'browse/part_svc.cgi',
392 % $html .= '<BR><INPUT NAME="submit" TYPE="button" VALUE="'.
393 % ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '" '.
394 % ' onClick="document.'. "$layer.submit.disabled=true; ".
395 % "fixup(document.$layer); $layer". 'process();">';
397 % #$html .= '<BR><INPUT TYPE="submit" VALUE="'.
398 % # ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '">';
407 Table <% $widget->html %>
409 <% include('/elements/footer.html') %>
414 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
416 my $conf = FS::Conf->new;
419 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {#clone
420 #$cgi->param('clone') =~ /^(\d+)$/ or die "malformed query: $query";
421 $part_svc = qsearchs('part_svc', { 'svcpart'=>$1 } )
422 or die "unknown svcpart: $1";
423 $clone = $part_svc->svcpart;
424 $part_svc->svcpart('');
425 } elsif ( $cgi->keywords ) { #edit
426 my($query) = $cgi->keywords;
427 $query =~ /^(\d+)$/ or die "malformed query: $query";
428 $part_svc=qsearchs('part_svc', { 'svcpart'=>$1 } )
429 or die "unknown svcpart: $1";
431 $part_svc = new FS::part_svc {};
434 my $action = $part_svc->svcpart ? 'Edit' : 'Add';
435 my $hashref = $part_svc->hashref;
436 # my $p_svcdb = $part_svc->svcdb || 'svc_acct';
438 my %communigate_fields = (
439 'svc_acct' => { map { $_=>1 }
440 qw( file_quota file_maxnum file_maxsize
441 password_selfchange password_recover
443 grep /^cgp_/, fields('svc_acct')
445 'svc_domain' => { map { $_=>1 }
446 qw( max_accounts trailer parent_svcnum ),
447 grep /^(cgp|acct_def)_/, fields('svc_domain')
449 #'svc_forward' => { map { $_=>1 } qw( ) },
450 #'svc_mailinglist' => { map { $_=>1 } qw( ) },
451 #'svc_cert' => { map { $_=>1 } qw( ) },
457 <TH ALIGN="left">Generic</TH>
458 <TH ALIGN="left">Access</TH>
459 <TH ALIGN="left">Telephony</TH>
460 <!-- <TH>Hosting</TH>
466 <UL STYLE="margin:0">
467 <LI><B>svc_acct</B>: Accounts - anything with a username (mailbox, shell, RADIUS, etc.)
468 <LI><B>svc_hardware</B>: Equipment supplied to customers
469 <LI><B>svc_external</B>: Externally-tracked service
473 <UL STYLE="margin:0">
474 <LI><B>svc_dsl</B>: DSL
475 <LI><B>svc_broadband</B>: Wireless broadband
476 <LI><B>svc_dish</B>: DISH Network
480 <UL STYLE="margin:0">
481 <LI><B>svc_phone</B>: Customer phone number
482 <LI><B>svc_pbx</B>: Customer PBX
490 <TH ALIGN="left">Hosting</TH>
491 <TH ALIGN="left">Colocation</TH>
494 <UL STYLE="margin:0">
495 <LI><B>svc_domain</B>: Domain
496 <LI><B>svc_cert</B>: Certificate
497 <LI><B>svc_forward</B>: Mail forwarding
498 <LI><B>svc_mailinglist</B>: Mailing list
499 <LI><B>svc_www</B>: Virtual domain website
503 <UL STYLE="margin:0">
504 <LI><B>svc_port</B>: Customer router/switch port
509 <!-- <LI>svc_charge - One-time charges (Partially unimplemented)
510 <LI>svc_wo - Work orders (Partially unimplemented)
515 For the selected table, you can give fields default or fixed (unchangable)
516 values, or select an inventory class to manually or automatically fill in