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' if $layer eq 'svc_acct'; #kludge
143 % $part_svc->svcpart($clone) if $clone; #haha, undone below
146 % foreach my $field (@fields) {
148 % #a few lines of false laziness w/browse/part_svc.cgi
149 % my $def = FS::part_svc->svc_table_fields($layer)->{$field};
150 % my $def_info = $def->{'def_info'};
151 % my $formatter = $def->{'format'} || sub { shift };
153 % my $part_svc_column = $part_svc->part_svc_column($field);
154 % my $label = $part_svc_column->columnlabel || $def->{'label'};
155 % my $value = &$formatter($part_svc_column->columnvalue);
156 % my $flag = $part_svc_column->columnflag;
158 % if ( $bgcolor eq $bgcolor1 ) {
159 % $bgcolor = $bgcolor2;
161 % $bgcolor = $bgcolor1;
164 % $html .= qq!<TR><TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">!.
165 % ( $def->{'label'} || $field ).
168 % $html .= qq!<TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor"><INPUT NAME="${layer}__${field}_label" VALUE="!. encode_entities($label). '" STYLE="text-align:right"></TD>';
170 % $flag = '' if $def->{type} eq 'disabled';
172 % $html .= qq!<TD CLASS="grid" BGCOLOR="$bgcolor">!;
174 % if ( $def->{type} eq 'disabled' ) {
176 % $html .= 'No default';
180 % $html .= qq!<SELECT NAME="${layer}__${field}_flag"!.
181 % qq! onChange="${layer}__${field}_flag_changed(this)">!;
183 % foreach my $f ( keys %flag ) {
185 % # need to template-ize more httemplate/edit/svc_* first
186 % next if $f eq 'M' and $layer !~ /^svc_(broadband|external|phone|dish)$/;
188 % #here is where the SUB from above is called, to skip some choices
189 % next if $flag{$f}->{condition}
190 % && &{ $flag{$f}->{condition} }( $def, $layer, $field );
192 % $html .= qq!<OPTION VALUE="$f"!.
193 % ' SELECTED'x($flag eq $f ).
194 % '>'. $flag{$f}->{desc};
198 % $html .= '</SELECT>';
200 % $html .= join("\n",
202 % " function ${layer}__${field}_flag_changed(what) {",
203 % ' var f = what.options[what.selectedIndex].value;',
204 % ' if ( f == "" || f == "X" ) { //disable',
205 % " what.form.${layer}__${field}.disabled = true;".
206 % " what.form.${layer}__${field}.style.backgroundColor = '#dddddd';".
207 % " if ( what.form.${layer}__${field}_classnum ) {".
208 % " what.form.${layer}__${field}_classnum.disabled = true;".
209 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#dddddd';".
211 % ' } else if ( f == "D" || f == "F" || f =="S" ) { //enable, text box',
212 % " what.form.${layer}__${field}.disabled = false;".
213 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
214 % " if ( f == 'S' || '${field}' == 'usergroup' ) {". # kludge
215 % " what.form.${layer}__${field}.multiple = true;".
217 % " what.form.${layer}__${field}.multiple = false;".
219 % " what.form.${layer}__${field}.style.display = '';".
220 % " if ( what.form.${layer}__${field}_classnum ) {".
221 % " what.form.${layer}__${field}_classnum.disabled = false;".
222 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
223 % " what.form.${layer}__${field}_classnum.style.display = 'none';".
225 % ' } else if ( f == "M" || f == "A" || f == "H" ) { '.
226 % '//enable, inventory',
227 % " what.form.${layer}__${field}.disabled = false;".
228 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
229 % " what.form.${layer}__${field}.style.display = 'none';".
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 = '';".
242 % $html .= qq!</TD><TD CLASS="grid" BGCOLOR="$bgcolor">!;
244 % my $disabled = $flag ? ''
245 % : 'DISABLED STYLE="background-color: #dddddd"';
246 % my $nodisplay = ' STYLE="display:none"';
248 % if ( !$def->{type} || $def->{type} eq 'text' ) {
250 % my $is_inv = ( $flag =~ /^[MA]$/ );
253 % qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value" !.
255 % ( $is_inv ? $nodisplay : $disabled ).
258 % $html .= include('/elements/select-table.html',
259 % 'element_name' => "${layer}__${field}_classnum",
260 % 'element_etc' => ( $is_inv
264 % 'table' => 'inventory_class',
265 % 'name_col' => 'classname',
267 % 'empty_label' => 'Select inventory class',
270 % } elsif ( $def->{type} eq 'checkbox' ) {
272 % $html .= include('/elements/checkbox.html',
273 % 'field' => $layer.'__'.$field,
274 % 'curr_value' => $value,
278 % } elsif ( $def->{type} eq 'select' ) {
280 % $html .= qq!<SELECT NAME="${layer}__${field}" $disabled!;
281 % $html .= ' MULTIPLE' if $flag eq 'S';
283 % $html .= '<OPTION> </OPTION>' unless $value;
284 % if ( $def->{select_table} ) {
285 % foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
286 % my $rvalue = $record->getfield($def->{select_key});
287 % my $select_label = $def->{select_label};
288 % $html .= qq!<OPTION VALUE="$rvalue"!.
289 % (grep(/^$rvalue$/, split(',',$value)) ? ' SELECTED>' : '>' ).
290 % $record->$select_label(). '</OPTION>';
292 % } elsif ( $def->{select_list} ) {
293 % foreach my $item ( @{$def->{select_list}} ) {
294 % $html .= qq!<OPTION VALUE="$item"!.
295 % (grep(/^$item$/, split(',',$value)) ? ' SELECTED>' : '>' ).
296 % $item. '</OPTION>';
298 % } elsif ( $def->{select_hash} ) {
299 % if ( ref($def->{select_hash}) eq 'ARRAY' ) {
300 % tie my %hash, 'Tie::IxHash', @{ $def->{select_hash} };
301 % $def->{select_hash} = \%hash;
303 % foreach my $key ( keys %{$def->{select_hash}} ) {
304 % $html .= qq!<OPTION VALUE="$key"!.
305 % (grep(/^$key$/, split(',',$value)) ? ' SELECTED>' : '>' ).
306 % $def->{select_hash}{$key}. '</OPTION>';
309 % $html .= '</SELECT>';
311 % } elsif ( $def->{type} eq 'textarea' ) {
314 % qq!<TEXTAREA NAME="${layer}__${field}">!. encode_entities($value).
317 % } elsif ( $def->{type} =~ /select-(.*?).html/ ) {
319 % $html .= include("/elements/".$def->{type},
320 % 'curr_value' => $value,
321 % 'element_name' => "${layer}__${field}",
322 % 'element_etc' => $disabled,
323 % 'multiple' => ($flag eq 'S'),
326 % } elsif ( $def->{type} eq 'communigate_pro-accessmodes' ) {
328 % $html .= include('/elements/communigate_pro-accessmodes.html',
329 % 'element_name_prefix' => "${layer}__${field}_",
330 % 'curr_value' => $value,
331 % #doesn't work#'element_etc' => $disabled,
334 % } elsif ( $def->{type} eq 'select-hardware' ) {
336 % $html .= qq!<INPUT TYPE="text" NAME="${layer}__${field}" $disabled>!;
337 % $html .= include('/elements/select-hardware_class.html',
338 % 'curr_value' => $value,
339 % 'element_name' => "${layer}__${field}_classnum",
340 % 'element_etc' => $flag ne 'H' && $nodisplay,
341 % 'empty_label' => 'Select hardware class',
344 % } elsif ( $def->{type} eq 'disabled' ) {
347 % qq!<INPUT TYPE="hidden" NAME="${layer}__${field}" VALUE="">!;
351 % $html .= '<font color="#ff0000">unknown type '. $def->{type};
355 % $html .= "</TD></TR>\n";
357 % $def_info = "($def_info)" if $def_info;
360 % qq! <TD COLSPAN=2 BGCOLOR="$bgcolor" ALIGN="center" !.
361 % qq! STYLE="padding:0; border-top: none">!.
362 % qq! <FONT SIZE="-1"><I>$def_info</I></FONT>!.
366 % } #foreach my $field (@fields) {
368 % $part_svc->svcpart('') if $clone; #undone
369 % $html .= "</TABLE>";
371 % $html .= include('/elements/progress-init.html',
373 % [ qw(svc svcpart disabled preserve exportnum),
375 % 'process/part_svc.cgi',
376 % $p.'browse/part_svc.cgi',
379 % $html .= '<BR><INPUT NAME="submit" TYPE="button" VALUE="'.
380 % ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '" '.
381 % ' onClick="document.'. "$layer.submit.disabled=true; ".
382 % "fixup(document.$layer); $layer". 'process();">';
384 % #$html .= '<BR><INPUT TYPE="submit" VALUE="'.
385 % # ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '">';
394 Table <% $widget->html %>
396 <% include('/elements/footer.html') %>
401 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
405 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {#clone
406 #$cgi->param('clone') =~ /^(\d+)$/ or die "malformed query: $query";
407 $part_svc = qsearchs('part_svc', { 'svcpart'=>$1 } )
408 or die "unknown svcpart: $1";
409 $clone = $part_svc->svcpart;
410 $part_svc->svcpart('');
411 } elsif ( $cgi->keywords ) { #edit
412 my($query) = $cgi->keywords;
413 $query =~ /^(\d+)$/ or die "malformed query: $query";
414 $part_svc=qsearchs('part_svc', { 'svcpart'=>$1 } )
415 or die "unknown svcpart: $1";
417 $part_svc = new FS::part_svc {};
420 my $action = $part_svc->svcpart ? 'Edit' : 'Add';
421 my $hashref = $part_svc->hashref;
422 # my $p_svcdb = $part_svc->svcdb || 'svc_acct';
424 my %communigate_fields = (
425 'svc_acct' => { map { $_=>1 }
426 qw( file_quota file_maxnum file_maxsize
427 password_selfchange password_recover
429 grep /^cgp_/, fields('svc_acct')
431 'svc_domain' => { map { $_=>1 }
432 qw( max_accounts trailer parent_svcnum ),
433 grep /^(cgp|acct_def)_/, fields('svc_domain')
435 #'svc_forward' => { map { $_=>1 } qw( ) },
436 #'svc_mailinglist' => { map { $_=>1 } qw( ) },
437 #'svc_cert' => { map { $_=>1 } qw( ) },
443 <TH ALIGN="left">Generic</TH>
444 <TH ALIGN="left">Access</TH>
445 <TH ALIGN="left">Telephony</TH>
446 <!-- <TH>Hosting</TH>
452 <UL STYLE="margin:0">
453 <LI><B>svc_acct</B>: Accounts - anything with a username (mailbox, shell, RADIUS, etc.)
454 <LI><B>svc_hardware</B>: Equipment supplied to customers
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
462 <LI><B>svc_dish</B>: DISH Network
466 <UL STYLE="margin:0">
467 <LI><B>svc_phone</B>: Customer phone number
468 <LI><B>svc_pbx</B>: Customer PBX
476 <TH ALIGN="left">Hosting</TH>
477 <TH ALIGN="left">Colocation</TH>
480 <UL STYLE="margin:0">
481 <LI><B>svc_domain</B>: Domain
482 <LI><B>svc_cert</B>: Certificate
483 <LI><B>svc_forward</B>: Mail forwarding
484 <LI><B>svc_mailinglist</B>: Mailing list
485 <LI><B>svc_www</B>: Virtual domain website
489 <UL STYLE="margin:0">
490 <LI><B>svc_port</B>: Customer router/switch port
495 <!-- <LI>svc_charge - One-time charges (Partially unimplemented)
496 <LI>svc_wo - Work orders (Partially unimplemented)
501 For the selected table, you can give fields default or fixed (unchangable)
502 values, or select an inventory class to manually or automatically fill in