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
19 <LI>svc_forward - Mail forwarding
20 <LI>svc_mailinglist - Mailing list
21 <LI>svc_www - Virtual domain website
22 <LI>svc_broadband - Broadband/High-speed Internet service (always-on)
23 <LI>svc_phone - Customer phone numbers
24 <LI>svc_pbx - Customer PBXs
25 <LI>svc_external - Externally-tracked service
26 <!-- <LI>svc_charge - One-time charges (Partially unimplemented)
27 <LI>svc_wo - Work orders (Partially unimplemented)
30 For the selected table, you can give fields default or fixed (unchangable)
31 values, or select an inventory class to manually or automatically fill in
35 % #YUCK. false laziness w/part_svc.pm. go away virtual fields, please
37 % foreach my $svcdb ( FS::part_svc->svc_tables() ) {
38 % eval "use FS::$svcdb;";
39 % my $self = "FS::$svcdb"->new;
40 % $vfields{$svcdb} = {};
41 % foreach my $field ($self->virtual_fields) { # svc_Common::virtual_fields with a null svcpart returns all of them
42 % my $pvf = $self->pvf($field);
43 % $vfields{$svcdb}->{$field} = $pvf;
44 % #warn "\$vfields{$svcdb}->{$field} = $pvf";
48 % #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm
49 % # and generalize the subs
50 % # condition sub is tested to see whether to disable display of this choice
51 % # params: ( $def, $layer, $field ) (see SUB below)
53 % $_[0]->{disable_inventory}
54 % || $_[0]->{'type'} ne 'text'
56 % tie my %flag, 'Tie::IxHash',
57 % '' => { 'desc' => 'No default', },
58 % 'D' => { 'desc' => 'Default',
60 % sub { $_[0]->{disable_default} },
62 % 'F' => { 'desc' => 'Fixed (unchangeable)',
64 % sub { $_[0]->{disable_fixed} },
66 % 'S' => { 'desc' => 'Selectable Choice',
68 % sub { !ref($_[0]) || $_[0]->{disable_select} },
70 % 'M' => { 'desc' => 'Manual selection from inventory',
71 % 'condition' => $inv_sub,
73 % 'A' => { 'desc' => 'Automatically fill in from inventory',
74 % 'condition' => $inv_sub,
76 % 'X' => { 'desc' => 'Excluded',
78 % sub { ! $vfields{$_[1]}->{$_[2]} },
83 % my @dbs = $hashref->{svcdb}
84 % ? ( $hashref->{svcdb} )
85 % : FS::part_svc->svc_tables();
87 % tie my %svcdb, 'Tie::IxHash', map { $_=>$_ } grep dbdef->table($_), @dbs;
88 % my $widget = new HTML::Widgets::SelectLayers(
89 % #'selected_layer' => $p_svcdb,
90 % 'selected_layer' => $hashref->{svcdb} || 'svc_acct',
91 % 'options' => \%svcdb,
92 % 'form_name' => 'dummy',
93 % #'form_action' => 'process/part_svc.cgi',
94 % 'form_action' => 'part_svc.cgi', #self
95 % 'form_text' => [ qw( svc svcpart ) ],
96 % 'form_checkbox' => [ 'disabled' ],
97 % 'layer_callback' => sub {
100 % my $html = qq!<INPUT TYPE="hidden" NAME="svcdb" VALUE="$layer">!;
105 % map { qsearch( 'part_export', {exporttype => $_ } ) }
106 % keys %{FS::part_export::export_info($layer)};
107 % $html .= '<BR><BR>'. table().
108 % "<TR><TH COLSPAN=$columns>Exports</TH></TR><TR>";
109 % foreach my $part_export ( @part_export ) {
110 % $html .= '<TD><INPUT TYPE="checkbox"'.
111 % ' NAME="exportnum'. $part_export->exportnum. '" VALUE="1" ';
113 % if ( $clone || $part_svc->svcpart ) #null svcpart search causing error
114 % && qsearchs( 'export_svc', {
115 % exportnum => $part_export->exportnum,
116 % svcpart => $clone || $part_svc->svcpart });
117 % $html .= '>'.$part_export->exportnum. ': ';
118 % $html .= $part_export->exportname . '<DIV ALIGN="right"><FONT SIZE=-1>'
119 % if ( $part_export->exportname );
120 % $html .= $part_export->exporttype. ' to '. $part_export->machine;
121 % $html .= '</FONT></DIV>' if ( $part_export->exportname );
124 % $html .= '</TR><TR>' unless $count % $columns;
126 % $html .= '</TR></TABLE><BR><BR>';
128 % $html .= include('/elements/table-grid.html', 'cellpadding' => 4 ).
130 % '<TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>'.
131 % '<TH CLASS="grid" BGCOLOR="#cccccc">Label</TH>'.
132 % '<TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>'.
135 % my $bgcolor1 = '#eeeeee';
136 % my $bgcolor2 = '#ffffff';
140 % my @fields = defined( dbdef->table($layer) )
143 % ( !FS::part_svc->svc_table_fields($layer)
144 % ->{$_}->{disable_part_svc_column} ||
145 % $part_svc->part_svc_column($_)->columnflag
150 % push @fields, 'usergroup' if $layer eq 'svc_acct'; #kludge
151 % $part_svc->svcpart($clone) if $clone; #haha, undone below
154 % foreach my $field (@fields) {
156 % #a few lines of false laziness w/browse/part_svc.cgi
157 % my $def = FS::part_svc->svc_table_fields($layer)->{$field};
158 % my $def_info = $def->{'def_info'};
159 % my $formatter = $def->{'format'} || sub { shift };
161 % my $part_svc_column = $part_svc->part_svc_column($field);
162 % my $label = $part_svc_column->columnlabel || $def->{'label'};
163 % my $value = &$formatter($part_svc_column->columnvalue);
164 % my $flag = $part_svc_column->columnflag;
166 % if ( $bgcolor eq $bgcolor1 ) {
167 % $bgcolor = $bgcolor2;
169 % $bgcolor = $bgcolor1;
172 % $html .= qq!<TR><TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">!.
173 % ( $def->{'label'} || $field ).
176 % $html .= qq!<TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor"><INPUT NAME="${layer}__${field}_label" VALUE="!. encode_entities($label). '" STYLE="text-align:right"></TD>';
178 % $flag = '' if $def->{type} eq 'disabled';
180 % $html .= qq!<TD CLASS="grid" BGCOLOR="$bgcolor">!;
182 % if ( $def->{type} eq 'disabled' ) {
184 % $html .= 'No default';
188 % $html .= qq!<SELECT NAME="${layer}__${field}_flag"!.
189 % qq! onChange="${layer}__${field}_flag_changed(this)">!;
191 % foreach my $f ( keys %flag ) {
193 % # need to template-ize more httemplate/edit/svc_* first
194 % next if $f eq 'M' and $layer !~ /^svc_(broadband|external|phone)$/;
196 % #here is where the SUB from above is called, to skip some choices
197 % next if $flag{$f}->{condition}
198 % && &{ $flag{$f}->{condition} }( $def, $layer, $field );
200 % $html .= qq!<OPTION VALUE="$f"!.
201 % ' SELECTED'x($flag eq $f ).
202 % '>'. $flag{$f}->{desc};
206 % $html .= '</SELECT>';
208 % $html .= join("\n",
210 % " function ${layer}__${field}_flag_changed(what) {",
211 % ' var f = what.options[what.selectedIndex].value;',
212 % ' if ( f == "" || f == "X" ) { //disable',
213 % " what.form.${layer}__${field}.disabled = true;".
214 % " what.form.${layer}__${field}.style.backgroundColor = '#dddddd';".
215 % " if ( what.form.${layer}__${field}_classnum ) {".
216 % " what.form.${layer}__${field}_classnum.disabled = true;".
217 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#dddddd';".
219 % ' } else if ( f == "D" || f == "F" || f =="S" ) { //enable, text box',
220 % " what.form.${layer}__${field}.disabled = false;".
221 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
222 % " if ( f == 'S' || '${field}' == 'usergroup' ) {". # kludge
223 % " what.form.${layer}__${field}.multiple = true;".
225 % " what.form.${layer}__${field}.multiple = false;".
227 % " what.form.${layer}__${field}.style.display = '';".
228 % " if ( what.form.${layer}__${field}_classnum ) {".
229 % " what.form.${layer}__${field}_classnum.disabled = false;".
230 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
231 % " what.form.${layer}__${field}_classnum.style.display = 'none';".
233 % ' } else if ( f == "M" || f == "A" ) { //enable, inventory',
234 % " what.form.${layer}__${field}.disabled = false;".
235 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
236 % " what.form.${layer}__${field}.style.display = 'none';".
237 % " if ( what.form.${layer}__${field}_classnum ) {".
238 % " what.form.${layer}__${field}_classnum.disabled = false;".
239 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
240 % " what.form.${layer}__${field}_classnum.style.display = '';".
249 % $html .= qq!</TD><TD CLASS="grid" BGCOLOR="$bgcolor">!;
251 % my $disabled = $flag ? ''
252 % : 'DISABLED STYLE="background-color: #dddddd"';
254 % if ( !$def->{type} || $def->{type} eq 'text' ) {
256 % my $nodisplay = ' STYLE="display:none"';
257 % my $is_inv = ( $flag =~ /^[MA]$/ );
260 % qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value" !.
262 % ( $is_inv ? $nodisplay : $disabled ).
265 % $html .= include('/elements/select-table.html',
266 % 'element_name' => "${layer}__${field}_classnum",
267 % 'element_etc' => ( $is_inv
271 % 'table' => 'inventory_class',
272 % 'name_col' => 'classname',
274 % 'empty_label' => 'Select inventory class',
277 % } elsif ( $def->{type} eq 'checkbox' ) {
279 % $html .= include('/elements/checkbox.html',
280 % 'field' => $layer.'__'.$field,
281 % 'curr_value' => $value,
285 % } elsif ( $def->{type} eq 'select' ) {
287 % $html .= qq!<SELECT NAME="${layer}__${field}" $disabled!;
288 % $html .= ' MULTIPLE' if $flag eq 'S';
290 % $html .= '<OPTION> </OPTION>' unless $value;
291 % if ( $def->{select_table} ) {
292 % foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
293 % my $rvalue = $record->getfield($def->{select_key});
294 % my $select_label = $def->{select_label};
295 % $html .= qq!<OPTION VALUE="$rvalue"!.
296 % (grep(/^$rvalue$/, split(',',$value)) ? ' SELECTED>' : '>' ).
297 % $record->$select_label(). '</OPTION>';
299 % } elsif ( $def->{select_list} ) {
300 % foreach my $item ( @{$def->{select_list}} ) {
301 % $html .= qq!<OPTION VALUE="$item"!.
302 % (grep(/^$item$/, split(',',$value)) ? ' SELECTED>' : '>' ).
303 % $item. '</OPTION>';
305 % } elsif ( $def->{select_hash} ) {
306 % if ( ref($def->{select_hash}) eq 'ARRAY' ) {
307 % tie my %hash, 'Tie::IxHash', @{ $def->{select_hash} };
308 % $def->{select_hash} = \%hash;
310 % foreach my $key ( keys %{$def->{select_hash}} ) {
311 % $html .= qq!<OPTION VALUE="$key"!.
312 % (grep(/^$key$/, split(',',$value)) ? ' SELECTED>' : '>' ).
313 % $def->{select_hash}{$key}. '</OPTION>';
316 % $html .= '</SELECT>';
318 % } elsif ( $def->{type} eq 'textarea' ) {
321 % qq!<TEXTAREA NAME="${layer}__${field}">!. encode_entities($value).
324 % } elsif ( $def->{type} eq 'select-svc_pbx.html' ) {
326 % $html .= include('/elements/select-svc_pbx.html',
327 % 'curr_value' => $value,
328 % 'element_name' => "${layer}__${field}",
329 % 'element_etc' => $disabled,
330 % 'multiple' => ($flag eq 'S'),
333 % } elsif ( $def->{type} eq 'radius_usergroup_selector' ) {
335 % #XXX disable the RADIUS usergroup selector? ugh it sure does need
336 % #an overhaul, people have dum group problems because of it
338 % $html .= FS::svc_acct::radius_usergroup_selector(
339 % [ split(',', $value) ], "${layer}__${field}" );
341 % } elsif ( $def->{type} eq 'communigate_pro-accessmodes' ) {
343 % $html .= include('/elements/communigate_pro-accessmodes.html',
344 % 'element_name_prefix' => "${layer}__${field}_",
345 % 'curr_value' => $value,
346 % #doesn't work#'element_etc' => $disabled,
349 % } elsif ( $def->{type} eq 'disabled' ) {
352 % qq!<INPUT TYPE="hidden" NAME="${layer}__${field}" VALUE="">!;
356 % $html .= '<font color="#ff0000">unknown type '. $def->{type};
360 % $html .= "</TD></TR>\n";
362 % $def_info = "($def_info)" if $def_info;
365 % qq! <TD COLSPAN=2 BGCOLOR="$bgcolor" ALIGN="center" !.
366 % qq! STYLE="padding:0; border-top: none">!.
367 % qq! <FONT SIZE="-1"><I>$def_info</I></FONT>!.
371 % } #foreach my $field (@fields) {
373 % $part_svc->svcpart('') if $clone; #undone
374 % $html .= "</TABLE>";
376 % $html .= include('/elements/progress-init.html',
378 % [ qw(svc svcpart disabled exportnum), @fields ],
379 % 'process/part_svc.cgi',
380 % $p.'browse/part_svc.cgi',
383 % $html .= '<BR><INPUT NAME="submit" TYPE="button" VALUE="'.
384 % ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '" '.
385 % ' onClick="document.'. "$layer.submit.disabled=true; ".
386 % "fixup(document.$layer); $layer". 'process();">';
388 % #$html .= '<BR><INPUT TYPE="submit" VALUE="'.
389 % # ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '">';
398 Table <% $widget->html %>
400 <% include('/elements/footer.html') %>
405 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
409 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {#clone
410 #$cgi->param('clone') =~ /^(\d+)$/ or die "malformed query: $query";
411 $part_svc = qsearchs('part_svc', { 'svcpart'=>$1 } )
412 or die "unknown svcpart: $1";
413 $clone = $part_svc->svcpart;
414 $part_svc->svcpart('');
415 } elsif ( $cgi->keywords ) { #edit
416 my($query) = $cgi->keywords;
417 $query =~ /^(\d+)$/ or die "malformed query: $query";
418 $part_svc=qsearchs('part_svc', { 'svcpart'=>$1 } )
419 or die "unknown svcpart: $1";
421 $part_svc = new FS::part_svc {};
424 my $action = $part_svc->svcpart ? 'Edit' : 'Add';
425 my $hashref = $part_svc->hashref;
426 # my $p_svcdb = $part_svc->svcdb || 'svc_acct';