--- loncom/interface/loncreateuser.pm	2008/07/07 23:54:27	1.250
+++ loncom/interface/loncreateuser.pm	2008/07/13 00:15:14	1.252
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.250 2008/07/07 23:54:27 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.252 2008/07/13 00:15:14 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1396,18 +1396,29 @@ sub modify_login_block {
 }
 
 sub personal_data_display {
-    my ($ccuname,$ccdomain,$newuser,$context,$inst_results) = @_;
-    my ($output,$showforceid,%userenv,%canmodify);
+    my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
+    my ($output,$showforceid,%userenv,%canmodify,@inststatuses);
     my @userinfo = ('firstname','middlename','lastname','generation',
                     'permanentemail','id');
-    if (!$newuser) {
+    my $rowcount = 0;
+    my $editable = 0;
+    if ($context eq 'selfcreate') {
+        if (ref($inst_results) eq 'HASH') {
+            @inststatuses = &get_inststatuses($inst_results);
+            if (@inststatuses == 0) {
+                @inststatuses = ('default');
+            }
+            $rolesarray = \@inststatuses;
+        }
+    }
+    if (!$newuser || $context eq 'selfcreate') {
         # Get the users information
         %userenv = &Apache::lonnet::get('environment',
                    ['firstname','middlename','lastname','generation',
                     'permanentemail','id'],$ccdomain,$ccuname);
         %canmodify =
             &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
-                                                       \@userinfo);
+                                                       \@userinfo,$rolesarray);
     }
     my %lt=&Apache::lonlocal::texthash(
                 'pd'             => "Personal Data",
@@ -1432,40 +1443,74 @@ sub personal_data_display {
               &Apache::lonhtmlcommon::start_pick_box();
     foreach my $item (@userinfo) {
         my $rowtitle = $lt{$item};
+        my $hiderow = 0;
         if ($item eq 'generation') {
             $rowtitle = $genhelp.$rowtitle;
         }
-        $output .= &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
+        my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
         if ($newuser) {
             if (ref($inst_results) eq 'HASH') {
                 if ($inst_results->{$item} ne '') {
-                    $output .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
+                    $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
                 } else {
-                    $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
+                    if ($context eq 'selfcreate') {
+                        if ($canmodify{$item}) { 
+                            $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
+                            $editable ++;
+                        } else {
+                            $hiderow = 1;
+                        }
+                    }
                 }
             } else {
-                $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
+                if ($context eq 'selfcreate') {
+                    if ($canmodify{$item}) {
+                        $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
+                        $editable ++;
+                    } else {
+                        $hiderow = 1;
+                    }
+                }
             }
         } else {
             if ($canmodify{$item}) {
-                $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
+                $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
             } else {
-                $output .= $userenv{$item};
+                $row .= $userenv{$item};
             }
             if ($item eq 'id') {
                 $showforceid = $canmodify{$item};
             }
         }
-        $output .= &Apache::lonhtmlcommon::row_closure(1);
+        $row .= &Apache::lonhtmlcommon::row_closure(1);
+        if (!$hiderow) {
+            $output .= $row;
+            $rowcount ++;
+        }
     }
     $output .= &Apache::lonhtmlcommon::end_pick_box();
     if (wantarray) {
-        return ($output,$showforceid);
+        if ($context eq 'selfcreate') {
+            return($output,$rowcount,$editable);
+        } else {
+            return ($output,$showforceid);
+        }
     } else {
         return $output;
     }
 }
 
+sub get_inststatuses {
+    my ($insthashref) = @_;
+    my @inststatuses = ();
+    if (ref($insthashref) eq 'HASH') {
+        if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
+            @inststatuses = @{$insthashref->{'inststatus'}};
+        }
+    }
+    return @inststatuses;
+}
+
 # ================================================================= Phase Three
 sub update_user_data {
     my ($r,$context) = @_; 
@@ -3538,7 +3583,7 @@ sub selfenroll_inst_types {
     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
     my $othervalue = 'any';
     if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
-        if (@{$types} > 0) {
+        if (keys(%{$usertypes}) > 0) {
             $othervalue = 'other';
         }
         $output .= '<table><tr>';