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' if $layer eq 'svc_acct'; #kludge
130 % $part_svc->svcpart($clone) if $clone; #haha, undone below
133 % foreach my $field (@fields) {
135 % #a few lines of false laziness w/browse/part_svc.cgi
136 % my $def = FS::part_svc->svc_table_fields($layer)->{$field};
137 % my $def_info = $def->{'def_info'};
138 % my $formatter = $def->{'format'} || sub { shift };
140 % my $part_svc_column = $part_svc->part_svc_column($field);
141 % my $label = $part_svc_column->columnlabel || $def->{'label'};
142 % my $value = &$formatter($part_svc_column->columnvalue);
143 % my $flag = $part_svc_column->columnflag;
145 % if ( $bgcolor eq $bgcolor1 ) {
146 % $bgcolor = $bgcolor2;
148 % $bgcolor = $bgcolor1;
151 % $html .= qq!<TR><TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">!.
152 % ( $def->{'label'} || $field ).
155 % $html .= qq!<TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor"><INPUT NAME="${layer}__${field}_label" VALUE="!. encode_entities($label). '" STYLE="text-align:right"></TD>';
157 % $flag = '' if $def->{type} eq 'disabled';
159 % $html .= qq!<TD CLASS="grid" BGCOLOR="$bgcolor">!;
161 % if ( $def->{type} eq 'disabled' ) {
163 % $html .= 'No default';
167 % $html .= qq!<SELECT NAME="${layer}__${field}_flag"!.
168 % qq! onChange="${layer}__${field}_flag_changed(this)">!;
170 % foreach my $f ( keys %flag ) {
172 % # need to template-ize more httemplate/edit/svc_* first
173 % next if $f eq 'M' and $layer !~ /^svc_(broadband|external|phone|dish)$/;
175 % #here is where the SUB from above is called, to skip some choices
176 % next if $flag{$f}->{condition}
177 % && &{ $flag{$f}->{condition} }( $def, $layer, $field );
179 % $html .= qq!<OPTION VALUE="$f"!.
180 % ' SELECTED'x($flag eq $f ).
181 % '>'. $flag{$f}->{desc};
185 % $html .= '</SELECT>';
187 % $html .= join("\n",
189 % " function ${layer}__${field}_flag_changed(what) {",
190 % ' var f = what.options[what.selectedIndex].value;',
191 % ' if ( f == "" || f == "X" ) { //disable',
192 % " what.form.${layer}__${field}.disabled = true;".
193 % " what.form.${layer}__${field}.style.backgroundColor = '#dddddd';".
194 % " if ( what.form.${layer}__${field}_classnum ) {".
195 % " what.form.${layer}__${field}_classnum.disabled = true;".
196 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#dddddd';".
198 % ' } else if ( f == "D" || f == "F" || f =="S" ) { //enable, text box',
199 % " what.form.${layer}__${field}.disabled = false;".
200 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
201 % " if ( f == 'S' || '${field}' == 'usergroup' ) {". # kludge
202 % " what.form.${layer}__${field}.multiple = true;".
204 % " what.form.${layer}__${field}.multiple = false;".
206 % " what.form.${layer}__${field}.style.display = '';".
207 % " if ( what.form.${layer}__${field}_classnum ) {".
208 % " what.form.${layer}__${field}_classnum.disabled = false;".
209 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
210 % " what.form.${layer}__${field}_classnum.style.display = 'none';".
212 % ' } else if ( f == "M" || f == "A" || f == "H" ) { '.
213 % '//enable, inventory',
214 % " what.form.${layer}__${field}.disabled = false;".
215 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
216 % " what.form.${layer}__${field}.style.display = 'none';".
217 % " if ( what.form.${layer}__${field}_classnum ) {".
218 % " what.form.${layer}__${field}_classnum.disabled = false;".
219 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
220 % " what.form.${layer}__${field}_classnum.style.display = '';".
229 % $html .= qq!</TD><TD CLASS="grid" BGCOLOR="$bgcolor">!;
231 % my $disabled = $flag ? ''
232 % : 'DISABLED STYLE="background-color: #dddddd"';
233 % my $nodisplay = ' STYLE="display:none"';
235 % if ( !$def->{type} || $def->{type} eq 'text' ) {
237 % my $is_inv = ( $flag =~ /^[MA]$/ );
240 % qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value" !.
242 % ( $is_inv ? $nodisplay : $disabled ).
245 % $html .= include('/elements/select-table.html',
246 % 'element_name' => "${layer}__${field}_classnum",
247 % 'element_etc' => ( $is_inv
251 % 'table' => 'inventory_class',
252 % 'name_col' => 'classname',
254 % 'empty_label' => 'Select inventory class',
257 % } elsif ( $def->{type} eq 'checkbox' ) {
259 % $html .= include('/elements/checkbox.html',
260 % 'field' => $layer.'__'.$field,
261 % 'curr_value' => $value,
265 % } elsif ( $def->{type} eq 'select' ) {
267 % $html .= qq!<SELECT NAME="${layer}__${field}" $disabled!;
268 % $html .= ' MULTIPLE' if $flag eq 'S';
270 % $html .= '<OPTION> </OPTION>' unless $value;
271 % if ( $def->{select_table} ) {
272 % foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
273 % my $rvalue = $record->getfield($def->{select_key});
274 % my $select_label = $def->{select_label};
275 % $html .= qq!<OPTION VALUE="$rvalue"!.
276 % (grep(/^$rvalue$/, split(',',$value)) ? ' SELECTED>' : '>' ).
277 % $record->$select_label(). '</OPTION>';
279 % } elsif ( $def->{select_list} ) {
280 % foreach my $item ( @{$def->{select_list}} ) {
281 % $html .= qq!<OPTION VALUE="$item"!.
282 % (grep(/^$item$/, split(',',$value)) ? ' SELECTED>' : '>' ).
283 % $item. '</OPTION>';
285 % } elsif ( $def->{select_hash} ) {
286 % if ( ref($def->{select_hash}) eq 'ARRAY' ) {
287 % tie my %hash, 'Tie::IxHash', @{ $def->{select_hash} };
288 % $def->{select_hash} = \%hash;
290 % foreach my $key ( keys %{$def->{select_hash}} ) {
291 % $html .= qq!<OPTION VALUE="$key"!.
292 % (grep(/^$key$/, split(',',$value)) ? ' SELECTED>' : '>' ).
293 % $def->{select_hash}{$key}. '</OPTION>';
296 % $html .= '</SELECT>';
298 % } elsif ( $def->{type} eq 'textarea' ) {
301 % qq!<TEXTAREA NAME="${layer}__${field}">!. encode_entities($value).
304 % } elsif ( $def->{type} =~ /select-(.*?).html/ ) {
306 % $html .= include("/elements/".$def->{type},
307 % 'curr_value' => $value,
308 % 'element_name' => "${layer}__${field}",
309 % 'element_etc' => $disabled,
310 % 'multiple' => ($flag eq 'S'),
313 % } elsif ( $def->{type} eq 'communigate_pro-accessmodes' ) {
315 % $html .= include('/elements/communigate_pro-accessmodes.html',
316 % 'element_name_prefix' => "${layer}__${field}_",
317 % 'curr_value' => $value,
318 % #doesn't work#'element_etc' => $disabled,
321 % } elsif ( $def->{type} eq 'select-hardware' ) {
323 % $html .= qq!<INPUT TYPE="text" NAME="${layer}__${field}" $disabled>!;
324 % $html .= include('/elements/select-hardware_class.html',
325 % 'curr_value' => $value,
326 % 'element_name' => "${layer}__${field}_classnum",
327 % 'element_etc' => $flag ne 'H' && $nodisplay,
328 % 'empty_label' => 'Select hardware class',
331 % } elsif ( $def->{type} eq 'disabled' ) {
334 % qq!<INPUT TYPE="hidden" NAME="${layer}__${field}" VALUE="">!;
338 % $html .= '<font color="#ff0000">unknown type '. $def->{type};
342 % $html .= "</TD></TR>\n";
344 % $def_info = "($def_info)" if $def_info;
347 % qq! <TD COLSPAN=2 BGCOLOR="$bgcolor" ALIGN="center" !.
348 % qq! STYLE="padding:0; border-top: none">!.
349 % qq! <FONT SIZE="-1"><I>$def_info</I></FONT>!.
353 % } #foreach my $field (@fields) {
355 % $part_svc->svcpart('') if $clone; #undone
356 % $html .= "</TABLE>";
358 % $html .= include('/elements/progress-init.html',
360 % [ qw(svc svcpart disabled preserve exportnum),
362 % 'process/part_svc.cgi',
363 % $p.'browse/part_svc.cgi',
366 % $html .= '<BR><INPUT NAME="submit" TYPE="button" VALUE="'.
367 % ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '" '.
368 % ' onClick="document.'. "$layer.submit.disabled=true; ".
369 % "fixup(document.$layer); $layer". 'process();">';
371 % #$html .= '<BR><INPUT TYPE="submit" VALUE="'.
372 % # ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '">';
381 Table <% $widget->html %>
383 <% include('/elements/footer.html') %>
388 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
392 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {#clone
393 #$cgi->param('clone') =~ /^(\d+)$/ or die "malformed query: $query";
394 $part_svc = qsearchs('part_svc', { 'svcpart'=>$1 } )
395 or die "unknown svcpart: $1";
396 $clone = $part_svc->svcpart;
397 $part_svc->svcpart('');
398 } elsif ( $cgi->keywords ) { #edit
399 my($query) = $cgi->keywords;
400 $query =~ /^(\d+)$/ or die "malformed query: $query";
401 $part_svc=qsearchs('part_svc', { 'svcpart'=>$1 } )
402 or die "unknown svcpart: $1";
404 $part_svc = new FS::part_svc {};
407 my $action = $part_svc->svcpart ? 'Edit' : 'Add';
408 my $hashref = $part_svc->hashref;
409 # my $p_svcdb = $part_svc->svcdb || 'svc_acct';
411 my %communigate_fields = (
412 'svc_acct' => { map { $_=>1 }
413 qw( file_quota file_maxnum file_maxsize
414 password_selfchange password_recover
416 grep /^cgp_/, fields('svc_acct')
418 'svc_domain' => { map { $_=>1 }
419 qw( max_accounts trailer parent_svcnum ),
420 grep /^(cgp|acct_def)_/, fields('svc_domain')
422 #'svc_forward' => { map { $_=>1 } qw( ) },
423 #'svc_mailinglist' => { map { $_=>1 } qw( ) },
424 #'svc_cert' => { map { $_=>1 } qw( ) },
430 <TH ALIGN="left">Generic</TH>
431 <TH ALIGN="left">Access</TH>
432 <TH ALIGN="left">Telephony</TH>
433 <!-- <TH>Hosting</TH>
439 <UL STYLE="margin:0">
440 <LI><B>svc_acct</B>: Accounts - anything with a username (mailbox, shell, RADIUS, etc.)
441 <LI><B>svc_hardware</B>: Equipment supplied to customers
442 <LI><B>svc_external</B>: Externally-tracked service
446 <UL STYLE="margin:0">
447 <LI><B>svc_dsl</B>: DSL
448 <LI><B>svc_broadband</B>: Wireless broadband
449 <LI><B>svc_dish</B>: DISH Network
453 <UL STYLE="margin:0">
454 <LI><B>svc_phone</B>: Customer phone number
455 <LI><B>svc_pbx</B>: Customer PBX
463 <TH ALIGN="left">Hosting</TH>
464 <TH ALIGN="left">Colocation</TH>
467 <UL STYLE="margin:0">
468 <LI><B>svc_domain</B>: Domain
469 <LI><B>svc_cert</B>: Certificate
470 <LI><B>svc_forward</B>: Mail forwarding
471 <LI><B>svc_mailinglist</B>: Mailing list
472 <LI><B>svc_www</B>: Virtual domain website
476 <UL STYLE="margin:0">
477 <LI><B>svc_port</B>: Customer router/switch port
482 <!-- <LI>svc_charge - One-time charges (Partially unimplemented)
483 <LI>svc_wo - Work orders (Partially unimplemented)
488 For the selected table, you can give fields default or fixed (unchangable)
489 values, or select an inventory class to manually or automatically fill in