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