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