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