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 % #YUCK. false laziness w/part_svc.pm. go away virtual fields, please
39 % foreach my $svcdb ( FS::part_svc->svc_tables() ) {
40 % eval "use FS::$svcdb;";
41 % my $self = "FS::$svcdb"->new;
42 % $vfields{$svcdb} = {};
43 % foreach my $field ($self->virtual_fields) { # svc_Common::virtual_fields with a null svcpart returns all of them
44 % my $pvf = $self->pvf($field);
45 % $vfields{$svcdb}->{$field} = $pvf;
46 % #warn "\$vfields{$svcdb}->{$field} = $pvf";
50 % #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm
51 % # and generalize the subs
52 % # condition sub is tested to see whether to disable display of this choice
53 % # params: ( $def, $layer, $field ) (see SUB below)
55 % $_[0]->{disable_inventory}
56 % || $_[0]->{'type'} ne 'text'
58 % tie my %flag, 'Tie::IxHash',
59 % '' => { 'desc' => 'No default', },
60 % 'D' => { 'desc' => 'Default',
62 % sub { $_[0]->{disable_default} },
64 % 'F' => { 'desc' => 'Fixed (unchangeable)',
66 % sub { $_[0]->{disable_fixed} },
68 % 'S' => { 'desc' => 'Selectable Choice',
70 % sub { !ref($_[0]) || $_[0]->{disable_select} },
72 % 'M' => { 'desc' => 'Manual selection from inventory',
73 % 'condition' => $inv_sub,
75 % 'A' => { 'desc' => 'Automatically fill in from inventory',
76 % 'condition' => $inv_sub,
78 % 'H' => { 'desc' => 'Select from hardware class',
79 % 'condition' => sub { $_[0]->{type} ne 'select-hardware' },
81 % 'X' => { 'desc' => 'Excluded',
83 % sub { ! $vfields{$_[1]}->{$_[2]} },
88 % my @dbs = $hashref->{svcdb}
89 % ? ( $hashref->{svcdb} )
90 % : FS::part_svc->svc_tables();
92 % tie my %svcdb, 'Tie::IxHash', map { $_=>$_ } grep dbdef->table($_), @dbs;
93 % my $widget = new HTML::Widgets::SelectLayers(
94 % #'selected_layer' => $p_svcdb,
95 % 'selected_layer' => $hashref->{svcdb} || 'svc_acct',
96 % 'options' => \%svcdb,
97 % 'form_name' => 'dummy',
98 % #'form_action' => 'process/part_svc.cgi',
99 % 'form_action' => 'part_svc.cgi', #self
100 % 'form_text' => [ qw( svc svcpart ) ],
101 % 'form_select' => [ 'selfservice_access' ],
102 % 'form_checkbox' => [ 'disabled', 'preserve' ],
103 % 'layer_callback' => sub {
106 % my $html = qq!<INPUT TYPE="hidden" NAME="svcdb" VALUE="$layer">!;
108 % $html .= $svcdb_info;
112 % my $communigate = 0;
114 % map { qsearch( 'part_export', {exporttype => $_ } ) }
115 % keys %{FS::part_export::export_info($layer)};
116 % $html .= '<BR><BR>'. include('/elements/table.html') .
117 % "<TR><TH COLSPAN=$columns>Exports</TH></TR><TR>";
118 % foreach my $part_export ( @part_export ) {
119 % $communigate++ if $part_export->exporttype =~ /^communigate/;
120 % $html .= '<TD><INPUT TYPE="checkbox"'.
121 % ' NAME="exportnum'. $part_export->exportnum. '" VALUE="1" ';
123 % if ( $clone || $part_svc->svcpart ) #null svcpart search causing error
124 % && qsearchs( 'export_svc', {
125 % exportnum => $part_export->exportnum,
126 % svcpart => $clone || $part_svc->svcpart });
127 % $html .= '>'.$part_export->exportnum. ': ';
128 % $html .= $part_export->exportname . '<DIV ALIGN="right"><FONT SIZE=-1>'
129 % if ( $part_export->exportname );
130 % $html .= $part_export->exporttype. ' to '. $part_export->machine;
131 % $html .= '</FONT></DIV>' if ( $part_export->exportname );
134 % $html .= '</TR><TR>' unless $count % $columns;
136 % $html .= '</TR></TABLE><BR><BR>'. $mod_info;
138 % $html .= include('/elements/table-grid.html', 'cellpadding' => 4 ).
140 % '<TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>'.
141 % '<TH CLASS="grid" BGCOLOR="#cccccc">Label</TH>'.
142 % '<TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>'.
145 % my $bgcolor1 = '#eeeeee';
146 % my $bgcolor2 = '#ffffff';
151 % if ( defined( dbdef->table($layer) ) ) {
154 % && ( $communigate || !$communigate_fields{$layer}->{$_} )
155 % && ( !FS::part_svc->svc_table_fields($layer)
156 % ->{$_}->{disable_part_svc_column}
157 % || $part_svc->part_svc_column($_)->columnflag
161 % push @fields, 'usergroup'
162 % if $layer eq 'svc_acct'
163 % or ( $layer eq 'svc_broadband' and
164 % $conf->exists('svc_broadband-radius') ); # double kludge
165 % # (but we do want to check the config, right?)
166 % $part_svc->svcpart($clone) if $clone; #haha, undone below
169 % foreach my $field (@fields) {
171 % #a few lines of false laziness w/browse/part_svc.cgi
172 % my $def = FS::part_svc->svc_table_fields($layer)->{$field};
173 % my $def_info = $def->{'def_info'};
174 % my $formatter = $def->{'format'} || sub { shift };
176 % my $part_svc_column = $part_svc->part_svc_column($field);
177 % my $label = $part_svc_column->columnlabel || $def->{'label'};
178 % my $value = &$formatter($part_svc_column->columnvalue);
179 % my $flag = $part_svc_column->columnflag;
181 % if ( $bgcolor eq $bgcolor1 ) {
182 % $bgcolor = $bgcolor2;
184 % $bgcolor = $bgcolor1;
187 % $html .= qq!<TR><TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">!.
188 % ( $def->{'label'} || $field ).
191 % $html .= qq!<TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor"><INPUT NAME="${layer}__${field}_label" VALUE="!. encode_entities($label). '" STYLE="text-align:right"></TD>';
193 % $flag = '' if $def->{type} eq 'disabled';
195 % $html .= qq!<TD CLASS="grid" BGCOLOR="$bgcolor">!;
197 % if ( $def->{type} eq 'disabled' ) {
199 % $html .= 'No default';
203 % $html .= qq!<SELECT NAME="${layer}__${field}_flag"!.
204 % qq! onChange="${layer}__${field}_flag_changed(this)">!;
206 % foreach my $f ( keys %flag ) {
208 % # need to template-ize more httemplate/edit/svc_* first
209 % next if $f eq 'M' and $layer !~ /^svc_(broadband|external|phone|dish)$/;
211 % #here is where the SUB from above is called, to skip some choices
212 % next if $flag{$f}->{condition}
213 % && &{ $flag{$f}->{condition} }( $def, $layer, $field );
215 % $html .= qq!<OPTION VALUE="$f"!.
216 % ' SELECTED'x($flag eq $f ).
217 % '>'. $flag{$f}->{desc};
221 % $html .= '</SELECT>';
223 % $html .= join("\n",
225 % " function ${layer}__${field}_flag_changed(what) {",
226 % ' var f = what.options[what.selectedIndex].value;',
227 % ' if ( f == "" || f == "X" ) { //disable',
228 % " what.form.${layer}__${field}.disabled = true;".
229 % " what.form.${layer}__${field}.style.backgroundColor = '#dddddd';".
230 % " if ( what.form.${layer}__${field}_classnum ) {".
231 % " what.form.${layer}__${field}_classnum.disabled = true;".
232 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#dddddd';".
234 % ' } else if ( f == "D" || f == "F" || f =="S" ) { //enable, text box',
235 % " what.form.${layer}__${field}.disabled = false;".
236 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
237 % " if ( f == 'S' || '${field}' == 'usergroup' ) {". # kludge
238 % " what.form.${layer}__${field}.multiple = true;".
240 % " what.form.${layer}__${field}.multiple = false;".
242 % " what.form.${layer}__${field}.style.display = '';".
243 % " if ( what.form.${layer}__${field}_classnum ) {".
244 % " what.form.${layer}__${field}_classnum.disabled = false;".
245 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
246 % " what.form.${layer}__${field}_classnum.style.display = 'none';".
248 % ' } else if ( f == "M" || f == "A" || f == "H" ) { '.
249 % '//enable, inventory',
250 % " what.form.${layer}__${field}.disabled = false;".
251 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
252 % " what.form.${layer}__${field}.style.display = 'none';".
253 % " if ( what.form.${layer}__${field}_classnum ) {".
254 % " what.form.${layer}__${field}_classnum.disabled = false;".
255 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
256 % " what.form.${layer}__${field}_classnum.style.display = '';".
265 % $html .= qq!</TD><TD CLASS="grid" BGCOLOR="$bgcolor">!;
267 % my $disabled = $flag ? ''
268 % : 'DISABLED STYLE="background-color: #dddddd"';
269 % my $nodisplay = ' STYLE="display:none"';
271 % if ( !$def->{type} || $def->{type} eq 'text' ) {
273 % my $is_inv = ( $flag =~ /^[MA]$/ );
276 % qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value" !.
278 % ( $is_inv ? $nodisplay : $disabled ).
281 % $html .= include('/elements/select-table.html',
282 % 'element_name' => "${layer}__${field}_classnum",
283 % 'element_etc' => ( $is_inv
287 % 'table' => 'inventory_class',
288 % 'name_col' => 'classname',
290 % 'empty_label' => 'Select inventory class',
293 % } elsif ( $def->{type} eq 'checkbox' ) {
295 % $html .= include('/elements/checkbox.html',
296 % 'field' => $layer.'__'.$field,
297 % 'curr_value' => $value,
301 % } elsif ( $def->{type} eq 'select' ) {
303 % $html .= qq!<SELECT NAME="${layer}__${field}" $disabled!;
304 % $html .= ' MULTIPLE' if $flag eq 'S';
306 % $html .= '<OPTION> </OPTION>' unless $value;
307 % if ( $def->{select_table} ) {
308 % foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
309 % my $rvalue = $record->getfield($def->{select_key});
310 % my $select_label = $def->{select_label};
311 % $html .= qq!<OPTION VALUE="$rvalue"!.
312 % (grep(/^$rvalue$/, split(',',$value)) ? ' SELECTED>' : '>' ).
313 % $record->$select_label(). '</OPTION>';
315 % } elsif ( $def->{select_list} ) {
316 % foreach my $item ( @{$def->{select_list}} ) {
317 % $html .= qq!<OPTION VALUE="$item"!.
318 % (grep(/^$item$/, split(',',$value)) ? ' SELECTED>' : '>' ).
319 % $item. '</OPTION>';
321 % } elsif ( $def->{select_hash} ) {
322 % if ( ref($def->{select_hash}) eq 'ARRAY' ) {
323 % tie my %hash, 'Tie::IxHash', @{ $def->{select_hash} };
324 % $def->{select_hash} = \%hash;
326 % foreach my $key ( keys %{$def->{select_hash}} ) {
327 % $html .= qq!<OPTION VALUE="$key"!.
328 % (grep(/^$key$/, split(',',$value)) ? ' SELECTED>' : '>' ).
329 % $def->{select_hash}{$key}. '</OPTION>';
332 % $html .= '</SELECT>';
334 % } elsif ( $def->{type} eq 'textarea' ) {
337 % qq!<TEXTAREA NAME="${layer}__${field}">!. encode_entities($value).
340 % } elsif ( $def->{type} =~ /select-(.*?).html/ ) {
342 % $html .= include("/elements/".$def->{type},
343 % 'curr_value' => $value,
344 % 'element_name' => "${layer}__${field}",
345 % 'element_etc' => $disabled,
346 % 'multiple' => ($def->{multiple} ||
348 % # allow the table def to force 'multiple'
351 % } elsif ( $def->{type} eq 'communigate_pro-accessmodes' ) {
353 % $html .= include('/elements/communigate_pro-accessmodes.html',
354 % 'element_name_prefix' => "${layer}__${field}_",
355 % 'curr_value' => $value,
356 % #doesn't work#'element_etc' => $disabled,
359 % } elsif ( $def->{type} eq 'select-hardware' ) {
361 % $html .= qq!<INPUT TYPE="text" NAME="${layer}__${field}" $disabled>!;
362 % $html .= include('/elements/select-hardware_class.html',
363 % 'curr_value' => $value,
364 % 'element_name' => "${layer}__${field}_classnum",
365 % 'element_etc' => $flag ne 'H' && $nodisplay,
366 % 'empty_label' => 'Select hardware class',
369 % } elsif ( $def->{type} eq 'disabled' ) {
372 % qq!<INPUT TYPE="hidden" NAME="${layer}__${field}" VALUE="">!;
376 % $html .= '<font color="#ff0000">unknown type '. $def->{type};
380 % $html .= "</TD></TR>\n";
382 % $def_info = "($def_info)" if $def_info;
385 % qq! <TD COLSPAN=2 BGCOLOR="$bgcolor" ALIGN="center" !.
386 % qq! STYLE="padding:0; border-top: none">!.
387 % qq! <FONT SIZE="-1"><I>$def_info</I></FONT>!.
391 % } #foreach my $field (@fields) {
393 % $part_svc->svcpart('') if $clone; #undone
394 % $html .= "</TABLE>";
396 % $html .= include('/elements/progress-init.html',
398 % [ qw(svc svcpart selfservice_access disabled preserve
401 % 'process/part_svc.cgi',
402 % $p.'browse/part_svc.cgi',
405 % $html .= '<BR><INPUT NAME="submit" TYPE="button" VALUE="'.
406 % ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '" '.
407 % ' onClick="document.'. "$layer.submit.disabled=true; ".
408 % "fixup(document.$layer); $layer". 'process();">';
410 % #$html .= '<BR><INPUT TYPE="submit" VALUE="'.
411 % # ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '">';
420 Table <% $widget->html %>
422 <% include('/elements/footer.html') %>
427 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
429 my $conf = FS::Conf->new;
432 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {#clone
433 #$cgi->param('clone') =~ /^(\d+)$/ or die "malformed query: $query";
434 $part_svc = qsearchs('part_svc', { 'svcpart'=>$1 } )
435 or die "unknown svcpart: $1";
436 $clone = $part_svc->svcpart;
437 $part_svc->svcpart('');
438 } elsif ( $cgi->keywords ) { #edit
439 my($query) = $cgi->keywords;
440 $query =~ /^(\d+)$/ or die "malformed query: $query";
441 $part_svc=qsearchs('part_svc', { 'svcpart'=>$1 } )
442 or die "unknown svcpart: $1";
444 $part_svc = new FS::part_svc {};
447 my $action = $part_svc->svcpart ? 'Edit' : 'Add';
448 my $hashref = $part_svc->hashref;
449 # my $p_svcdb = $part_svc->svcdb || 'svc_acct';
451 my %communigate_fields = (
452 'svc_acct' => { map { $_=>1 }
453 qw( file_quota file_maxnum file_maxsize
454 password_selfchange password_recover
456 grep /^cgp_/, fields('svc_acct')
458 'svc_domain' => { map { $_=>1 }
459 qw( max_accounts trailer parent_svcnum ),
460 grep /^(cgp|acct_def)_/, fields('svc_domain')
462 #'svc_forward' => { map { $_=>1 } qw( ) },
463 #'svc_mailinglist' => { map { $_=>1 } qw( ) },
464 #'svc_cert' => { map { $_=>1 } qw( ) },
470 <TH ALIGN="left">Generic</TH>
471 <TH ALIGN="left">Access</TH>
472 <TH ALIGN="left">Telephony</TH>
473 <!-- <TH>Hosting</TH>
479 <UL STYLE="margin:0">
480 <LI><B>svc_acct</B>: Accounts - anything with a username (mailbox, shell, RADIUS, etc.)
481 <LI><B>svc_hardware</B>: Equipment supplied to customers
482 <LI><B>svc_external</B>: Externally-tracked service
486 <UL STYLE="margin:0">
487 <LI><B>svc_dsl</B>: DSL
488 <LI><B>svc_broadband</B>: Wireless broadband
489 <LI><B>svc_dish</B>: DISH Network
493 <UL STYLE="margin:0">
494 <LI><B>svc_phone</B>: Customer phone number
495 <LI><B>svc_pbx</B>: Customer PBX
503 <TH ALIGN="left">Hosting</TH>
504 <TH ALIGN="left">Colocation</TH>
507 <UL STYLE="margin:0">
508 <LI><B>svc_domain</B>: Domain
509 <LI><B>svc_cert</B>: Certificate
510 <LI><B>svc_forward</B>: Mail forwarding
511 <LI><B>svc_mailinglist</B>: Mailing list
512 <LI><B>svc_www</B>: Virtual domain website
516 <UL STYLE="margin:0">
517 <LI><B>svc_port</B>: Customer router/switch port
522 <!-- <LI>svc_charge - One-time charges (Partially unimplemented)
523 <LI>svc_wo - Work orders (Partially unimplemented)
528 For the selected table, you can give fields default or fixed (unchangable)
529 values, or select an inventory class to manually or automatically fill in