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. ': '. $part_export->exporttype.
118 % ' to '. $part_export->machine. '</TD>';
120 % $html .= '</TR><TR>' unless $count % $columns;
122 % $html .= '</TR></TABLE><BR><BR>';
124 % $html .= include('/elements/table-grid.html', 'cellpadding' => 4 ).
126 % '<TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>'.
127 % '<TH CLASS="grid" BGCOLOR="#cccccc">Label</TH>'.
128 % '<TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>'.
131 % my $bgcolor1 = '#eeeeee';
132 % my $bgcolor2 = '#ffffff';
136 % my @fields = defined( dbdef->table($layer) )
139 % ( !FS::part_svc->svc_table_fields($layer)
140 % ->{$_}->{disable_part_svc_column} ||
141 % $part_svc->part_svc_column($_)->columnflag
146 % push @fields, 'usergroup' if $layer eq 'svc_acct'; #kludge
147 % $part_svc->svcpart($clone) if $clone; #haha, undone below
150 % foreach my $field (@fields) {
152 % #a few lines of false laziness w/browse/part_svc.cgi
153 % my $def = FS::part_svc->svc_table_fields($layer)->{$field};
154 % my $def_info = $def->{'def_info'};
155 % my $formatter = $def->{'format'} || sub { shift };
157 % my $part_svc_column = $part_svc->part_svc_column($field);
158 % my $label = $part_svc_column->columnlabel || $def->{'label'};
159 % my $value = &$formatter($part_svc_column->columnvalue);
160 % my $flag = $part_svc_column->columnflag;
162 % if ( $bgcolor eq $bgcolor1 ) {
163 % $bgcolor = $bgcolor2;
165 % $bgcolor = $bgcolor1;
168 % $html .= qq!<TR><TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">!.
169 % ( $def->{'label'} || $field ).
172 % $html .= qq!<TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor"><INPUT NAME="${layer}__${field}_label" VALUE="!. encode_entities($label). '" STYLE="text-align:right"></TD>';
174 % $flag = '' if $def->{type} eq 'disabled';
176 % $html .= qq!<TD CLASS="grid" BGCOLOR="$bgcolor">!;
178 % if ( $def->{type} eq 'disabled' ) {
180 % $html .= 'No default';
184 % $html .= qq!<SELECT NAME="${layer}__${field}_flag"!.
185 % qq! onChange="${layer}__${field}_flag_changed(this)">!;
187 % foreach my $f ( keys %flag ) {
189 % # need to template-ize more httemplate/edit/svc_* first
190 % next if $f eq 'M' and $layer !~ /^svc_(broadband|external|phone)$/;
192 % #here is where the SUB from above is called, to skip some choices
193 % next if $flag{$f}->{condition}
194 % && &{ $flag{$f}->{condition} }( $def, $layer, $field );
196 % $html .= qq!<OPTION VALUE="$f"!.
197 % ' SELECTED'x($flag eq $f ).
198 % '>'. $flag{$f}->{desc};
202 % $html .= '</SELECT>';
204 % $html .= join("\n",
206 % " function ${layer}__${field}_flag_changed(what) {",
207 % ' var f = what.options[what.selectedIndex].value;',
208 % ' if ( f == "" || f == "X" ) { //disable',
209 % " what.form.${layer}__${field}.disabled = true;".
210 % " what.form.${layer}__${field}.style.backgroundColor = '#dddddd';".
211 % " if ( what.form.${layer}__${field}_classnum ) {".
212 % " what.form.${layer}__${field}_classnum.disabled = true;".
213 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#dddddd';".
215 % ' } else if ( f == "D" || f == "F" || f =="S" ) { //enable, text box',
216 % " what.form.${layer}__${field}.disabled = false;".
217 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
218 % " if ( f == 'S' || '${field}' == 'usergroup' ) {". # kludge
219 % " what.form.${layer}__${field}.multiple = true;".
221 % " what.form.${layer}__${field}.multiple = false;".
223 % " what.form.${layer}__${field}.style.display = '';".
224 % " if ( what.form.${layer}__${field}_classnum ) {".
225 % " what.form.${layer}__${field}_classnum.disabled = false;".
226 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
227 % " what.form.${layer}__${field}_classnum.style.display = 'none';".
229 % ' } else if ( f == "M" || f == "A" ) { //enable, inventory',
230 % " what.form.${layer}__${field}.disabled = false;".
231 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
232 % " what.form.${layer}__${field}.style.display = 'none';".
233 % " if ( what.form.${layer}__${field}_classnum ) {".
234 % " what.form.${layer}__${field}_classnum.disabled = false;".
235 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
236 % " what.form.${layer}__${field}_classnum.style.display = '';".
245 % $html .= qq!</TD><TD CLASS="grid" BGCOLOR="$bgcolor">!;
247 % my $disabled = $flag ? ''
248 % : 'DISABLED STYLE="background-color: #dddddd"';
250 % if ( !$def->{type} || $def->{type} eq 'text' ) {
252 % my $nodisplay = ' STYLE="display:none"';
253 % my $is_inv = ( $flag =~ /^[MA]$/ );
256 % qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value" !.
258 % ( $is_inv ? $nodisplay : $disabled ).
261 % $html .= include('/elements/select-table.html',
262 % 'element_name' => "${layer}__${field}_classnum",
263 % 'element_etc' => ( $is_inv
267 % 'table' => 'inventory_class',
268 % 'name_col' => 'classname',
270 % 'empty_label' => 'Select inventory class',
273 % } elsif ( $def->{type} eq 'checkbox' ) {
275 % $html .= include('/elements/checkbox.html',
276 % 'field' => $layer.'__'.$field,
277 % 'curr_value' => $value,
281 % } elsif ( $def->{type} eq 'select' ) {
283 % $html .= qq!<SELECT NAME="${layer}__${field}" $disabled!;
284 % $html .= ' MULTIPLE' if $flag eq 'S';
286 % $html .= '<OPTION> </OPTION>' unless $value;
287 % if ( $def->{select_table} ) {
288 % foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
289 % my $rvalue = $record->getfield($def->{select_key});
290 % my $select_label = $def->{select_label};
291 % $html .= qq!<OPTION VALUE="$rvalue"!.
292 % (grep(/^$rvalue$/, split(',',$value)) ? ' SELECTED>' : '>' ).
293 % $record->$select_label(). '</OPTION>';
295 % } elsif ( $def->{select_list} ) {
296 % foreach my $item ( @{$def->{select_list}} ) {
297 % $html .= qq!<OPTION VALUE="$item"!.
298 % (grep(/^$item$/, split(',',$value)) ? ' SELECTED>' : '>' ).
299 % $item. '</OPTION>';
301 % } elsif ( $def->{select_hash} ) {
302 % if ( ref($def->{select_hash}) eq 'ARRAY' ) {
303 % tie my %hash, 'Tie::IxHash', @{ $def->{select_hash} };
304 % $def->{select_hash} = \%hash;
306 % foreach my $key ( keys %{$def->{select_hash}} ) {
307 % $html .= qq!<OPTION VALUE="$key"!.
308 % (grep(/^$key$/, split(',',$value)) ? ' SELECTED>' : '>' ).
309 % $def->{select_hash}{$key}. '</OPTION>';
312 % $html .= '</SELECT>';
314 % } elsif ( $def->{type} eq 'textarea' ) {
317 % qq!<TEXTAREA NAME="${layer}__${field}">!. encode_entities($value).
320 % } elsif ( $def->{type} eq 'select-svc_pbx.html' ) {
322 % $html .= include('/elements/select-svc_pbx.html',
323 % 'curr_value' => $value,
324 % 'element_name' => "${layer}__${field}",
325 % 'element_etc' => $disabled,
326 % 'multiple' => ($flag eq 'S'),
329 % } elsif ( $def->{type} eq 'radius_usergroup_selector' ) {
331 % #XXX disable the RADIUS usergroup selector? ugh it sure does need
332 % #an overhaul, people have dum group problems because of it
334 % $html .= FS::svc_acct::radius_usergroup_selector(
335 % [ split(',', $value) ], "${layer}__${field}" );
337 % } elsif ( $def->{type} eq 'communigate_pro-accessmodes' ) {
339 % $html .= include('/elements/communigate_pro-accessmodes.html',
340 % 'element_name_prefix' => "${layer}__${field}_",
341 % 'curr_value' => $value,
342 % #doesn't work#'element_etc' => $disabled,
345 % } elsif ( $def->{type} eq 'disabled' ) {
348 % qq!<INPUT TYPE="hidden" NAME="${layer}__${field}" VALUE="">!;
352 % $html .= '<font color="#ff0000">unknown type '. $def->{type};
356 % $html .= "</TD></TR>\n";
358 % $def_info = "($def_info)" if $def_info;
361 % qq! <TD COLSPAN=2 BGCOLOR="$bgcolor" ALIGN="center" !.
362 % qq! STYLE="padding:0; border-top: none">!.
363 % qq! <FONT SIZE="-1"><I>$def_info</I></FONT>!.
367 % } #foreach my $field (@fields) {
369 % $part_svc->svcpart('') if $clone; #undone
370 % $html .= "</TABLE>";
372 % $html .= include('/elements/progress-init.html',
374 % [ qw(svc svcpart disabled exportnum), @fields ],
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';