4 %if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {#clone
5 % #$cgi->param('clone') =~ /^(\d+)$/ or die "malformed query: $query";
6 % $part_svc = qsearchs('part_svc', { 'svcpart'=>$1 } )
7 % or die "unknown svcpart: $1";
8 % $clone = $part_svc->svcpart;
9 % $part_svc->svcpart('');
10 %} elsif ( $cgi->keywords ) { #edit
11 % my($query) = $cgi->keywords;
12 % $query =~ /^(\d+)$/ or die "malformed query: $query";
13 % $part_svc=qsearchs('part_svc', { 'svcpart'=>$1 } )
14 % or die "unknown svcpart: $1";
16 % $part_svc = new FS::part_svc {};
19 %my $action = $part_svc->svcpart ? 'Edit' : 'Add';
20 %my $hashref = $part_svc->hashref;
21 %# my $p_svcdb = $part_svc->svcdb || 'svc_acct';
24 % #" onLoad=\"visualize()\""
27 <% include("/elements/header.html","$action Service Definition",
28 menubar( 'Main Menu' => $p,
29 'View all service definitions' => "${p}browse/part_svc.cgi"
36 Service Part #<% $part_svc->svcpart ? $part_svc->svcpart : "(NEW)" %>
38 Service <INPUT TYPE="text" NAME="svc" VALUE="<% $hashref->{svc} %>"><BR>
39 Disable new orders <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>><BR>
40 <INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $hashref->{svcpart} %>">
42 Service definitions are the templates for items you offer to your customers.
43 <UL><LI>svc_acct - Accounts - anything with a username (Mailboxes, PPP accounts, shell accounts, RADIUS entries for broadband, etc.)
44 <LI>svc_domain - Domains
45 <LI>svc_forward - mail forwarding
46 <LI>svc_www - Virtual domain website
47 <LI>svc_broadband - Broadband/High-speed Internet service (always-on)
48 <LI>svc_phone - Customer phone numbers
49 <LI>svc_external - Externally-tracked service
50 <!-- <LI>svc_charge - One-time charges (Partially unimplemented)
51 <LI>svc_wo - Work orders (Partially unimplemented)
54 For the selected table, you can give fields default or fixed (unchangable)
55 values, or select an inventory class to manually or automatically fill in
59 % #YUCK. false laziness w/part_svc.pm. go away virtual fields, please
61 % foreach my $svcdb ( FS::part_svc->svc_tables() ) {
62 % eval "use FS::$svcdb;";
63 % my $self = "FS::$svcdb"->new;
64 % $vfields{$svcdb} = {};
65 % foreach my $field ($self->virtual_fields) { # svc_Common::virtual_fields with a null svcpart returns all of them
66 % my $pvf = $self->pvf($field);
67 % $vfields{$svcdb}->{$field} = $pvf;
68 % #warn "\$vfields{$svcdb}->{$field} = $pvf";
72 % #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm
73 % # and generalize the subs
74 % # condition sub is tested to see whether to disable display of this choice
75 % # params: ( $def, $layer, $field ) (see SUB below)
77 % $_[0]->{disable_inventory}
78 % || $_[0]->{'type'} ne 'text'
80 % tie my %flag, 'Tie::IxHash',
81 % '' => { 'desc' => 'No default', },
82 % 'D' => { 'desc' => 'Default',
84 % sub { $_[0]->{disable_default} },
86 % 'F' => { 'desc' => 'Fixed (unchangeable)',
88 % sub { $_[0]->{disable_fixed} },
90 % 'S' => { 'desc' => 'Selectable Choice',
92 % sub { !ref($_[0]) || $_[0]->{disable_select} },
94 %# need to template-ize httemplate/edit/svc_* first
95 %# 'M' => { 'desc' => 'Manual selection from inventory',
96 %# 'condition' => $inv_sub,
98 % 'A' => { 'desc' => 'Automatically fill in from inventory',
99 % 'condition' => $inv_sub,
101 % 'X' => { 'desc' => 'Excluded',
103 % sub { ! $vfields{$_[1]}->{$_[2]} },
108 % my @dbs = $hashref->{svcdb}
109 % ? ( $hashref->{svcdb} )
110 % : FS::part_svc->svc_tables();
112 % tie my %svcdb, 'Tie::IxHash', map { $_=>$_ } grep dbdef->table($_), @dbs;
113 % my $widget = new HTML::Widgets::SelectLayers(
114 % #'selected_layer' => $p_svcdb,
115 % 'selected_layer' => $hashref->{svcdb} || 'svc_acct',
116 % 'options' => \%svcdb,
117 % 'form_name' => 'dummy',
118 % #'form_action' => 'process/part_svc.cgi',
119 % 'form_action' => 'part_svc.cgi', #self
120 % 'form_text' => [ qw( svc svcpart ) ],
121 % 'form_checkbox' => [ 'disabled' ],
122 % 'layer_callback' => sub {
125 % my $html = qq!<INPUT TYPE="hidden" NAME="svcdb" VALUE="$layer">!;
130 % map { qsearch( 'part_export', {exporttype => $_ } ) }
131 % keys %{FS::part_export::export_info($layer)};
132 % $html .= '<BR><BR>'. table().
133 % "<TR><TH COLSPAN=$columns>Exports</TH></TR><TR>";
134 % foreach my $part_export ( @part_export ) {
135 % $html .= '<TD><INPUT TYPE="checkbox"'.
136 % ' NAME="exportnum'. $part_export->exportnum. '" VALUE="1" ';
138 % if ( $clone || $part_svc->svcpart ) #null svcpart search causing error
139 % && qsearchs( 'export_svc', {
140 % exportnum => $part_export->exportnum,
141 % svcpart => $clone || $part_svc->svcpart });
142 % $html .= '>'. $part_export->exportnum. ': '. $part_export->exporttype.
143 % ' to '. $part_export->machine. '</TD>';
145 % $html .= '</TR><TR>' unless $count % $columns;
147 % $html .= '</TR></TABLE><BR><BR>';
149 % $html .= include('/elements/table-grid.html', 'cellpadding' => 4 ).
151 % '<TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>'.
152 % '<TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>'.
155 % my $bgcolor1 = '#eeeeee';
156 % my $bgcolor2 = '#ffffff';
160 % my @fields = defined( dbdef->table($layer) )
161 % ? grep { $_ ne 'svcnum' } fields($layer)
163 % push @fields, 'usergroup' if $layer eq 'svc_acct'; #kludge
164 % $part_svc->svcpart($clone) if $clone; #haha, undone below
167 % foreach my $field (@fields) {
169 % #my $def = $defs{$layer}{$field};
170 % my $def = FS::part_svc->svc_table_fields($layer)->{$field};
171 % my $label = $def->{'def_label'} || $def->{'label'};
172 % my $formatter = $def->{'format'} || sub { shift };
173 % my $part_svc_column = $part_svc->part_svc_column($field);
174 % my $value = &$formatter($part_svc_column->columnvalue);
175 % my $flag = $part_svc_column->columnflag;
177 % if ( $bgcolor eq $bgcolor1 ) {
178 % $bgcolor = $bgcolor2;
180 % $bgcolor = $bgcolor1;
183 % $html .= qq!<TR><TD CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">!.
184 % ( $label || $field ).
186 % $flag = '' if $def->{type} eq 'disabled';
188 % $html .= qq!<TD CLASS="grid" BGCOLOR="$bgcolor">!;
190 % if ( $def->{type} eq 'disabled' ) {
192 % $html .= 'No default';
196 % $html .= qq!<SELECT NAME="${layer}__${field}_flag"!.
197 % qq! onChange="${layer}__${field}_flag_changed(this)">!;
199 % foreach my $f ( keys %flag ) {
201 % #here is where the SUB from above is called, to skip some choices
202 % next if $flag{$f}->{condition}
203 % && &{ $flag{$f}->{condition} }( $def, $layer, $field );
205 % $html .= qq!<OPTION VALUE="$f"!.
206 % ' SELECTED'x($flag eq $f ).
207 % '>'. $flag{$f}->{desc};
211 % $html .= '</SELECT>';
213 % $html .= join("\n",
215 % " function ${layer}__${field}_flag_changed(what) {",
216 % ' var f = what.options[what.selectedIndex].value;',
217 % ' if ( f == "" || f == "X" ) { //disable',
218 % " what.form.${layer}__${field}.disabled = true;".
219 % " what.form.${layer}__${field}.style.backgroundColor = '#dddddd';".
220 % " if ( what.form.${layer}__${field}_classnum ) {".
221 % " what.form.${layer}__${field}_classnum.disabled = true;".
222 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#dddddd';".
224 % ' } else if ( f == "D" || f == "F" || f =="S" ) { //enable, text box',
225 % " what.form.${layer}__${field}.disabled = false;".
226 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
227 % " if ( f == 'S' || '${field}' == 'usergroup' ) {". # kludge
228 % " what.form.${layer}__${field}.multiple = true;".
230 % " what.form.${layer}__${field}.multiple = false;".
232 % " what.form.${layer}__${field}.style.display = '';".
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 = 'none';".
238 % ' } else if ( f == "M" || f == "A" ) { //enable, inventory',
239 % " what.form.${layer}__${field}.disabled = false;".
240 % " what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
241 % " what.form.${layer}__${field}.style.display = 'none';".
242 % " if ( what.form.${layer}__${field}_classnum ) {".
243 % " what.form.${layer}__${field}_classnum.disabled = false;".
244 % " what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
245 % " what.form.${layer}__${field}_classnum.style.display = '';".
254 % $html .= qq!</TD><TD CLASS="grid" BGCOLOR="$bgcolor">!;
256 % my $disabled = $flag ? ''
257 % : 'DISABLED STYLE="background-color: #dddddd"';
259 % if ( !$def->{type} || $def->{type} eq 'text' ) {
261 % my $nodisplay = ' STYLE="display:none"';
262 % my $is_inv = ( $flag =~ /^[MA]$/ );
265 % qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value" !.
267 % ( $is_inv ? $nodisplay : $disabled ).
270 % $html .= include('/elements/select-table.html',
271 % 'element_name' => "${layer}__${field}_classnum",
272 % 'element_etc' => ( $is_inv
276 % 'table' => 'inventory_class',
277 % 'name_col' => 'classname',
279 % 'empty_label' => 'Select inventory class',
282 % } elsif ( $def->{type} eq 'select' ) {
284 % $html .= qq!<SELECT NAME="${layer}__${field}" $disabled!;
285 % $html .= ' MULTIPLE' if $flag eq 'S';
287 % $html .= '<OPTION> </OPTION>' unless $value;
288 % if ( $def->{select_table} ) {
289 % foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
290 % my $rvalue = $record->getfield($def->{select_key});
291 % $html .= qq!<OPTION VALUE="$rvalue"!.
292 % (grep(/^$rvalue$/, split(',',$value)) ? ' SELECTED>' : '>' ).
293 % $record->getfield($def->{select_label}). '</OPTION>';
295 % } else { # select_list
296 % foreach my $item ( @{$def->{select_list}} ) {
297 % $html .= qq!<OPTION VALUE="$item"!.
298 % (grep(/^$item$/, split(',',$value)) ? ' SELECTED>' : '>' ).
299 % $item. '</OPTION>';
302 % $html .= '</SELECT>';
304 % } elsif ( $def->{type} eq 'radius_usergroup_selector' ) {
306 % #XXX disable the RADIUS usergroup selector? ugh it sure does need
307 % #an overhaul, people have dum group problems because of it
309 % $html .= FS::svc_acct::radius_usergroup_selector(
310 % [ split(',', $value) ], "${layer}__${field}" );
312 % } elsif ( $def->{type} eq 'disabled' ) {
315 % qq!<INPUT TYPE="hidden" NAME="${layer}__${field}" VALUE="">!;
319 % $html .= '<font color="#ff0000">unknown type'. $def->{type};
323 % $html .= "</TD></TR>\n";
325 % } #foreach my $field (@fields) {
327 % $part_svc->svcpart('') if $clone; #undone
328 % $html .= "</TABLE>";
330 % $html .= include('/elements/progress-init.html',
332 % [ qw(svc svcpart disabled exportnum), @fields ],
333 % 'process/part_svc.cgi',
334 % $p.'browse/part_svc.cgi',
337 % $html .= '<BR><INPUT NAME="submit" TYPE="button" VALUE="'.
338 % ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '" '.
339 % ' onClick="document.'. "$layer.submit.disabled=true; ".
340 % "fixup(document.$layer); $layer". 'process();">';
342 % #$html .= '<BR><INPUT TYPE="submit" VALUE="'.
343 % # ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '">';
352 Table <% $widget->html %>