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 % #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm
20 % # and generalize the subs
21 % # condition sub is tested to see whether to disable display of this choice
22 % # params: ( $def, $layer, $field ) (see SUB below)
24 % $_[0]->{disable_inventory}
25 % || $_[0]->{'type'} ne 'text'
27 % tie my %flag, 'Tie::IxHash',
28 % '' => { 'desc' => 'No default', },
29 % 'D' => { 'desc' => 'Default',
31 % sub { $_[0]->{disable_default} },
33 % 'F' => { 'desc' => 'Fixed (unchangeable)',
35 % sub { $_[0]->{disable_fixed} },
37 % 'S' => { 'desc' => 'Selectable Choice',
39 % sub { !ref($_[0]) || $_[0]->{disable_select} },
41 % 'M' => { 'desc' => 'Manual selection from inventory',
42 % 'condition' => $inv_sub,
44 % 'A' => { 'desc' => 'Automatically fill in from inventory',
45 % 'condition' => $inv_sub,
47 % 'H' => { 'desc' => 'Select from hardware class',
48 % 'condition' => sub { $_[0]->{type} ne 'select-hardware' },
50 % 'X' => { 'desc' => 'Excluded',
52 % sub { ! $vfields{$_[1]}->{$_[2]} },
57 % my @dbs = $hashref->{svcdb}
58 % ? ( $hashref->{svcdb} )
59 % : FS::part_svc->svc_tables();
61 % tie my %svcdb, 'Tie::IxHash', map { $_=>$_ } grep dbdef->table($_), @dbs;
62 % my $widget = new HTML::Widgets::SelectLayers(
63 % #'selected_layer' => $p_svcdb,
64 % 'selected_layer' => $hashref->{svcdb} || 'svc_acct',
65 % 'options' => \%svcdb,
66 % 'form_name' => 'dummy',
67 % #'form_action' => 'process/part_svc.cgi',
68 % 'form_action' => 'part_svc.cgi', #self
69 % 'form_text' => [ qw( svc svcpart ) ],
70 % 'form_checkbox' => [ 'disabled', 'preserve' ],
71 % 'layer_callback' => sub {
74 % my $html = qq!<INPUT TYPE="hidden" NAME="svcdb" VALUE="$layer">!;
76 % $html .= $svcdb_info;
80 % my $communigate = 0;
82 % map { qsearch( 'part_export', {exporttype => $_ } ) }
83 % keys %{FS::part_export::export_info($layer)};
84 % $html .= '<BR><BR>'. include('/elements/table.html') .
85 % "<TR><TH COLSPAN=$columns>Exports</TH></TR><TR>";
86 % foreach my $part_export ( @part_export ) {
87 % $communigate++ if $part_export->exporttype =~ /^communigate/;
88 % $html .= '<TD><INPUT TYPE="checkbox"'.
89 % ' NAME="exportnum'. $part_export->exportnum. '" VALUE="1" ';
91 % if ( $clone || $part_svc->svcpart ) #null svcpart search causing error
92 % && qsearchs( 'export_svc', {
93 % exportnum => $part_export->exportnum,
94 % svcpart => $clone || $part_svc->svcpart });
95 % $html .= '>'.$part_export->exportnum. ': ';
96 % $html .= $part_export->exportname . '<DIV ALIGN="right"><FONT SIZE=-1>'
97 % if ( $part_export->exportname );
98 % $html .= $part_export->exporttype. ' to '. $part_export->machine;
99 % $html .= '</FONT></DIV>' if ( $part_export->exportname );
102 % $html .= '</TR><TR>' unless $count % $columns;
104 % $html .= '</TR></TABLE><BR><BR>'. $mod_info;
106 % $html .= include('/elements/table-grid.html', 'cellpadding' => 4 ).
108 % '<TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>'.
109 % '<TH CLASS="grid" BGCOLOR="#cccccc">Label</TH>'.
110 % '<TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>'.
113 % my $bgcolor1 = '#eeeeee';
114 % my $bgcolor2 = '#ffffff';
119 % if ( defined( dbdef->table($layer) ) ) {
122 % && ( $communigate || !$communigate_fields{$layer}->{$_} )
123 % && ( !FS::part_svc->svc_table_fields($layer)
124 % ->{$_}->{disable_part_svc_column}
125 % || $part_svc->part_svc_column($_)->columnflag
129 % push @fields, 'usergroup'
130 % if $layer eq 'svc_acct'
131 % or ( $layer eq 'svc_broadband' and
132 % $conf->exists('svc_broadband-radius') ); # double kludge
133 % # (but we do want to check the config, right?)
134 % $part_svc->svcpart($clone) if $clone; #haha, undone below
137 % foreach my $field (@fields) {
139 % #a few lines of false laziness w/browse/part_svc.cgi
140 % my $def = FS::part_svc->svc_table_fields($layer)->{$field};
141 % my $def_info = $def->{'def_info'};
142 % my $formatter = $def->{'format'} || sub { shift };
144 % my $part_svc_column = $part_svc->part_svc_column($field);
145 % my $label = $part_svc_column->columnlabel || $def->{'label'};
146 % my $value = &$formatter($part_svc_column->columnvalue);
147 % my $flag = $part_svc_column->columnflag;
149 % if ( $bgcolor eq $bgcolor1 ) {
150 % $bgcolor = $bgcolor2;
152 % $bgcolor = $bgcolor1;
155 % $html .= qq!<TR><TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">!.
156 % ( $def->{'label'} || $field ).
159 % $html .= qq!<TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor"><INPUT NAME="${layer}__${field}_label" VALUE="!. encode_entities($label). '" STYLE="text-align:right"></TD>';
161 % $flag = '' if $def->{type} eq 'disabled';
163 % $html .= qq!<TD CLASS="grid" BGCOLOR="$bgcolor">!;
165 % if ( $def->{type} eq 'disabled' ) {
167 % $html .= 'No default';
171 % $html .= qq!<SELECT NAME="${layer}__${field}_flag"!.
172 % qq! onChange="${layer}__${field}_flag_changed(this)">!;
174 % foreach my $f ( keys %flag ) {
176 % # need to template-ize more httemplate/edit/svc_* first
177 % next if $f eq 'M' and $layer !~ /^svc_(broadband|external|phone|dish)$/;
179 % #here is where the SUB from above is called, to skip some choices
180 % next if $flag{$f}->{condition}
181 % && &{ $flag{$f}->{condition} }( $def, $layer, $field );
183 % $html .= qq!<OPTION VALUE="$f"!.
184 % ' SELECTED'x($flag eq $f ).
185 % '>'. $flag{$f}->{desc};
189 % $html .= '</SELECT>';
191 % $html .= join("\n",
193 % " function ${layer}__${field}_flag_changed(what) {",
194 % ' var f = what.options[what.selectedIndex].value;',
195 % ' if ( f == "" || f == "X" ) { //disable',
196 % " what.form.${layer}__${field}.disabled = true;".
197 % " what.form.${layer}__${field}.style.backgroundColor = '#dddddd';".
198 % " if ( what.form.${layer}__${field}_classnum ) {".
199 % " what.form.${layer}__${field}_classnum.disabled = true;".
200 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#dddddd';".
202 % ' } else if ( f == "D" || f == "F" || f =="S" ) { //enable, text box',
203 % " what.form.${layer}__${field}.disabled = false;".
204 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
205 % " if ( f == 'S' || '${field}' == 'usergroup' ) {". # kludge
206 % " what.form.${layer}__${field}.multiple = true;".
208 % " what.form.${layer}__${field}.multiple = false;".
210 % " what.form.${layer}__${field}.style.display = '';".
211 % " if ( what.form.${layer}__${field}_classnum ) {".
212 % " what.form.${layer}__${field}_classnum.disabled = false;".
213 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
214 % " what.form.${layer}__${field}_classnum.style.display = 'none';".
216 % ' } else if ( f == "M" || f == "A" || f == "H" ) { '.
217 % '//enable, inventory',
218 % " what.form.${layer}__${field}.disabled = false;".
219 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
220 % " what.form.${layer}__${field}.style.display = 'none';".
221 % " if ( what.form.${layer}__${field}_classnum ) {".
222 % " what.form.${layer}__${field}_classnum.disabled = false;".
223 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
224 % " what.form.${layer}__${field}_classnum.style.display = '';".
233 % $html .= qq!</TD><TD CLASS="grid" BGCOLOR="$bgcolor">!;
235 % my $disabled = $flag ? ''
236 % : 'DISABLED STYLE="background-color: #dddddd"';
237 % my $nodisplay = ' STYLE="display:none"';
239 % if ( !$def->{type} || $def->{type} eq 'text' ) {
241 % my $is_inv = ( $flag =~ /^[MA]$/ );
244 % qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value" !.
246 % ( $is_inv ? $nodisplay : $disabled ).
249 % $html .= include('/elements/select-table.html',
250 % 'element_name' => "${layer}__${field}_classnum",
251 % 'element_etc' => ( $is_inv
255 % 'table' => 'inventory_class',
256 % 'name_col' => 'classname',
258 % 'empty_label' => 'Select inventory class',
261 % } elsif ( $def->{type} eq 'checkbox' ) {
263 % $html .= include('/elements/checkbox.html',
264 % 'field' => $layer.'__'.$field,
265 % 'curr_value' => $value,
269 % } elsif ( $def->{type} eq 'select' ) {
271 % $html .= qq!<SELECT NAME="${layer}__${field}" $disabled!;
272 % $html .= ' MULTIPLE' if $flag eq 'S';
274 % $html .= '<OPTION> </OPTION>' unless $value;
275 % if ( $def->{select_table} ) {
276 % foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
277 % my $rvalue = $record->getfield($def->{select_key});
278 % my $select_label = $def->{select_label};
279 % $html .= qq!<OPTION VALUE="$rvalue"!.
280 % (grep(/^$rvalue$/, split(',',$value)) ? ' SELECTED>' : '>' ).
281 % $record->$select_label(). '</OPTION>';
283 % } elsif ( $def->{select_list} ) {
284 % foreach my $item ( @{$def->{select_list}} ) {
285 % $html .= qq!<OPTION VALUE="$item"!.
286 % (grep(/^$item$/, split(',',$value)) ? ' SELECTED>' : '>' ).
287 % $item. '</OPTION>';
289 % } elsif ( $def->{select_hash} ) {
290 % if ( ref($def->{select_hash}) eq 'ARRAY' ) {
291 % tie my %hash, 'Tie::IxHash', @{ $def->{select_hash} };
292 % $def->{select_hash} = \%hash;
294 % foreach my $key ( keys %{$def->{select_hash}} ) {
295 % $html .= qq!<OPTION VALUE="$key"!.
296 % (grep(/^$key$/, split(',',$value)) ? ' SELECTED>' : '>' ).
297 % $def->{select_hash}{$key}. '</OPTION>';
300 % $html .= '</SELECT>';
302 % } elsif ( $def->{type} eq 'textarea' ) {
305 % qq!<TEXTAREA NAME="${layer}__${field}">!. encode_entities($value).
308 % } elsif ( $def->{type} =~ /select-(.*?).html/ ) {
310 % $html .= include("/elements/".$def->{type},
311 % 'curr_value' => $value,
312 % 'element_name' => "${layer}__${field}",
313 % 'element_etc' => $disabled,
314 % 'multiple' => ($def->{multiple} ||
316 % # allow the table def to force 'multiple'
319 % } elsif ( $def->{type} eq 'communigate_pro-accessmodes' ) {
321 % $html .= include('/elements/communigate_pro-accessmodes.html',
322 % 'element_name_prefix' => "${layer}__${field}_",
323 % 'curr_value' => $value,
324 % #doesn't work#'element_etc' => $disabled,
327 % } elsif ( $def->{type} eq 'select-hardware' ) {
329 % $html .= qq!<INPUT TYPE="text" NAME="${layer}__${field}" $disabled>!;
330 % $html .= include('/elements/select-hardware_class.html',
331 % 'curr_value' => $value,
332 % 'element_name' => "${layer}__${field}_classnum",
333 % 'element_etc' => $flag ne 'H' && $nodisplay,
334 % 'empty_label' => 'Select hardware class',
337 % } elsif ( $def->{type} eq 'disabled' ) {
340 % qq!<INPUT TYPE="hidden" NAME="${layer}__${field}" VALUE="">!;
344 % $html .= '<font color="#ff0000">unknown type '. $def->{type};
348 % $html .= "</TD></TR>\n";
350 % $def_info = "($def_info)" if $def_info;
353 % qq! <TD COLSPAN=2 BGCOLOR="$bgcolor" ALIGN="center" !.
354 % qq! STYLE="padding:0; border-top: none">!.
355 % qq! <FONT SIZE="-1"><I>$def_info</I></FONT>!.
359 % } #foreach my $field (@fields) {
361 % $part_svc->svcpart('') if $clone; #undone
362 % $html .= "</TABLE>";
364 % $html .= include('/elements/progress-init.html',
366 % [ qw(svc svcpart disabled preserve exportnum),
368 % 'process/part_svc.cgi',
369 % $p.'browse/part_svc.cgi',
372 % $html .= '<BR><INPUT NAME="submit" TYPE="button" VALUE="'.
373 % ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '" '.
374 % ' onClick="document.'. "$layer.submit.disabled=true; ".
375 % "fixup(document.$layer); $layer". 'process();">';
377 % #$html .= '<BR><INPUT TYPE="submit" VALUE="'.
378 % # ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '">';
387 Table <% $widget->html %>
389 <% include('/elements/footer.html') %>
394 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
396 my $conf = FS::Conf->new;
399 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {#clone
400 #$cgi->param('clone') =~ /^(\d+)$/ or die "malformed query: $query";
401 $part_svc = qsearchs('part_svc', { 'svcpart'=>$1 } )
402 or die "unknown svcpart: $1";
403 $clone = $part_svc->svcpart;
404 $part_svc->svcpart('');
405 } elsif ( $cgi->keywords ) { #edit
406 my($query) = $cgi->keywords;
407 $query =~ /^(\d+)$/ or die "malformed query: $query";
408 $part_svc=qsearchs('part_svc', { 'svcpart'=>$1 } )
409 or die "unknown svcpart: $1";
411 $part_svc = new FS::part_svc {};
414 my $action = $part_svc->svcpart ? 'Edit' : 'Add';
415 my $hashref = $part_svc->hashref;
416 # my $p_svcdb = $part_svc->svcdb || 'svc_acct';
418 my %communigate_fields = (
419 'svc_acct' => { map { $_=>1 }
420 qw( file_quota file_maxnum file_maxsize
421 password_selfchange password_recover
423 grep /^cgp_/, fields('svc_acct')
425 'svc_domain' => { map { $_=>1 }
426 qw( max_accounts trailer parent_svcnum ),
427 grep /^(cgp|acct_def)_/, fields('svc_domain')
429 #'svc_forward' => { map { $_=>1 } qw( ) },
430 #'svc_mailinglist' => { map { $_=>1 } qw( ) },
431 #'svc_cert' => { map { $_=>1 } qw( ) },
437 <TH ALIGN="left">Generic</TH>
438 <TH ALIGN="left">Access</TH>
439 <TH ALIGN="left">Telephony</TH>
440 <!-- <TH>Hosting</TH>
446 <UL STYLE="margin:0">
447 <LI><B>svc_acct</B>: Accounts - anything with a username (mailbox, shell, RADIUS, etc.)
448 <LI><B>svc_hardware</B>: Equipment supplied to customers
449 <LI><B>svc_external</B>: Externally-tracked service
453 <UL STYLE="margin:0">
454 <LI><B>svc_dsl</B>: DSL
455 <LI><B>svc_broadband</B>: Wireless broadband
456 <LI><B>svc_dish</B>: DISH Network
460 <UL STYLE="margin:0">
461 <LI><B>svc_phone</B>: Customer phone number
462 <LI><B>svc_pbx</B>: Customer PBX
470 <TH ALIGN="left">Hosting</TH>
471 <TH ALIGN="left">Colocation</TH>
474 <UL STYLE="margin:0">
475 <LI><B>svc_domain</B>: Domain
476 <LI><B>svc_cert</B>: Certificate
477 <LI><B>svc_forward</B>: Mail forwarding
478 <LI><B>svc_mailinglist</B>: Mailing list
479 <LI><B>svc_www</B>: Virtual domain website
483 <UL STYLE="margin:0">
484 <LI><B>svc_port</B>: Customer router/switch port
489 <!-- <LI>svc_charge - One-time charges (Partially unimplemented)
490 <LI>svc_wo - Work orders (Partially unimplemented)
495 For the selected table, you can give fields default or fixed (unchangable)
496 values, or select an inventory class to manually or automatically fill in