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>
12 <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>> Disable new orders<BR>
13 <INPUT TYPE="checkbox" NAME="preserve" VALUE="Y"<% $hashref->{'preserve'} eq 'Y' ? ' CHECKED' : '' %>> Preserve this service on package cancellation<BR>
14 <INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $hashref->{svcpart} %>">
19 % #YUCK. false laziness w/part_svc.pm. go away virtual fields, please
21 % foreach my $svcdb ( FS::part_svc->svc_tables() ) {
22 % eval "use FS::$svcdb;";
23 % my $self = "FS::$svcdb"->new;
24 % $vfields{$svcdb} = {};
25 % foreach my $field ($self->virtual_fields) { # svc_Common::virtual_fields with a null svcpart returns all of them
26 % my $pvf = $self->pvf($field);
27 % $vfields{$svcdb}->{$field} = $pvf;
28 % #warn "\$vfields{$svcdb}->{$field} = $pvf";
32 % #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm
33 % # and generalize the subs
34 % # condition sub is tested to see whether to disable display of this choice
35 % # params: ( $def, $layer, $field ) (see SUB below)
37 % $_[0]->{disable_inventory}
38 % || $_[0]->{'type'} ne 'text'
40 % tie my %flag, 'Tie::IxHash',
41 % '' => { 'desc' => 'No default', },
42 % 'D' => { 'desc' => 'Default',
44 % sub { $_[0]->{disable_default} },
46 % 'F' => { 'desc' => 'Fixed (unchangeable)',
48 % sub { $_[0]->{disable_fixed} },
50 % 'S' => { 'desc' => 'Selectable Choice',
52 % sub { !ref($_[0]) || $_[0]->{disable_select} },
54 % 'M' => { 'desc' => 'Manual selection from inventory',
55 % 'condition' => $inv_sub,
57 % 'A' => { 'desc' => 'Automatically fill in from inventory',
58 % 'condition' => $inv_sub,
60 % 'H' => { 'desc' => 'Select from hardware class',
61 % 'condition' => sub { $_[0]->{type} ne 'select-hardware' },
63 % 'X' => { 'desc' => 'Excluded',
65 % sub { ! $vfields{$_[1]}->{$_[2]} },
70 % my @dbs = $hashref->{svcdb}
71 % ? ( $hashref->{svcdb} )
72 % : FS::part_svc->svc_tables();
74 % tie my %svcdb, 'Tie::IxHash', map { $_=>$_ } grep dbdef->table($_), @dbs;
75 % my $widget = new HTML::Widgets::SelectLayers(
76 % #'selected_layer' => $p_svcdb,
77 % 'selected_layer' => $hashref->{svcdb} || 'svc_acct',
78 % 'options' => \%svcdb,
79 % 'form_name' => 'dummy',
80 % #'form_action' => 'process/part_svc.cgi',
81 % 'form_action' => 'part_svc.cgi', #self
82 % 'form_text' => [ qw( svc svcpart ) ],
83 % 'form_checkbox' => [ 'disabled', 'preserve' ],
84 % 'layer_callback' => sub {
87 % my $html = qq!<INPUT TYPE="hidden" NAME="svcdb" VALUE="$layer">!;
89 % $html .= $svcdb_info;
93 % my $communigate = 0;
95 % map { qsearch( 'part_export', {exporttype => $_ } ) }
96 % keys %{FS::part_export::export_info($layer)};
97 % $html .= '<BR><BR>'. include('/elements/table.html') .
98 % "<TR><TH COLSPAN=$columns>Exports</TH></TR><TR>";
99 % foreach my $part_export ( @part_export ) {
100 % $communigate++ if $part_export->exporttype =~ /^communigate/;
101 % $html .= '<TD><INPUT TYPE="checkbox"'.
102 % ' NAME="exportnum'. $part_export->exportnum. '" VALUE="1" ';
104 % if ( $clone || $part_svc->svcpart ) #null svcpart search causing error
105 % && qsearchs( 'export_svc', {
106 % exportnum => $part_export->exportnum,
107 % svcpart => $clone || $part_svc->svcpart });
108 % $html .= '>'.$part_export->exportnum. ': ';
109 % $html .= $part_export->exportname . '<DIV ALIGN="right"><FONT SIZE=-1>'
110 % if ( $part_export->exportname );
111 % $html .= $part_export->exporttype. ' to '. $part_export->machine;
112 % $html .= '</FONT></DIV>' if ( $part_export->exportname );
115 % $html .= '</TR><TR>' unless $count % $columns;
117 % $html .= '</TR></TABLE><BR><BR>'. $mod_info;
119 % $html .= include('/elements/table-grid.html', 'cellpadding' => 4 ).
121 % '<TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>'.
122 % '<TH CLASS="grid" BGCOLOR="#cccccc">Label</TH>'.
123 % '<TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>'.
126 % my $bgcolor1 = '#eeeeee';
127 % my $bgcolor2 = '#ffffff';
132 % if ( defined( dbdef->table($layer) ) ) {
135 % && ( $communigate || !$communigate_fields{$layer}->{$_} )
136 % && ( !FS::part_svc->svc_table_fields($layer)
137 % ->{$_}->{disable_part_svc_column}
138 % || $part_svc->part_svc_column($_)->columnflag
142 % push @fields, 'usergroup'
143 % if $layer eq 'svc_acct'
144 % or ( $layer eq 'svc_broadband' and
145 % $conf->exists('svc_broadband-radius') ); # double kludge
146 % # (but we do want to check the config, right?)
147 % $part_svc->svcpart($clone) if $clone; #haha, undone below
150 % foreach my $field (@fields) {
152 % #a few lines of false laziness w/browse/part_svc.cgi
153 % my $def = FS::part_svc->svc_table_fields($layer)->{$field};
154 % my $def_info = $def->{'def_info'};
155 % my $formatter = $def->{'format'} || sub { shift };
157 % my $part_svc_column = $part_svc->part_svc_column($field);
158 % my $label = $part_svc_column->columnlabel || $def->{'label'};
159 % my $value = &$formatter($part_svc_column->columnvalue);
160 % my $flag = $part_svc_column->columnflag;
162 % if ( $bgcolor eq $bgcolor1 ) {
163 % $bgcolor = $bgcolor2;
165 % $bgcolor = $bgcolor1;
168 % $html .= qq!<TR><TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">!.
169 % ( $def->{'label'} || $field ).
172 % $html .= qq!<TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor"><INPUT NAME="${layer}__${field}_label" VALUE="!. encode_entities($label). '" STYLE="text-align:right"></TD>';
174 % $flag = '' if $def->{type} eq 'disabled';
176 % $html .= qq!<TD CLASS="grid" BGCOLOR="$bgcolor">!;
178 % if ( $def->{type} eq 'disabled' ) {
180 % $html .= 'No default';
184 % $html .= qq!<SELECT NAME="${layer}__${field}_flag"!.
185 % qq! onChange="${layer}__${field}_flag_changed(this)">!;
187 % foreach my $f ( keys %flag ) {
189 % # need to template-ize more httemplate/edit/svc_* first
190 % next if $f eq 'M' and $layer !~ /^svc_(broadband|external|phone|dish)$/;
192 % #here is where the SUB from above is called, to skip some choices
193 % next if $flag{$f}->{condition}
194 % && &{ $flag{$f}->{condition} }( $def, $layer, $field );
196 % $html .= qq!<OPTION VALUE="$f"!.
197 % ' SELECTED'x($flag eq $f ).
198 % '>'. $flag{$f}->{desc};
202 % $html .= '</SELECT>';
204 % $html .= join("\n",
206 % " function ${layer}__${field}_flag_changed(what) {",
207 % ' var f = what.options[what.selectedIndex].value;',
208 % ' if ( f == "" || f == "X" ) { //disable',
209 % " what.form.${layer}__${field}.disabled = true;".
210 % " what.form.${layer}__${field}.style.backgroundColor = '#dddddd';".
211 % " if ( what.form.${layer}__${field}_classnum ) {".
212 % " what.form.${layer}__${field}_classnum.disabled = true;".
213 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#dddddd';".
215 % ' } else if ( f == "D" || f == "F" || f =="S" ) { //enable, text box',
216 % " what.form.${layer}__${field}.disabled = false;".
217 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
218 % " if ( f == 'S' || '${field}' == 'usergroup' ) {". # kludge
219 % " what.form.${layer}__${field}.multiple = true;".
221 % " what.form.${layer}__${field}.multiple = false;".
223 % " what.form.${layer}__${field}.style.display = '';".
224 % " if ( what.form.${layer}__${field}_classnum ) {".
225 % " what.form.${layer}__${field}_classnum.disabled = false;".
226 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
227 % " what.form.${layer}__${field}_classnum.style.display = 'none';".
229 % ' } else if ( f == "M" || f == "A" || f == "H" ) { '.
230 % '//enable, inventory',
231 % " what.form.${layer}__${field}.disabled = false;".
232 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
233 % " what.form.${layer}__${field}.style.display = 'none';".
234 % " if ( what.form.${layer}__${field}_classnum ) {".
235 % " what.form.${layer}__${field}_classnum.disabled = false;".
236 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
237 % " what.form.${layer}__${field}_classnum.style.display = '';".
246 % $html .= qq!</TD><TD CLASS="grid" BGCOLOR="$bgcolor">!;
248 % my $disabled = $flag ? ''
249 % : 'DISABLED STYLE="background-color: #dddddd"';
250 % my $nodisplay = ' STYLE="display:none"';
252 % if ( !$def->{type} || $def->{type} eq 'text' ) {
254 % my $is_inv = ( $flag =~ /^[MA]$/ );
257 % qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value" !.
259 % ( $is_inv ? $nodisplay : $disabled ).
262 % $html .= include('/elements/select-table.html',
263 % 'element_name' => "${layer}__${field}_classnum",
264 % 'element_etc' => ( $is_inv
268 % 'table' => 'inventory_class',
269 % 'name_col' => 'classname',
271 % 'empty_label' => 'Select inventory class',
274 % } elsif ( $def->{type} eq 'checkbox' ) {
276 % $html .= include('/elements/checkbox.html',
277 % 'field' => $layer.'__'.$field,
278 % 'curr_value' => $value,
282 % } elsif ( $def->{type} eq 'select' ) {
284 % $html .= qq!<SELECT NAME="${layer}__${field}" $disabled!;
285 % $html .= ' MULTIPLE' if $flag eq 'S';
287 % $html .= '<OPTION> </OPTION>' unless $value;
288 % if ( $def->{select_table} ) {
289 % foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
290 % my $rvalue = $record->getfield($def->{select_key});
291 % my $select_label = $def->{select_label};
292 % $html .= qq!<OPTION VALUE="$rvalue"!.
293 % (grep(/^$rvalue$/, split(',',$value)) ? ' SELECTED>' : '>' ).
294 % $record->$select_label(). '</OPTION>';
296 % } elsif ( $def->{select_list} ) {
297 % foreach my $item ( @{$def->{select_list}} ) {
298 % $html .= qq!<OPTION VALUE="$item"!.
299 % (grep(/^$item$/, split(',',$value)) ? ' SELECTED>' : '>' ).
300 % $item. '</OPTION>';
302 % } elsif ( $def->{select_hash} ) {
303 % if ( ref($def->{select_hash}) eq 'ARRAY' ) {
304 % tie my %hash, 'Tie::IxHash', @{ $def->{select_hash} };
305 % $def->{select_hash} = \%hash;
307 % foreach my $key ( keys %{$def->{select_hash}} ) {
308 % $html .= qq!<OPTION VALUE="$key"!.
309 % (grep(/^$key$/, split(',',$value)) ? ' SELECTED>' : '>' ).
310 % $def->{select_hash}{$key}. '</OPTION>';
313 % $html .= '</SELECT>';
315 % } elsif ( $def->{type} eq 'textarea' ) {
318 % qq!<TEXTAREA NAME="${layer}__${field}">!. encode_entities($value).
321 % } elsif ( $def->{type} =~ /select-(.*?).html/ ) {
323 % $html .= include("/elements/".$def->{type},
324 % 'curr_value' => $value,
325 % 'element_name' => "${layer}__${field}",
326 % 'element_etc' => $disabled,
327 % 'multiple' => ($def->{multiple} ||
329 % # allow the table def to force 'multiple'
332 % } elsif ( $def->{type} eq 'communigate_pro-accessmodes' ) {
334 % $html .= include('/elements/communigate_pro-accessmodes.html',
335 % 'element_name_prefix' => "${layer}__${field}_",
336 % 'curr_value' => $value,
337 % #doesn't work#'element_etc' => $disabled,
340 % } elsif ( $def->{type} eq 'select-hardware' ) {
342 % $html .= qq!<INPUT TYPE="text" NAME="${layer}__${field}" $disabled>!;
343 % $html .= include('/elements/select-hardware_class.html',
344 % 'curr_value' => $value,
345 % 'element_name' => "${layer}__${field}_classnum",
346 % 'element_etc' => $flag ne 'H' && $nodisplay,
347 % 'empty_label' => 'Select hardware class',
350 % } elsif ( $def->{type} eq 'disabled' ) {
353 % qq!<INPUT TYPE="hidden" NAME="${layer}__${field}" VALUE="">!;
357 % $html .= '<font color="#ff0000">unknown type '. $def->{type};
361 % $html .= "</TD></TR>\n";
363 % $def_info = "($def_info)" if $def_info;
366 % qq! <TD COLSPAN=2 BGCOLOR="$bgcolor" ALIGN="center" !.
367 % qq! STYLE="padding:0; border-top: none">!.
368 % qq! <FONT SIZE="-1"><I>$def_info</I></FONT>!.
372 % } #foreach my $field (@fields) {
374 % $part_svc->svcpart('') if $clone; #undone
375 % $html .= "</TABLE>";
377 % $html .= include('/elements/progress-init.html',
379 % [ qw(svc svcpart disabled preserve exportnum),
381 % 'process/part_svc.cgi',
382 % $p.'browse/part_svc.cgi',
385 % $html .= '<BR><INPUT NAME="submit" TYPE="button" VALUE="'.
386 % ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '" '.
387 % ' onClick="document.'. "$layer.submit.disabled=true; ".
388 % "fixup(document.$layer); $layer". 'process();">';
390 % #$html .= '<BR><INPUT TYPE="submit" VALUE="'.
391 % # ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '">';
400 Table <% $widget->html %>
402 <% include('/elements/footer.html') %>
407 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
409 my $conf = FS::Conf->new;
412 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {#clone
413 #$cgi->param('clone') =~ /^(\d+)$/ or die "malformed query: $query";
414 $part_svc = qsearchs('part_svc', { 'svcpart'=>$1 } )
415 or die "unknown svcpart: $1";
416 $clone = $part_svc->svcpart;
417 $part_svc->svcpart('');
418 } elsif ( $cgi->keywords ) { #edit
419 my($query) = $cgi->keywords;
420 $query =~ /^(\d+)$/ or die "malformed query: $query";
421 $part_svc=qsearchs('part_svc', { 'svcpart'=>$1 } )
422 or die "unknown svcpart: $1";
424 $part_svc = new FS::part_svc {};
427 my $action = $part_svc->svcpart ? 'Edit' : 'Add';
428 my $hashref = $part_svc->hashref;
429 # my $p_svcdb = $part_svc->svcdb || 'svc_acct';
431 my %communigate_fields = (
432 'svc_acct' => { map { $_=>1 }
433 qw( file_quota file_maxnum file_maxsize
434 password_selfchange password_recover
436 grep /^cgp_/, fields('svc_acct')
438 'svc_domain' => { map { $_=>1 }
439 qw( max_accounts trailer parent_svcnum ),
440 grep /^(cgp|acct_def)_/, fields('svc_domain')
442 #'svc_forward' => { map { $_=>1 } qw( ) },
443 #'svc_mailinglist' => { map { $_=>1 } qw( ) },
444 #'svc_cert' => { map { $_=>1 } qw( ) },
450 <TH ALIGN="left">Generic</TH>
451 <TH ALIGN="left">Access</TH>
452 <TH ALIGN="left">Telephony</TH>
453 <!-- <TH>Hosting</TH>
459 <UL STYLE="margin:0">
460 <LI><B>svc_acct</B>: Accounts - anything with a username (mailbox, shell, RADIUS, etc.)
461 <LI><B>svc_hardware</B>: Equipment supplied to customers
462 <LI><B>svc_external</B>: Externally-tracked service
466 <UL STYLE="margin:0">
467 <LI><B>svc_dsl</B>: DSL
468 <LI><B>svc_broadband</B>: Wireless broadband
469 <LI><B>svc_dish</B>: DISH Network
473 <UL STYLE="margin:0">
474 <LI><B>svc_phone</B>: Customer phone number
475 <LI><B>svc_pbx</B>: Customer PBX
483 <TH ALIGN="left">Hosting</TH>
484 <TH ALIGN="left">Colocation</TH>
487 <UL STYLE="margin:0">
488 <LI><B>svc_domain</B>: Domain
489 <LI><B>svc_cert</B>: Certificate
490 <LI><B>svc_forward</B>: Mail forwarding
491 <LI><B>svc_mailinglist</B>: Mailing list
492 <LI><B>svc_www</B>: Virtual domain website
496 <UL STYLE="margin:0">
497 <LI><B>svc_port</B>: Customer router/switch port
502 <!-- <LI>svc_charge - One-time charges (Partially unimplemented)
503 <LI>svc_wo - Work orders (Partially unimplemented)
508 For the selected table, you can give fields default or fixed (unchangable)
509 values, or select an inventory class to manually or automatically fill in