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} %>">
15 Service definitions are the templates for items you offer to your customers.
16 <UL><LI>svc_acct - Accounts - anything with a username (Mailboxes, PPP accounts, shell accounts, RADIUS entries for broadband, etc.)
17 <LI>svc_domain - Domains
18 <LI>svc_cert - Certificates
20 <LI>svc_forward - Mail forwarding
21 <LI>svc_mailinglist - Mailing list
22 <LI>svc_www - Virtual domain website
23 <LI>svc_broadband - Broadband/High-speed Internet service (always-on)
24 <LI>svc_phone - Customer phone numbers
25 <LI>svc_pbx - Customer PBXs
26 <LI>svc_external - Externally-tracked service
27 <!-- <LI>svc_charge - One-time charges (Partially unimplemented)
28 <LI>svc_wo - Work orders (Partially unimplemented)
31 For the selected table, you can give fields default or fixed (unchangable)
32 values, or select an inventory class to manually or automatically fill in
36 % #YUCK. false laziness w/part_svc.pm. go away virtual fields, please
38 % foreach my $svcdb ( FS::part_svc->svc_tables() ) {
39 % eval "use FS::$svcdb;";
40 % my $self = "FS::$svcdb"->new;
41 % $vfields{$svcdb} = {};
42 % foreach my $field ($self->virtual_fields) { # svc_Common::virtual_fields with a null svcpart returns all of them
43 % my $pvf = $self->pvf($field);
44 % $vfields{$svcdb}->{$field} = $pvf;
45 % #warn "\$vfields{$svcdb}->{$field} = $pvf";
49 % #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm
50 % # and generalize the subs
51 % # condition sub is tested to see whether to disable display of this choice
52 % # params: ( $def, $layer, $field ) (see SUB below)
54 % $_[0]->{disable_inventory}
55 % || $_[0]->{'type'} ne 'text'
57 % tie my %flag, 'Tie::IxHash',
58 % '' => { 'desc' => 'No default', },
59 % 'D' => { 'desc' => 'Default',
61 % sub { $_[0]->{disable_default} },
63 % 'F' => { 'desc' => 'Fixed (unchangeable)',
65 % sub { $_[0]->{disable_fixed} },
67 % 'S' => { 'desc' => 'Selectable Choice',
69 % sub { !ref($_[0]) || $_[0]->{disable_select} },
71 % 'M' => { 'desc' => 'Manual selection from inventory',
72 % 'condition' => $inv_sub,
74 % 'A' => { 'desc' => 'Automatically fill in from inventory',
75 % 'condition' => $inv_sub,
77 % 'X' => { 'desc' => 'Excluded',
79 % sub { ! $vfields{$_[1]}->{$_[2]} },
84 % my @dbs = $hashref->{svcdb}
85 % ? ( $hashref->{svcdb} )
86 % : FS::part_svc->svc_tables();
88 % tie my %svcdb, 'Tie::IxHash', map { $_=>$_ } grep dbdef->table($_), @dbs;
89 % my $widget = new HTML::Widgets::SelectLayers(
90 % #'selected_layer' => $p_svcdb,
91 % 'selected_layer' => $hashref->{svcdb} || 'svc_acct',
92 % 'options' => \%svcdb,
93 % 'form_name' => 'dummy',
94 % #'form_action' => 'process/part_svc.cgi',
95 % 'form_action' => 'part_svc.cgi', #self
96 % 'form_text' => [ qw( svc svcpart ) ],
97 % 'form_checkbox' => [ 'disabled' ],
98 % 'layer_callback' => sub {
101 % my $html = qq!<INPUT TYPE="hidden" NAME="svcdb" VALUE="$layer">!;
105 % my $communigate = 0;
107 % map { qsearch( 'part_export', {exporttype => $_ } ) }
108 % keys %{FS::part_export::export_info($layer)};
109 % $html .= '<BR><BR>'. table().
110 % "<TR><TH COLSPAN=$columns>Exports</TH></TR><TR>";
111 % foreach my $part_export ( @part_export ) {
112 % $communigate++ if $part_export->exporttype =~ /^communigate/;
113 % $html .= '<TD><INPUT TYPE="checkbox"'.
114 % ' NAME="exportnum'. $part_export->exportnum. '" VALUE="1" ';
116 % if ( $clone || $part_svc->svcpart ) #null svcpart search causing error
117 % && qsearchs( 'export_svc', {
118 % exportnum => $part_export->exportnum,
119 % svcpart => $clone || $part_svc->svcpart });
120 % $html .= '>'.$part_export->exportnum. ': ';
121 % $html .= $part_export->exportname . '<DIV ALIGN="right"><FONT SIZE=-1>'
122 % if ( $part_export->exportname );
123 % $html .= $part_export->exporttype. ' to '. $part_export->machine;
124 % $html .= '</FONT></DIV>' if ( $part_export->exportname );
127 % $html .= '</TR><TR>' unless $count % $columns;
129 % $html .= '</TR></TABLE><BR><BR>';
131 % $html .= include('/elements/table-grid.html', 'cellpadding' => 4 ).
133 % '<TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>'.
134 % '<TH CLASS="grid" BGCOLOR="#cccccc">Label</TH>'.
135 % '<TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>'.
138 % my $bgcolor1 = '#eeeeee';
139 % my $bgcolor2 = '#ffffff';
144 % if ( defined( dbdef->table($layer) ) ) {
147 % && ( $communigate || !$communigate_fields{$layer}->{$_} )
148 % && ( !FS::part_svc->svc_table_fields($layer)
149 % ->{$_}->{disable_part_svc_column}
150 % || $part_svc->part_svc_column($_)->columnflag
154 % push @fields, 'usergroup' if $layer eq 'svc_acct'; #kludge
155 % $part_svc->svcpart($clone) if $clone; #haha, undone below
158 % foreach my $field (@fields) {
160 % #a few lines of false laziness w/browse/part_svc.cgi
161 % my $def = FS::part_svc->svc_table_fields($layer)->{$field};
162 % my $def_info = $def->{'def_info'};
163 % my $formatter = $def->{'format'} || sub { shift };
165 % my $part_svc_column = $part_svc->part_svc_column($field);
166 % my $label = $part_svc_column->columnlabel || $def->{'label'};
167 % my $value = &$formatter($part_svc_column->columnvalue);
168 % my $flag = $part_svc_column->columnflag;
170 % if ( $bgcolor eq $bgcolor1 ) {
171 % $bgcolor = $bgcolor2;
173 % $bgcolor = $bgcolor1;
176 % $html .= qq!<TR><TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">!.
177 % ( $def->{'label'} || $field ).
180 % $html .= qq!<TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor"><INPUT NAME="${layer}__${field}_label" VALUE="!. encode_entities($label). '" STYLE="text-align:right"></TD>';
182 % $flag = '' if $def->{type} eq 'disabled';
184 % $html .= qq!<TD CLASS="grid" BGCOLOR="$bgcolor">!;
186 % if ( $def->{type} eq 'disabled' ) {
188 % $html .= 'No default';
192 % $html .= qq!<SELECT NAME="${layer}__${field}_flag"!.
193 % qq! onChange="${layer}__${field}_flag_changed(this)">!;
195 % foreach my $f ( keys %flag ) {
197 % # need to template-ize more httemplate/edit/svc_* first
198 % next if $f eq 'M' and $layer !~ /^svc_(broadband|external|phone)$/;
200 % #here is where the SUB from above is called, to skip some choices
201 % next if $flag{$f}->{condition}
202 % && &{ $flag{$f}->{condition} }( $def, $layer, $field );
204 % $html .= qq!<OPTION VALUE="$f"!.
205 % ' SELECTED'x($flag eq $f ).
206 % '>'. $flag{$f}->{desc};
210 % $html .= '</SELECT>';
212 % $html .= join("\n",
214 % " function ${layer}__${field}_flag_changed(what) {",
215 % ' var f = what.options[what.selectedIndex].value;',
216 % ' if ( f == "" || f == "X" ) { //disable',
217 % " what.form.${layer}__${field}.disabled = true;".
218 % " what.form.${layer}__${field}.style.backgroundColor = '#dddddd';".
219 % " if ( what.form.${layer}__${field}_classnum ) {".
220 % " what.form.${layer}__${field}_classnum.disabled = true;".
221 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#dddddd';".
223 % ' } else if ( f == "D" || f == "F" || f =="S" ) { //enable, text box',
224 % " what.form.${layer}__${field}.disabled = false;".
225 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
226 % " if ( f == 'S' || '${field}' == 'usergroup' ) {". # kludge
227 % " what.form.${layer}__${field}.multiple = true;".
229 % " what.form.${layer}__${field}.multiple = false;".
231 % " what.form.${layer}__${field}.style.display = '';".
232 % " if ( what.form.${layer}__${field}_classnum ) {".
233 % " what.form.${layer}__${field}_classnum.disabled = false;".
234 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
235 % " what.form.${layer}__${field}_classnum.style.display = 'none';".
237 % ' } else if ( f == "M" || f == "A" ) { //enable, inventory',
238 % " what.form.${layer}__${field}.disabled = false;".
239 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
240 % " what.form.${layer}__${field}.style.display = 'none';".
241 % " if ( what.form.${layer}__${field}_classnum ) {".
242 % " what.form.${layer}__${field}_classnum.disabled = false;".
243 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
244 % " what.form.${layer}__${field}_classnum.style.display = '';".
253 % $html .= qq!</TD><TD CLASS="grid" BGCOLOR="$bgcolor">!;
255 % my $disabled = $flag ? ''
256 % : 'DISABLED STYLE="background-color: #dddddd"';
258 % if ( !$def->{type} || $def->{type} eq 'text' ) {
260 % my $nodisplay = ' STYLE="display:none"';
261 % my $is_inv = ( $flag =~ /^[MA]$/ );
264 % qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value" !.
266 % ( $is_inv ? $nodisplay : $disabled ).
269 % $html .= include('/elements/select-table.html',
270 % 'element_name' => "${layer}__${field}_classnum",
271 % 'element_etc' => ( $is_inv
275 % 'table' => 'inventory_class',
276 % 'name_col' => 'classname',
278 % 'empty_label' => 'Select inventory class',
281 % } elsif ( $def->{type} eq 'checkbox' ) {
283 % $html .= include('/elements/checkbox.html',
284 % 'field' => $layer.'__'.$field,
285 % 'curr_value' => $value,
289 % } elsif ( $def->{type} eq 'select' ) {
291 % $html .= qq!<SELECT NAME="${layer}__${field}" $disabled!;
292 % $html .= ' MULTIPLE' if $flag eq 'S';
294 % $html .= '<OPTION> </OPTION>' unless $value;
295 % if ( $def->{select_table} ) {
296 % foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
297 % my $rvalue = $record->getfield($def->{select_key});
298 % my $select_label = $def->{select_label};
299 % $html .= qq!<OPTION VALUE="$rvalue"!.
300 % (grep(/^$rvalue$/, split(',',$value)) ? ' SELECTED>' : '>' ).
301 % $record->$select_label(). '</OPTION>';
303 % } elsif ( $def->{select_list} ) {
304 % foreach my $item ( @{$def->{select_list}} ) {
305 % $html .= qq!<OPTION VALUE="$item"!.
306 % (grep(/^$item$/, split(',',$value)) ? ' SELECTED>' : '>' ).
307 % $item. '</OPTION>';
309 % } elsif ( $def->{select_hash} ) {
310 % if ( ref($def->{select_hash}) eq 'ARRAY' ) {
311 % tie my %hash, 'Tie::IxHash', @{ $def->{select_hash} };
312 % $def->{select_hash} = \%hash;
314 % foreach my $key ( keys %{$def->{select_hash}} ) {
315 % $html .= qq!<OPTION VALUE="$key"!.
316 % (grep(/^$key$/, split(',',$value)) ? ' SELECTED>' : '>' ).
317 % $def->{select_hash}{$key}. '</OPTION>';
320 % $html .= '</SELECT>';
322 % } elsif ( $def->{type} eq 'textarea' ) {
325 % qq!<TEXTAREA NAME="${layer}__${field}">!. encode_entities($value).
328 % } elsif ( $def->{type} eq 'select-svc_pbx.html' ) {
330 % $html .= include('/elements/select-svc_pbx.html',
331 % 'curr_value' => $value,
332 % 'element_name' => "${layer}__${field}",
333 % 'element_etc' => $disabled,
334 % 'multiple' => ($flag eq 'S'),
337 % } elsif ( $def->{type} eq 'radius_usergroup_selector' ) {
339 % #XXX disable the RADIUS usergroup selector? ugh it sure does need
340 % #an overhaul, people have dum group problems because of it
342 % $html .= FS::svc_acct::radius_usergroup_selector(
343 % [ split(',', $value) ], "${layer}__${field}" );
345 % } elsif ( $def->{type} eq 'communigate_pro-accessmodes' ) {
347 % $html .= include('/elements/communigate_pro-accessmodes.html',
348 % 'element_name_prefix' => "${layer}__${field}_",
349 % 'curr_value' => $value,
350 % #doesn't work#'element_etc' => $disabled,
353 % } elsif ( $def->{type} eq 'disabled' ) {
356 % qq!<INPUT TYPE="hidden" NAME="${layer}__${field}" VALUE="">!;
360 % $html .= '<font color="#ff0000">unknown type '. $def->{type};
364 % $html .= "</TD></TR>\n";
366 % $def_info = "($def_info)" if $def_info;
369 % qq! <TD COLSPAN=2 BGCOLOR="$bgcolor" ALIGN="center" !.
370 % qq! STYLE="padding:0; border-top: none">!.
371 % qq! <FONT SIZE="-1"><I>$def_info</I></FONT>!.
375 % } #foreach my $field (@fields) {
377 % $part_svc->svcpart('') if $clone; #undone
378 % $html .= "</TABLE>";
380 % $html .= include('/elements/progress-init.html',
382 % [ qw(svc svcpart disabled exportnum), @fields ],
383 % 'process/part_svc.cgi',
384 % $p.'browse/part_svc.cgi',
387 % $html .= '<BR><INPUT NAME="submit" TYPE="button" VALUE="'.
388 % ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '" '.
389 % ' onClick="document.'. "$layer.submit.disabled=true; ".
390 % "fixup(document.$layer); $layer". 'process();">';
392 % #$html .= '<BR><INPUT TYPE="submit" VALUE="'.
393 % # ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '">';
402 Table <% $widget->html %>
404 <% include('/elements/footer.html') %>
409 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
413 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {#clone
414 #$cgi->param('clone') =~ /^(\d+)$/ or die "malformed query: $query";
415 $part_svc = qsearchs('part_svc', { 'svcpart'=>$1 } )
416 or die "unknown svcpart: $1";
417 $clone = $part_svc->svcpart;
418 $part_svc->svcpart('');
419 } elsif ( $cgi->keywords ) { #edit
420 my($query) = $cgi->keywords;
421 $query =~ /^(\d+)$/ or die "malformed query: $query";
422 $part_svc=qsearchs('part_svc', { 'svcpart'=>$1 } )
423 or die "unknown svcpart: $1";
425 $part_svc = new FS::part_svc {};
428 my $action = $part_svc->svcpart ? 'Edit' : 'Add';
429 my $hashref = $part_svc->hashref;
430 # my $p_svcdb = $part_svc->svcdb || 'svc_acct';
432 my %communigate_fields = (
433 'svc_acct' => { map { $_=>1 }
434 qw( file_quota file_maxnum file_maxsize
435 password_selfchange password_recover
437 grep /^cgp_/, fields('svc_acct')
439 'svc_domain' => { map { $_=>1 }
440 qw( max_accounts trailer parent_svcnum ),
441 grep /^(cgp|acct_def)_/, fields('svc_domain')
443 #'svc_forward' => { map { $_=>1 } qw( ) },
444 #'svc_mailinglist' => { map { $_=>1 } qw( ) },
445 #'svc_cert' => { map { $_=>1 } qw( ) },