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 Disable new orders <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>><BR>
13 <INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $hashref->{svcpart} %>">
18 % #YUCK. false laziness w/part_svc.pm. go away virtual fields, please
20 % foreach my $svcdb ( FS::part_svc->svc_tables() ) {
21 % eval "use FS::$svcdb;";
22 % my $self = "FS::$svcdb"->new;
23 % $vfields{$svcdb} = {};
24 % foreach my $field ($self->virtual_fields) { # svc_Common::virtual_fields with a null svcpart returns all of them
25 % my $pvf = $self->pvf($field);
26 % $vfields{$svcdb}->{$field} = $pvf;
27 % #warn "\$vfields{$svcdb}->{$field} = $pvf";
31 % #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm
32 % # and generalize the subs
33 % # condition sub is tested to see whether to disable display of this choice
34 % # params: ( $def, $layer, $field ) (see SUB below)
36 % $_[0]->{disable_inventory}
37 % || $_[0]->{'type'} ne 'text'
39 % tie my %flag, 'Tie::IxHash',
40 % '' => { 'desc' => 'No default', },
41 % 'D' => { 'desc' => 'Default',
43 % sub { $_[0]->{disable_default} },
45 % 'F' => { 'desc' => 'Fixed (unchangeable)',
47 % sub { $_[0]->{disable_fixed} },
49 % 'S' => { 'desc' => 'Selectable Choice',
51 % sub { !ref($_[0]) || $_[0]->{disable_select} },
53 % 'M' => { 'desc' => 'Manual selection from inventory',
54 % 'condition' => $inv_sub,
56 % 'A' => { 'desc' => 'Automatically fill in from inventory',
57 % 'condition' => $inv_sub,
59 % 'X' => { 'desc' => 'Excluded',
61 % sub { ! $vfields{$_[1]}->{$_[2]} },
66 % my @dbs = $hashref->{svcdb}
67 % ? ( $hashref->{svcdb} )
68 % : FS::part_svc->svc_tables();
70 % tie my %svcdb, 'Tie::IxHash', map { $_=>$_ } grep dbdef->table($_), @dbs;
71 % my $widget = new HTML::Widgets::SelectLayers(
72 % #'selected_layer' => $p_svcdb,
73 % 'selected_layer' => $hashref->{svcdb} || 'svc_acct',
74 % 'options' => \%svcdb,
75 % 'form_name' => 'dummy',
76 % #'form_action' => 'process/part_svc.cgi',
77 % 'form_action' => 'part_svc.cgi', #self
78 % 'form_text' => [ qw( svc svcpart ) ],
79 % 'form_checkbox' => [ 'disabled' ],
80 % 'layer_callback' => sub {
83 % my $html = qq!<INPUT TYPE="hidden" NAME="svcdb" VALUE="$layer">!;
85 % $html .= $svcdb_info;
89 % my $communigate = 0;
91 % map { qsearch( 'part_export', {exporttype => $_ } ) }
92 % keys %{FS::part_export::export_info($layer)};
93 % $html .= '<BR><BR>'. table().
94 % "<TR><TH COLSPAN=$columns>Exports</TH></TR><TR>";
95 % foreach my $part_export ( @part_export ) {
96 % $communigate++ if $part_export->exporttype =~ /^communigate/;
97 % $html .= '<TD><INPUT TYPE="checkbox"'.
98 % ' NAME="exportnum'. $part_export->exportnum. '" VALUE="1" ';
100 % if ( $clone || $part_svc->svcpart ) #null svcpart search causing error
101 % && qsearchs( 'export_svc', {
102 % exportnum => $part_export->exportnum,
103 % svcpart => $clone || $part_svc->svcpart });
104 % $html .= '>'.$part_export->exportnum. ': ';
105 % $html .= $part_export->exportname . '<DIV ALIGN="right"><FONT SIZE=-1>'
106 % if ( $part_export->exportname );
107 % $html .= $part_export->exporttype. ' to '. $part_export->machine;
108 % $html .= '</FONT></DIV>' if ( $part_export->exportname );
111 % $html .= '</TR><TR>' unless $count % $columns;
113 % $html .= '</TR></TABLE><BR><BR>'. $mod_info;
115 % $html .= include('/elements/table-grid.html', 'cellpadding' => 4 ).
117 % '<TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>'.
118 % '<TH CLASS="grid" BGCOLOR="#cccccc">Label</TH>'.
119 % '<TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>'.
122 % my $bgcolor1 = '#eeeeee';
123 % my $bgcolor2 = '#ffffff';
128 % if ( defined( dbdef->table($layer) ) ) {
131 % && ( $communigate || !$communigate_fields{$layer}->{$_} )
132 % && ( !FS::part_svc->svc_table_fields($layer)
133 % ->{$_}->{disable_part_svc_column}
134 % || $part_svc->part_svc_column($_)->columnflag
138 % push @fields, 'usergroup' if $layer eq 'svc_acct'; #kludge
139 % $part_svc->svcpart($clone) if $clone; #haha, undone below
142 % foreach my $field (@fields) {
144 % #a few lines of false laziness w/browse/part_svc.cgi
145 % my $def = FS::part_svc->svc_table_fields($layer)->{$field};
146 % my $def_info = $def->{'def_info'};
147 % my $formatter = $def->{'format'} || sub { shift };
149 % my $part_svc_column = $part_svc->part_svc_column($field);
150 % my $label = $part_svc_column->columnlabel || $def->{'label'};
151 % my $value = &$formatter($part_svc_column->columnvalue);
152 % my $flag = $part_svc_column->columnflag;
154 % if ( $bgcolor eq $bgcolor1 ) {
155 % $bgcolor = $bgcolor2;
157 % $bgcolor = $bgcolor1;
160 % $html .= qq!<TR><TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">!.
161 % ( $def->{'label'} || $field ).
164 % $html .= qq!<TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor"><INPUT NAME="${layer}__${field}_label" VALUE="!. encode_entities($label). '" STYLE="text-align:right"></TD>';
166 % $flag = '' if $def->{type} eq 'disabled';
168 % $html .= qq!<TD CLASS="grid" BGCOLOR="$bgcolor">!;
170 % if ( $def->{type} eq 'disabled' ) {
172 % $html .= 'No default';
176 % $html .= qq!<SELECT NAME="${layer}__${field}_flag"!.
177 % qq! onChange="${layer}__${field}_flag_changed(this)">!;
179 % foreach my $f ( keys %flag ) {
181 % # need to template-ize more httemplate/edit/svc_* first
182 % next if $f eq 'M' and $layer !~ /^svc_(broadband|external|phone)$/;
184 % #here is where the SUB from above is called, to skip some choices
185 % next if $flag{$f}->{condition}
186 % && &{ $flag{$f}->{condition} }( $def, $layer, $field );
188 % $html .= qq!<OPTION VALUE="$f"!.
189 % ' SELECTED'x($flag eq $f ).
190 % '>'. $flag{$f}->{desc};
194 % $html .= '</SELECT>';
196 % $html .= join("\n",
198 % " function ${layer}__${field}_flag_changed(what) {",
199 % ' var f = what.options[what.selectedIndex].value;',
200 % ' if ( f == "" || f == "X" ) { //disable',
201 % " what.form.${layer}__${field}.disabled = true;".
202 % " what.form.${layer}__${field}.style.backgroundColor = '#dddddd';".
203 % " if ( what.form.${layer}__${field}_classnum ) {".
204 % " what.form.${layer}__${field}_classnum.disabled = true;".
205 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#dddddd';".
207 % ' } else if ( f == "D" || f == "F" || f =="S" ) { //enable, text box',
208 % " what.form.${layer}__${field}.disabled = false;".
209 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
210 % " if ( f == 'S' || '${field}' == 'usergroup' ) {". # kludge
211 % " what.form.${layer}__${field}.multiple = true;".
213 % " what.form.${layer}__${field}.multiple = false;".
215 % " what.form.${layer}__${field}.style.display = '';".
216 % " if ( what.form.${layer}__${field}_classnum ) {".
217 % " what.form.${layer}__${field}_classnum.disabled = false;".
218 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
219 % " what.form.${layer}__${field}_classnum.style.display = 'none';".
221 % ' } else if ( f == "M" || f == "A" ) { //enable, inventory',
222 % " what.form.${layer}__${field}.disabled = false;".
223 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
224 % " what.form.${layer}__${field}.style.display = 'none';".
225 % " if ( what.form.${layer}__${field}_classnum ) {".
226 % " what.form.${layer}__${field}_classnum.disabled = false;".
227 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
228 % " what.form.${layer}__${field}_classnum.style.display = '';".
237 % $html .= qq!</TD><TD CLASS="grid" BGCOLOR="$bgcolor">!;
239 % my $disabled = $flag ? ''
240 % : 'DISABLED STYLE="background-color: #dddddd"';
242 % if ( !$def->{type} || $def->{type} eq 'text' ) {
244 % my $nodisplay = ' STYLE="display:none"';
245 % my $is_inv = ( $flag =~ /^[MA]$/ );
248 % qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value" !.
250 % ( $is_inv ? $nodisplay : $disabled ).
253 % $html .= include('/elements/select-table.html',
254 % 'element_name' => "${layer}__${field}_classnum",
255 % 'element_etc' => ( $is_inv
259 % 'table' => 'inventory_class',
260 % 'name_col' => 'classname',
262 % 'empty_label' => 'Select inventory class',
265 % } elsif ( $def->{type} eq 'checkbox' ) {
267 % $html .= include('/elements/checkbox.html',
268 % 'field' => $layer.'__'.$field,
269 % 'curr_value' => $value,
273 % } elsif ( $def->{type} eq 'select' ) {
275 % $html .= qq!<SELECT NAME="${layer}__${field}" $disabled!;
276 % $html .= ' MULTIPLE' if $flag eq 'S';
278 % $html .= '<OPTION> </OPTION>' unless $value;
279 % if ( $def->{select_table} ) {
280 % foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
281 % my $rvalue = $record->getfield($def->{select_key});
282 % my $select_label = $def->{select_label};
283 % $html .= qq!<OPTION VALUE="$rvalue"!.
284 % (grep(/^$rvalue$/, split(',',$value)) ? ' SELECTED>' : '>' ).
285 % $record->$select_label(). '</OPTION>';
287 % } elsif ( $def->{select_list} ) {
288 % foreach my $item ( @{$def->{select_list}} ) {
289 % $html .= qq!<OPTION VALUE="$item"!.
290 % (grep(/^$item$/, split(',',$value)) ? ' SELECTED>' : '>' ).
291 % $item. '</OPTION>';
293 % } elsif ( $def->{select_hash} ) {
294 % if ( ref($def->{select_hash}) eq 'ARRAY' ) {
295 % tie my %hash, 'Tie::IxHash', @{ $def->{select_hash} };
296 % $def->{select_hash} = \%hash;
298 % foreach my $key ( keys %{$def->{select_hash}} ) {
299 % $html .= qq!<OPTION VALUE="$key"!.
300 % (grep(/^$key$/, split(',',$value)) ? ' SELECTED>' : '>' ).
301 % $def->{select_hash}{$key}. '</OPTION>';
304 % $html .= '</SELECT>';
306 % } elsif ( $def->{type} eq 'textarea' ) {
309 % qq!<TEXTAREA NAME="${layer}__${field}">!. encode_entities($value).
312 % } elsif ( $def->{type} eq 'select-svc_pbx.html' ) {
314 % $html .= include('/elements/select-svc_pbx.html',
315 % 'curr_value' => $value,
316 % 'element_name' => "${layer}__${field}",
317 % 'element_etc' => $disabled,
318 % 'multiple' => ($flag eq 'S'),
321 % } elsif ( $def->{type} eq 'select-lnp_status.html' ) {
323 % $html .= include('/elements/select-lnp_status.html',
324 % 'curr_value' => $value,
325 % 'element_name' => "${layer}__${field}",
326 % 'element_etc' => $disabled,
327 % 'multiple' => ($flag eq 'S'),
330 % } elsif ( $def->{type} eq 'radius_usergroup_selector' ) {
332 % #XXX disable the RADIUS usergroup selector? ugh it sure does need
333 % #an overhaul, people have dum group problems because of it
335 % $html .= FS::svc_acct::radius_usergroup_selector(
336 % [ split(',', $value) ], "${layer}__${field}" );
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 'disabled' ) {
349 % qq!<INPUT TYPE="hidden" NAME="${layer}__${field}" VALUE="">!;
353 % $html .= '<font color="#ff0000">unknown type '. $def->{type};
357 % $html .= "</TD></TR>\n";
359 % $def_info = "($def_info)" if $def_info;
362 % qq! <TD COLSPAN=2 BGCOLOR="$bgcolor" ALIGN="center" !.
363 % qq! STYLE="padding:0; border-top: none">!.
364 % qq! <FONT SIZE="-1"><I>$def_info</I></FONT>!.
368 % } #foreach my $field (@fields) {
370 % $part_svc->svcpart('') if $clone; #undone
371 % $html .= "</TABLE>";
373 % $html .= include('/elements/progress-init.html',
375 % [ qw(svc svcpart disabled exportnum), @fields ],
376 % 'process/part_svc.cgi',
377 % $p.'browse/part_svc.cgi',
380 % $html .= '<BR><INPUT NAME="submit" TYPE="button" VALUE="'.
381 % ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '" '.
382 % ' onClick="document.'. "$layer.submit.disabled=true; ".
383 % "fixup(document.$layer); $layer". 'process();">';
385 % #$html .= '<BR><INPUT TYPE="submit" VALUE="'.
386 % # ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '">';
395 Table <% $widget->html %>
397 <% include('/elements/footer.html') %>
402 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
406 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {#clone
407 #$cgi->param('clone') =~ /^(\d+)$/ or die "malformed query: $query";
408 $part_svc = qsearchs('part_svc', { 'svcpart'=>$1 } )
409 or die "unknown svcpart: $1";
410 $clone = $part_svc->svcpart;
411 $part_svc->svcpart('');
412 } elsif ( $cgi->keywords ) { #edit
413 my($query) = $cgi->keywords;
414 $query =~ /^(\d+)$/ or die "malformed query: $query";
415 $part_svc=qsearchs('part_svc', { 'svcpart'=>$1 } )
416 or die "unknown svcpart: $1";
418 $part_svc = new FS::part_svc {};
421 my $action = $part_svc->svcpart ? 'Edit' : 'Add';
422 my $hashref = $part_svc->hashref;
423 # my $p_svcdb = $part_svc->svcdb || 'svc_acct';
425 my %communigate_fields = (
426 'svc_acct' => { map { $_=>1 }
427 qw( file_quota file_maxnum file_maxsize
428 password_selfchange password_recover
430 grep /^cgp_/, fields('svc_acct')
432 'svc_domain' => { map { $_=>1 }
433 qw( max_accounts trailer parent_svcnum ),
434 grep /^(cgp|acct_def)_/, fields('svc_domain')
436 #'svc_forward' => { map { $_=>1 } qw( ) },
437 #'svc_mailinglist' => { map { $_=>1 } qw( ) },
438 #'svc_cert' => { map { $_=>1 } qw( ) },
444 <TH ALIGN="left">Generic</TH>
445 <TH ALIGN="left">Access</TH>
446 <TH ALIGN="left">Telephony</TH>
447 <!-- <TH>Hosting</TH>
453 <UL STYLE="margin:0">
454 <LI><B>svc_acct</B>: Accounts - anything with a username (mailbox, shell, RADIUS, etc.)
455 <LI><B>svc_external</B>: Externally-tracked service
459 <UL STYLE="margin:0">
460 <LI><B>svc_dsl</B>: DSL
461 <LI><B>svc_broadband</B>: Wireless broadband
465 <UL STYLE="margin:0">
466 <LI><B>svc_phone</B>: Customer phone number
467 <LI><B>svc_pbx</B>: Customer PBX
475 <TH ALIGN="left">Hosting</TH>
476 <TH ALIGN="left">Colocation</TH>
479 <UL STYLE="margin:0">
480 <LI><B>svc_domain</B>: Domain
481 <LI><B>svc_cert</B>: Certificate
482 <LI><B>svc_forward</B>: Mail forwarding
483 <LI><B>svc_mailinglist</B>: Mailing list
484 <LI><B>svc_www</B>: Virtual domain website
488 <UL STYLE="margin:0">
489 <LI><B>svc_port</B>: Customer router/switch port
494 <!-- <LI>svc_charge - One-time charges (Partially unimplemented)
495 <LI>svc_wo - Work orders (Partially unimplemented)
500 For the selected table, you can give fields default or fixed (unchangable)
501 values, or select an inventory class to manually or automatically fill in