finish existing customer dsl order, RT#7111
[freeside.git] / httemplate / edit / part_svc.cgi
1 <% include('/elements/header.html', "$action Service Definition",
2            menubar('View all service definitions' => "${p}browse/part_svc.cgi"),
3            #" onLoad=\"visualize()\""
4           )
5 %>
6
7 <FORM NAME="dummy">
8
9       Service Part #<% $part_svc->svcpart ? $part_svc->svcpart : "(NEW)" %>
10 <BR><BR>
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} %>">
14
15 <BR>
16
17
18 % #YUCK.  false laziness w/part_svc.pm.  go away virtual fields, please
19 % my %vfields;
20 % foreach my $svcdb ( FS::part_svc->svc_tables() ) {
21 %   eval "use FS::$svcdb;";
22 %   my $self = "FS::$svcdb"->new;
23 %   $vfields{$svcdb} = {};
24 %   foreach my $field ($self->virtual_fields) { # svc_Common::virtual_fields with a null svcpart returns all of them
25 %     my $pvf = $self->pvf($field);
26 %     $vfields{$svcdb}->{$field} = $pvf;
27 %     #warn "\$vfields{$svcdb}->{$field} = $pvf";
28 %   } #next $field
29 % } #next $svcdb
30 %
31 %  #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm
32 %  # and generalize the subs
33 %  # condition sub is tested to see whether to disable display of this choice
34 %  # params: ( $def, $layer, $field )  (see SUB below)
35 %  my $inv_sub = sub {
36 %                      $_[0]->{disable_inventory}
37 %                        || $_[0]->{'type'} ne 'text'
38 %                    };
39 %  tie my %flag, 'Tie::IxHash',
40 %    ''  => { 'desc' => 'No default', },
41 %    'D' => { 'desc' => 'Default',
42 %             'condition' =>
43 %               sub { $_[0]->{disable_default} }, 
44 %           },
45 %    'F' => { 'desc' => 'Fixed (unchangeable)',
46 %             'condition' =>
47 %               sub { $_[0]->{disable_fixed} }, 
48 %           },
49 %    'S' => { 'desc' => 'Selectable Choice',
50 %             'condition' =>
51 %               sub { !ref($_[0]) || $_[0]->{disable_select} }, 
52 %           },
53 %    'M' => { 'desc' => 'Manual selection from inventory',
54 %             'condition' => $inv_sub,
55 %           },
56 %    'A' => { 'desc' => 'Automatically fill in from inventory',
57 %             'condition' => $inv_sub,
58 %           },
59 %    'X' => { 'desc' => 'Excluded',
60 %             'condition' =>
61 %               sub { ! $vfields{$_[1]}->{$_[2]} },
62 %
63 %           },
64 %  ;
65 %  
66 %  my @dbs = $hashref->{svcdb}
67 %             ? ( $hashref->{svcdb} )
68 %             : FS::part_svc->svc_tables();
69 %
70 %  tie my %svcdb, 'Tie::IxHash', map { $_=>$_ } grep dbdef->table($_), @dbs;
71 %  my $widget = new HTML::Widgets::SelectLayers(
72 %    #'selected_layer' => $p_svcdb,
73 %    'selected_layer' => $hashref->{svcdb} || 'svc_acct',
74 %    'options'        => \%svcdb,
75 %    'form_name'      => 'dummy',
76 %    #'form_action'    => 'process/part_svc.cgi',
77 %    'form_action'    => 'part_svc.cgi', #self
78 %    'form_text'      => [ qw( svc svcpart ) ],
79 %    'form_checkbox'  => [ 'disabled' ],
80 %    'layer_callback' => sub {
81 %      my $layer = shift;
82 %      
83 %      my $html = qq!<INPUT TYPE="hidden" NAME="svcdb" VALUE="$layer">!;
84 %
85 %      $html .= $svcdb_info;
86 %
87 %      my $columns = 3;
88 %      my $count = 0;
89 %      my $communigate = 0;
90 %      my @part_export =
91 %        map { qsearch( 'part_export', {exporttype => $_ } ) }
92 %          keys %{FS::part_export::export_info($layer)};
93 %      $html .= '<BR><BR>'. table(). 
94 %               "<TR><TH COLSPAN=$columns>Exports</TH></TR><TR>";
95 %      foreach my $part_export ( @part_export ) {
96 %        $communigate++ if $part_export->exporttype =~ /^communigate/;
97 %        $html .= '<TD><INPUT TYPE="checkbox"'.
98 %                 ' NAME="exportnum'. $part_export->exportnum. '"  VALUE="1" ';
99 %        $html .= 'CHECKED'
100 %          if ( $clone || $part_svc->svcpart ) #null svcpart search causing error
101 %              && qsearchs( 'export_svc', {
102 %                                   exportnum => $part_export->exportnum,
103 %                                   svcpart   => $clone || $part_svc->svcpart });
104 %        $html .= '>'.$part_export->exportnum. ': ';
105 %        $html .= $part_export->exportname . '<DIV ALIGN="right"><FONT SIZE=-1>'
106 %          if ( $part_export->exportname );
107 %        $html .= $part_export->exporttype. ' to '. $part_export->machine;
108 %        $html .= '</FONT></DIV>' if ( $part_export->exportname );
109 %        $html .= '</TD>';
110 %        $count++;
111 %        $html .= '</TR><TR>' unless $count % $columns;
112 %      }
113 %      $html .= '</TR></TABLE><BR><BR>'. $mod_info;
114 %
115 %      $html .= include('/elements/table-grid.html', 'cellpadding' => 4 ).
116 %               '<TR>'.
117 %                 '<TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>'.
118 %                 '<TH CLASS="grid" BGCOLOR="#cccccc">Label</TH>'.
119 %                 '<TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>'.
120 %               '</TR>';
121 %
122 %      my $bgcolor1 = '#eeeeee';
123 %      my $bgcolor2 = '#ffffff';
124 %      my $bgcolor;
125 %
126 %      #yucky kludge
127 %      my @fields = ();
128 %      if ( defined( dbdef->table($layer) ) ) {
129 %        @fields = grep {
130 %            $_ ne 'svcnum'
131 %            && ( $communigate || !$communigate_fields{$layer}->{$_} )
132 %            && ( !FS::part_svc->svc_table_fields($layer)
133 %                   ->{$_}->{disable_part_svc_column}
134 %                 || $part_svc->part_svc_column($_)->columnflag
135 %               )
136 %        } fields($layer);
137 %      }
138 %      push @fields, 'usergroup' if $layer eq 'svc_acct'; #kludge
139 %      $part_svc->svcpart($clone) if $clone; #haha, undone below
140 %
141 %
142 %      foreach my $field (@fields) {
143 %
144 %        #a few lines of false laziness w/browse/part_svc.cgi
145 %        my $def = FS::part_svc->svc_table_fields($layer)->{$field};
146 %        my $def_info  = $def->{'def_info'};
147 %        my $formatter = $def->{'format'} || sub { shift };
148 %
149 %        my $part_svc_column = $part_svc->part_svc_column($field);
150 %        my $label = $part_svc_column->columnlabel || $def->{'label'};
151 %        my $value = &$formatter($part_svc_column->columnvalue);
152 %        my $flag  = $part_svc_column->columnflag;
153 %
154 %        if ( $bgcolor eq $bgcolor1 ) {
155 %          $bgcolor = $bgcolor2;
156 %        } else {
157 %          $bgcolor = $bgcolor1;
158 %        }
159 %        
160 %        $html .= qq!<TR><TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">!.
161 %                 ( $def->{'label'} || $field ).
162 %                 "</TD>";
163 %
164 %        $html .= qq!<TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor"><INPUT NAME="${layer}__${field}_label" VALUE="!. encode_entities($label). '" STYLE="text-align:right"></TD>';
165 %
166 %        $flag = '' if $def->{type} eq 'disabled';
167 %
168 %        $html .= qq!<TD CLASS="grid" BGCOLOR="$bgcolor">!;
169 %
170 %        if ( $def->{type} eq 'disabled' ) {
171 %        
172 %          $html .= 'No default';
173 %
174 %        } else {
175 %
176 %          $html .= qq!<SELECT NAME="${layer}__${field}_flag"!.
177 %                      qq! onChange="${layer}__${field}_flag_changed(this)">!;
178 %
179 %          foreach my $f ( keys %flag ) {
180 %
181 %            # need to template-ize more httemplate/edit/svc_* first
182 %            next if $f eq 'M' and $layer !~ /^svc_(broadband|external|phone)$/;
183 %
184 %            #here is where the SUB from above is called, to skip some choices
185 %            next if $flag{$f}->{condition}
186 %                 && &{ $flag{$f}->{condition} }( $def, $layer, $field );
187 %
188 %            $html .= qq!<OPTION VALUE="$f"!.
189 %                     ' SELECTED'x($flag eq $f ).
190 %                     '>'. $flag{$f}->{desc};
191 %
192 %          }
193 %
194 %          $html .= '</SELECT>';
195 %
196 %          $html .= join("\n",
197 %            '<SCRIPT>',
198 %            "  function ${layer}__${field}_flag_changed(what) {",
199 %            '    var f = what.options[what.selectedIndex].value;',
200 %            '    if ( f == "" || f == "X" ) { //disable',
201 %            "      what.form.${layer}__${field}.disabled = true;".
202 %            "      what.form.${layer}__${field}.style.backgroundColor = '#dddddd';".
203 %            "      if ( what.form.${layer}__${field}_classnum ) {".
204 %            "        what.form.${layer}__${field}_classnum.disabled = true;".
205 %            "        what.form.${layer}__${field}_classnum.style.backgroundColor = '#dddddd';".
206 %            "      }".
207 %            '    } else if ( f == "D" || f == "F" || f =="S" ) { //enable, text box',
208 %            "      what.form.${layer}__${field}.disabled = false;".
209 %            "      what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
210 %            "      if ( f == 'S' || '${field}' == 'usergroup' ) {". # kludge
211 %            "        what.form.${layer}__${field}.multiple = true;".
212 %            "      } else {".
213 %            "        what.form.${layer}__${field}.multiple = false;".
214 %            "      }".
215 %            "      what.form.${layer}__${field}.style.display = '';".
216 %            "      if ( what.form.${layer}__${field}_classnum ) {".
217 %            "        what.form.${layer}__${field}_classnum.disabled = false;".
218 %            "        what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
219 %            "        what.form.${layer}__${field}_classnum.style.display = 'none';".
220 %            "      }".
221 %            '    } else if ( f == "M" || f == "A" ) { //enable, inventory',
222 %            "      what.form.${layer}__${field}.disabled = false;".
223 %            "      what.form.${layer}__${field}.style.backgroundColor = '#ffffff';".
224 %            "      what.form.${layer}__${field}.style.display = 'none';".
225 %            "      if ( what.form.${layer}__${field}_classnum ) {".
226 %            "        what.form.${layer}__${field}_classnum.disabled = false;".
227 %            "        what.form.${layer}__${field}_classnum.style.backgroundColor = '#ffffff';".
228 %            "        what.form.${layer}__${field}_classnum.style.display = '';".
229 %            "      }".
230 %            '    }',
231 %            '  }',
232 %            '</SCRIPT>',
233 %          );
234 %
235 %        }
236 %
237 %        $html .= qq!</TD><TD CLASS="grid" BGCOLOR="$bgcolor">!;
238 %
239 %        my $disabled = $flag ? ''
240 %                             : 'DISABLED STYLE="background-color: #dddddd"';
241 %
242 %        if ( !$def->{type} || $def->{type} eq 'text' ) {
243 %
244 %          my $nodisplay = ' STYLE="display:none"';
245 %          my $is_inv = ( $flag =~ /^[MA]$/ );
246 %
247 %          $html .=
248 %            qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value" !.
249 %            $disabled.
250 %            ( $is_inv ? $nodisplay : $disabled ).
251 %            '>';
252 %
253 %          $html .= include('/elements/select-table.html',
254 %                             'element_name' => "${layer}__${field}_classnum",
255 %                             'element_etc'  => ( $is_inv
256 %                                                   ? $disabled
257 %                                                   : $nodisplay
258 %                                               ),
259 %                             'table'        => 'inventory_class',
260 %                             'name_col'     => 'classname',
261 %                             'value'        => $value,
262 %                             'empty_label'  => 'Select inventory class',
263 %                          );
264 %
265 %        } elsif ( $def->{type} eq 'checkbox' ) {
266 %
267 %          $html .= include('/elements/checkbox.html',
268 %                             'field'      => $layer.'__'.$field,
269 %                             'curr_value' => $value,
270 %                             'value'      => 'Y',
271 %                          );
272 %
273 %        } elsif ( $def->{type} eq 'select' ) {
274 %
275 %          $html .= qq!<SELECT NAME="${layer}__${field}" $disabled!;
276 %          $html .= ' MULTIPLE' if $flag eq 'S';
277 %          $html .= '>';
278 %          $html .= '<OPTION> </OPTION>' unless $value;
279 %          if ( $def->{select_table} ) {
280 %            foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
281 %              my $rvalue = $record->getfield($def->{select_key});
282 %              my $select_label = $def->{select_label};
283 %              $html .= qq!<OPTION VALUE="$rvalue"!.
284 %                  (grep(/^$rvalue$/, split(',',$value)) ? ' SELECTED>' : '>' ).
285 %                  $record->$select_label(). '</OPTION>';
286 %            } #next $record
287 %          } elsif ( $def->{select_list} ) {
288 %            foreach my $item ( @{$def->{select_list}} ) {
289 %              $html .= qq!<OPTION VALUE="$item"!.
290 %                    (grep(/^$item$/, split(',',$value)) ? ' SELECTED>' : '>' ).
291 %                    $item. '</OPTION>';
292 %            } #next $item
293 %          } elsif ( $def->{select_hash} ) {
294 %            if ( ref($def->{select_hash}) eq 'ARRAY' ) {
295 %              tie my %hash, 'Tie::IxHash', @{ $def->{select_hash} };
296 %              $def->{select_hash} = \%hash;
297 %            }
298 %            foreach my $key ( keys %{$def->{select_hash}} ) {
299 %              $html .= qq!<OPTION VALUE="$key"!.
300 %                    (grep(/^$key$/, split(',',$value)) ? ' SELECTED>' : '>' ).
301 %                    $def->{select_hash}{$key}. '</OPTION>';
302 %            } #next $key
303 %          } #endif
304 %          $html .= '</SELECT>';
305 %
306 %        } elsif ( $def->{type} eq 'textarea' ) {
307 %
308 %          $html .=
309 %            qq!<TEXTAREA NAME="${layer}__${field}">!. encode_entities($value).
310 %            '</TEXTAREA>';
311 %
312 %        } elsif ( $def->{type} eq 'select-svc_pbx.html' ) {
313 %
314 %          $html .= include('/elements/select-svc_pbx.html',
315 %                             'curr_value'   => $value,
316 %                             'element_name' => "${layer}__${field}",
317 %                             'element_etc'  => $disabled,
318 %                             'multiple'     => ($flag eq 'S'),
319 %                          );
320 %
321 %        } elsif ( $def->{type} eq 'select-lnp_status.html' ) {
322 %
323 %          $html .= include('/elements/select-lnp_status.html',
324 %                             'curr_value'   => $value,
325 %                             'element_name' => "${layer}__${field}",
326 %                             'element_etc'  => $disabled,
327 %                             'multiple'     => ($flag eq 'S'),
328 %                          );
329 %
330 %        } elsif ( $def->{type} eq 'radius_usergroup_selector' ) {
331 %
332 %          #XXX disable the RADIUS usergroup selector?  ugh it sure does need
333 %          #an overhaul, people have dum group problems because of it
334 %
335 %          $html .= FS::svc_acct::radius_usergroup_selector(
336 %            [ split(',', $value) ], "${layer}__${field}" );
337 %
338 %        } elsif ( $def->{type} eq 'communigate_pro-accessmodes' ) {
339 %
340 %          $html .= include('/elements/communigate_pro-accessmodes.html',
341 %                             'element_name_prefix' => "${layer}__${field}_",
342 %                             'curr_value'          => $value,
343 %                             #doesn't work#'element_etc'  => $disabled,
344 %                          );
345 %
346 %        } elsif ( $def->{type} eq 'disabled' ) {
347 %
348 %          $html .=
349 %            qq!<INPUT TYPE="hidden" NAME="${layer}__${field}" VALUE="">!;
350 %
351 %        } else {
352 %
353 %          $html .= '<font color="#ff0000">unknown type '. $def->{type};
354 %
355 %        }
356 %
357 %        $html .= "</TD></TR>\n";
358
359 %        $def_info = "($def_info)" if $def_info;
360 %        $html .=
361 %          qq!<TR>!.
362 %          qq!  <TD COLSPAN=2 BGCOLOR="$bgcolor" ALIGN="center" !.
363 %          qq!      STYLE="padding:0; border-top: none">!.
364 %          qq!    <FONT SIZE="-1"><I>$def_info</I></FONT>!.
365 %          qq!  </TD>!.
366 %          qq!</TR>\n!;
367 %
368 %      } #foreach my $field (@fields) {
369 %
370 %      $part_svc->svcpart('') if $clone; #undone
371 %      $html .= "</TABLE>";
372 %
373 %      $html .= include('/elements/progress-init.html',
374 %                         $layer, #form name
375 %                         [ qw(svc svcpart disabled exportnum), @fields ],
376 %                         'process/part_svc.cgi',
377 %                         $p.'browse/part_svc.cgi',
378 %                         $layer,
379 %                      );
380 %      $html .= '<BR><INPUT NAME="submit" TYPE="button" VALUE="'.
381 %               ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '" '.
382 %               ' onClick="document.'. "$layer.submit.disabled=true; ".
383 %               "fixup(document.$layer); $layer". 'process();">';
384 %
385 %      #$html .= '<BR><INPUT TYPE="submit" VALUE="'.
386 %      #         ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '">';
387 %
388 %      $html;
389 %
390 %    },
391 %  );
392 %
393 %
394
395 Table <% $widget->html %>
396
397 <% include('/elements/footer.html') %>
398
399 <%init>
400
401 die "access denied"
402   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
403
404 my $part_svc;
405 my $clone = '';
406 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {#clone
407   #$cgi->param('clone') =~ /^(\d+)$/ or die "malformed query: $query";
408   $part_svc = qsearchs('part_svc', { 'svcpart'=>$1 } )
409     or die "unknown svcpart: $1";
410   $clone = $part_svc->svcpart;
411   $part_svc->svcpart('');
412 } elsif ( $cgi->keywords ) { #edit
413   my($query) = $cgi->keywords;
414   $query =~ /^(\d+)$/ or die "malformed query: $query";
415   $part_svc=qsearchs('part_svc', { 'svcpart'=>$1 } )
416     or die "unknown svcpart: $1";
417 } else { #adding
418   $part_svc = new FS::part_svc {};
419 }
420
421 my $action = $part_svc->svcpart ? 'Edit' : 'Add';
422 my $hashref = $part_svc->hashref;
423 #   my $p_svcdb = $part_svc->svcdb || 'svc_acct';
424
425 my %communigate_fields = (
426   'svc_acct'        => { map { $_=>1 }
427                            qw( file_quota file_maxnum file_maxsize
428                                password_selfchange password_recover
429                              ),
430                            grep /^cgp_/, fields('svc_acct')
431                        },
432   'svc_domain'      => { map { $_=>1 }
433                            qw( max_accounts trailer parent_svcnum ),
434                            grep /^(cgp|acct_def)_/, fields('svc_domain')
435                        },
436   #'svc_forward'     => { map { $_=>1 } qw( ) },
437   #'svc_mailinglist' => { map { $_=>1 } qw( ) },
438   #'svc_cert'        => { map { $_=>1 } qw( ) },
439 );
440
441 my $svcdb_info = '
442 <TABLE>
443   <TR>
444     <TH ALIGN="left">Generic</TH>
445     <TH ALIGN="left">Access</TH>
446     <TH ALIGN="left">Telephony</TH>
447 <!--    <TH>Hosting</TH>
448     <TH>Colocation</TH>
449 -->
450   </TR>
451   <TR>
452     <TD VALIGN="top">
453       <UL STYLE="margin:0">
454         <LI><B>svc_acct</B>: Accounts - anything with a username (mailbox, shell, RADIUS, etc.)
455         <LI><B>svc_external</B>: Externally-tracked service
456       </UL>
457     </TD>
458     <TD VALIGN="top">
459       <UL STYLE="margin:0">
460         <LI><B>svc_dsl</B>: DSL
461         <LI><B>svc_broadband</B>: Wireless broadband
462       </UL>
463     </TD>
464     <TD VALIGN="top">
465       <UL STYLE="margin:0">
466         <LI><B>svc_phone</B>: Customer phone number
467         <LI><B>svc_pbx</B>: Customer PBX
468       </UL>
469     </TD>
470   </TR>
471 </TABLE>
472 <BR>
473 <TABLE>
474   <TR>
475     <TH ALIGN="left">Hosting</TH>
476     <TH ALIGN="left">Colocation</TH>
477   </TR>
478     <TD VALIGN="top">
479       <UL STYLE="margin:0">
480         <LI><B>svc_domain</B>: Domain
481         <LI><B>svc_cert</B>: Certificate
482         <LI><B>svc_forward</B>: Mail forwarding
483         <LI><B>svc_mailinglist</B>: Mailing list
484         <LI><B>svc_www</B>: Virtual domain website
485       </UL>
486     </TD>
487     <TD VALIGN="top">
488       <UL STYLE="margin:0">
489         <LI><B>svc_port</B>: Customer router/switch port
490       </UL>
491     </TD>
492   </TR>
493 <TABLE>
494 <!--   <LI>svc_charge - One-time charges (Partially unimplemented)
495        <LI>svc_wo - Work orders (Partially unimplemented)
496 -->
497 ';
498
499 my $mod_info = '
500 For the selected table, you can give fields default or fixed (unchangable)
501 values, or select an inventory class to manually or automatically fill in
502 that field.
503 ';
504
505 </%init>
506
507
508