-w-safe and run under a 1.4 schema too
[freeside.git] / httemplate / edit / part_svc.cgi
index d4bb470..18319b3 100755 (executable)
@@ -65,6 +65,9 @@ blank <B>slipip</B> as well as a fixed shell something like <B>/bin/true</B> or
 <BR><BR>
 
 <%
+
+my %vfields;
+
 #these might belong somewhere else for other user interfaces 
 #pry need to eventually create stuff that's shared amount UIs
 my %defs = (
@@ -109,34 +112,48 @@ my %defs = (
     'dstsvc'    => 'service to which mail is to be forwarded',
     'dst'       => 'someone@another.domain.com to use when dstsvc is 0',
   },
-  'svc_charge' => {
-    'amount'    => 'amount',
-  },
-  'svc_wo' => {
-    'worker'    => 'Worker',
-    '_date'      => 'Date',
-  },
+#  'svc_charge' => {
+#    'amount'    => 'amount',
+#  },
+#  'svc_wo' => {
+#    'worker'    => 'Worker',
+#    '_date'      => 'Date',
+#  },
   'svc_www' => {
     #'recnum' => '',
     #'usersvc' => '',
   },
   'svc_broadband' => {
-    'actypenum' => 'This is the actypenum that refers to the type of AC that can be provisioned for this service.  This field must be set fixed.',
     'speed_down' => 'Maximum download speed for this service in Kbps.  0 denotes unlimited.',
     'speed_up' => 'Maximum upload speed for this service in Kbps.  0 denotes unlimited.',
-    'acnum' => 'acnum of a specific AC that this service is restricted to.  Not required',
     'ip_addr' => 'IP address.  Leave blank for automatic assignment.',
-    'ip_netmask' => 'Mask length, aka. netmask bits.  (Eg. 255.255.255.0 == 24)',
-    'mac_addr' => 'MAC address which is used by some ACs for access control.  Specified by 6 colon seperated hex octets. (Eg. 00:00:0a:bc:1a:2b)',
-    'location' => 'Defines the physically location at which this service was installed.  This is not necessarily the billing address',
+    'blocknum' => 'Address block.',
   },
 );
 
+  foreach my $svcdb (grep dbdef->table($_), keys %defs ) {
+    my $self = "FS::$svcdb"->new;
+    $vfields{$svcdb} = {};
+    foreach my $field ($self->virtual_fields) { # svc_Common::virtual_fields with a null svcpart returns all of them
+      my $pvf = $self->pvf($field);
+      my @list = $pvf->list;
+      if (scalar @list) {
+        $defs{$svcdb}->{$field} = { desc        => $pvf->label,
+                                    type        => 'select',
+                                    select_list => \@list };
+      } else {
+        $defs{$svcdb}->{$field} = $pvf->label;
+      } #endif
+      $vfields{$svcdb}->{$field} = $pvf;
+      warn "\$vfields{$svcdb}->{$field} = $pvf";
+    } #next $field
+  } #next $svcdb
+  
   my @dbs = $hashref->{svcdb}
              ? ( $hashref->{svcdb} )
              : qw( svc_acct svc_domain svc_forward svc_www svc_broadband );
 
-  tie my %svcdb, 'Tie::IxHash', map { $_=>$_ } @dbs;
+  tie my %svcdb, 'Tie::IxHash', map { $_=>$_ } grep dbdef->table($_), @dbs;
   my $widget = new HTML::Widgets::SelectLayers(
     #'selected_layer' => $p_svcdb,
     'selected_layer' => $hashref->{svcdb} || 'svc_acct',
@@ -157,7 +174,7 @@ my %defs = (
       $html .= '<BR><BR>'. table().
                table(). "<TR><TH COLSPAN=$columns>Exports</TH></TR><TR>";
       foreach my $part_export ( @part_export ) {
-        $html .= '<TD><INPUT TYPE="checkbox"'.
+        $html .= '<TD><INPUT TYPE="checbox"'.
                  ' NAME="exportnum'. $part_export->exportnum. '"  VALUE="1" ';
         $html .= 'CHECKED'
           if ( $clone || $part_svc->svcpart ) #null svcpart search causing error
@@ -202,19 +219,27 @@ my %defs = (
             qq!<INPUT TYPE="radio" NAME="${layer}__${field}_flag" VALUE="D"!.
             ' CHECKED'x($flag eq 'D'). ">Default ".
             qq!<INPUT TYPE="radio" NAME="${layer}__${field}_flag" VALUE="F"!.
-            ' CHECKED'x($flag eq 'F'). ">Fixed ".
-            '<BR>';
+            ' CHECKED'x($flag eq 'F'). ">Fixed ";
+          $html .= '<BR>';
         }
         if ( ref($def) ) {
           if ( $def->{type} eq 'select' ) {
             $html .= qq!<SELECT NAME="${layer}__${field}">!;
             $html .= '<OPTION> </OPTION>' unless $value;
-            foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
-              my $rvalue = $record->getfield($def->{select_key});
-              $html .= qq!<OPTION VALUE="$rvalue"!.
-                       ( $rvalue==$value ? ' SELECTED>' : '>' ).
-                       $record->getfield($def->{select_label}). '</OPTION>';
-            }
+            if ( $def->{select_table} ) {
+              foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
+                my $rvalue = $record->getfield($def->{select_key});
+                $html .= qq!<OPTION VALUE="$rvalue"!.
+                         ( $rvalue==$value ? ' SELECTED>' : '>' ).
+                         $record->getfield($def->{select_label}). '</OPTION>';
+              } #next $record
+            } else { # select_list
+              foreach my $item ( @{$def->{select_list}} ) {
+                $html .= qq!<OPTION VALUE="$item"!.
+                         ( $item eq $value ? ' SELECTED>' : '>' ).
+                         $item. '</OPTION>';
+              } #next $item
+            } #endif
             $html .= '</SELECT>';
           } elsif ( $def->{type} eq 'radius_usergroup_selector' ) {
             $html .= FS::svc_acct::radius_usergroup_selector(
@@ -229,6 +254,11 @@ my %defs = (
           $html .=
             qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value">!;
         }
+
+        if($vfields{$layer}->{$field}) {
+          $html .= qq!<BR><INPUT TYPE="radio" NAME="${layer}__${field}_flag" VALUE="X"!.
+          ' CHECKED'x($flag eq 'X'). ">Excluded ";
+        }
         $html .= "</TD></TR>\n";
       }
       $part_svc->svcpart('') if $clone; #undone