backport select_list changes from 1.5 so the fix for #118 works in 1.4 branch too
[freeside.git] / httemplate / edit / part_svc.cgi
index b4900a0..ce8c463 100755 (executable)
@@ -1,10 +1,17 @@
 <!-- mason kludge -->
 <% 
    my $part_svc;
+   my $clone = '';
    if ( $cgi->param('error') ) { #error
      $part_svc = new FS::part_svc ( {
        map { $_, scalar($cgi->param($_)) } fields('part_svc')
      } );
+   } elsif ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {#clone
+     #$cgi->param('clone') =~ /^(\d+)$/ or die "malformed query: $query";
+     $part_svc = qsearchs('part_svc', { 'svcpart'=>$1 } )
+       or die "unknown svcpart: $1";
+     $clone = $part_svc->svcpart;
+     $part_svc->svcpart('');
    } elsif ( $cgi->keywords ) { #edit
      my($query) = $cgi->keywords;
      $query =~ /^(\d+)$/ or die "malformed query: $query";
@@ -60,6 +67,7 @@ blank <B>slipip</B> as well as a fixed shell something like <B>/bin/true</B> or
 <%
 #these might belong somewhere else for other user interfaces 
 #pry need to eventually create stuff that's shared amount UIs
+my $conf = new FS::Conf;
 my %defs = (
   'svc_acct' => {
     'dir'       => 'Home directory',
@@ -73,11 +81,18 @@ my %defs = (
                      select_key   => 'popnum',
                      select_label => 'city',
                    },
-    'username'  => 'Username',
+    'username'  => {
+                      desc => 'Username',
+                      type => 'disabled',
+                   },
     'quota'     => '',
     '_password' => 'Password',
     'gid'       => 'GID (when blank, defaults to UID)',
-    'shell'     => 'Shell (all service definitions should have a default or fixed shell that is present in the <b>shells</b> configuration file)',
+    'shell'     => {
+                     desc =>'Shell (all service definitions should have a default or fixed shell that is present in the <b>shells</b> configuration file)',
+                     type =>'select',
+                     select_list => [ $conf->config('shells') ],
+                   },
     'finger'    => 'GECOS',
     'domsvc'    => {
                      desc =>'svcnum from svc_domain',
@@ -132,13 +147,37 @@ my %defs = (
     'form_checkbox'  => [ 'disabled' ],
     'layer_callback' => sub {
       my $layer = shift;
-      my $html = qq!<INPUT TYPE="hidden" NAME="svcdb" VALUE="$layer">!.
-                 table(). "<TH>Field</TH><TH COLSPAN=2>Modifier</TH>";
+      my $html = qq!<INPUT TYPE="hidden" NAME="svcdb" VALUE="$layer">!;
+
+      my $columns = 3;
+      my $count = 0;
+      my @part_export =
+        map { qsearch( 'part_export', {exporttype => $_ } ) }
+          keys %{FS::part_export::export_info($layer)};
+      $html .= '<BR><BR>'. table().
+               table(). "<TR><TH COLSPAN=$columns>Exports</TH></TR><TR>";
+      foreach my $part_export ( @part_export ) {
+        $html .= '<TD><INPUT TYPE="checkbox"'.
+                 ' NAME="exportnum'. $part_export->exportnum. '"  VALUE="1" ';
+        $html .= 'CHECKED'
+          if ( $clone || $part_svc->svcpart ) #null svcpart search causing error
+              && qsearchs( 'export_svc', {
+                                   exportnum => $part_export->exportnum,
+                                   svcpart   => $clone || $part_svc->svcpart });
+        $html .= '>'. $part_export->exportnum. ': '. $part_export->exporttype.
+                 ' to '. $part_export->machine. '</TD>';
+        $count++;
+        $html .= '</TR><TR>' unless $count % $columns;
+      }
+      $html .= '</TR></TABLE><BR><BR>';
+
+      $html .=  table(). "<TH>Field</TH><TH COLSPAN=2>Modifier</TH>";
       #yucky kludge
       my @fields = defined( $FS::Record::dbdef->table($layer) )
                       ? grep { $_ ne 'svcnum' } fields($layer)
                       : ();
       push @fields, 'usergroup' if $layer eq 'svc_acct'; #kludge
+      $part_svc->svcpart($clone) if $clone; #haha, undone below
       foreach my $field (@fields) {
         my $part_svc_column = $part_svc->part_svc_column($field);
         my $value = $cgi->param('error')
@@ -153,28 +192,44 @@ my %defs = (
         $html .= "<TR><TD>$field";
         $html .= "- <FONT SIZE=-1>$desc</FONT>" if $desc;
         $html .=  "</TD>";
+        $flag = '' if ref($def) && $def->{type} eq 'disabled';
         $html .=
           qq!<TD><INPUT TYPE="radio" NAME="${layer}__${field}_flag" VALUE=""!.
           ' CHECKED'x($flag eq ''). ">Off</TD>".
-          qq!<TD><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>';
+          '<TD>';
+        unless ( ref($def) && $def->{type} eq 'disabled' ) {
+          $html .= 
+            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>';
+        }
         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(
               [ split(',', $value) ], "${layer}__${field}" );
+          } elsif ( $def->{type} eq 'disabled' ) {
+            $html .=
+              qq!<INPUT TYPE="hidden" NAME="${layer}__${field}" VALUE="">!;
           } else {
             $html .= '<font color="#ff0000">unknown type'. $def->{type};
           }
@@ -184,6 +239,7 @@ my %defs = (
         }
         $html .= "</TD></TR>\n";
       }
+      $part_svc->svcpart('') if $clone; #undone
       $html .= "</TABLE>";
 
       $html .= '<BR><INPUT TYPE="submit" VALUE="'.