--- loncom/interface/loncreateuser.pm	2007/11/15 19:06:28	1.195
+++ loncom/interface/loncreateuser.pm	2007/12/11 02:27:24	1.206
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.195 2007/11/15 19:06:28 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.206 2007/12/11 02:27:24 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -76,7 +76,7 @@ my $authformfsys;
 my $authformloc;
 
 sub initialize_authen_forms {
-    my ($dom,$curr_authtype) = @_; 
+    my ($dom,$curr_authtype,$mode) = @_; 
     my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
     $krbdefdom= uc($krbdefdom);
     my %param = ( formname => 'document.cu',
@@ -91,6 +91,9 @@ sub initialize_authen_forms {
         if ($long_auth =~ /^krb(4|5)$/) {
             $param{'curr_kerb_ver'} = $1;
         }
+        if ($mode eq 'modifyuser') {
+            $param{'mode'} = $mode;
+        }
     }
 # no longer static due to configurable kerberos defaults
 #    $loginscript  = &Apache::loncommon::authform_header(%param);
@@ -440,7 +443,7 @@ sub print_user_query_page {
 }
 
 sub print_user_modification_page {
-    my ($r,$ccuname,$ccdomain,$srch,$response) = @_;
+    my ($r,$ccuname,$ccdomain,$srch,$response,$context) = @_;
     if (($ccuname eq '') || ($ccdomain eq '')) {
         my $usermsg = &mt('No username and/or domain provided.'); 
 	&print_username_entry_form($r,$usermsg);
@@ -448,30 +451,32 @@ sub print_user_modification_page {
     }
     my %abv_auth = &auth_abbrev();
     my ($curr_authtype,%rulematch,%inst_results,$curr_kerb_ver,$newuser,
-        %alerts,%curr_rules);
+        %alerts,%curr_rules,%got_rules);
     my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
     if ($uhome eq 'no_host') {
         $newuser = 1;
         my $checkhash;
         my $checks = { 'username' => 1 };
-        $checkhash->{$ccuname.':'.$ccdomain} = { 'status' => 'new' };
+        $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
         &Apache::loncommon::user_rule_check($checkhash,$checks,
-                   \%alerts,\%rulematch,\%inst_results,\%curr_rules);
-        if (ref($alerts{$ccuname.':'.$ccdomain}) eq 'HASH') {
-            if ($alerts{$ccuname.':'.$ccdomain}{'username'}) {
-                my $domdesc = 
+            \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
+        if (ref($alerts{'username'}) eq 'HASH') {
+            if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
+                my $domdesc =
                     &Apache::lonnet::domain($ccdomain,'description');
-                my $userchkmsg;
-                if (ref($curr_rules{$ccdomain}) eq 'HASH') {  
-                    $userchkmsg = 
-                        &Apache::loncommon::instrule_disallow_msg('username',
+                if ($alerts{'username'}{$ccdomain}{$ccuname}) {
+                    my $userchkmsg;
+                    if (ref($curr_rules{$ccdomain}) eq 'HASH') {  
+                        $userchkmsg = 
+                            &Apache::loncommon::instrule_disallow_msg('username',
                                                                  $domdesc,1).
                         &Apache::loncommon::user_rule_formats($ccdomain,
                             $domdesc,$curr_rules{$ccdomain}{'username'},
                             'username');
-                }
-                &print_username_entry_form($r,$userchkmsg);
-                return;
+                    }
+                    &print_username_entry_form($r,$userchkmsg);
+                    return;
+                } 
             }
         }
     } else {
@@ -625,82 +630,8 @@ sub print_user_modification_page {
     }
 ENDSCRIPT
     } else {
-        $nondc_setsection_code = <<"ENDSECCODE";
-    function setSections() {
-        var re1 = /^currsec_/;
-        var groups = new Array($groupslist);
-        for (var i=0;i<document.cu.elements.length;i++) {
-            var str = document.cu.elements[i].name;
-            var checkcurr = str.match(re1);
-            if (checkcurr != null) {
-                if (document.cu.elements[i-1].checked == true) {
-		    var match = str.split('_');
-                    var role = match[3];
-                    if (role == 'cc') {
-                        alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
-                    }
-                    else {
-                        var sections = '';
-                        var numsec = 0;
-                        var sections;
-                        for (var j=0; j<document.cu.elements[i].length; j++) {
-                            if (document.cu.elements[i].options[j].selected == true ) {
-                                if (document.cu.elements[i].options[j].value != "") {
-                                    if (numsec == 0) {
-                                        if (document.cu.elements[i].options[j].value != "") {
-                                            sections = document.cu.elements[i].options[j].value;
-                                            numsec ++;
-                                        }
-                                    }
-                                    else {
-                                        sections = sections + "," +  document.cu.elements[i].options[j].value
-                                        numsec ++;
-                                    }
-                                }
-                            }
-                        }
-                        if (numsec > 0) {
-                            if (document.cu.elements[i+1].value != "" && document.cu.elements[i+1].value != null) {
-                                sections = sections + "," +  document.cu.elements[i+1].value;
-                            }
-                        }
-                        else {
-                            sections = document.cu.elements[i+1].value;
-                        }
-                        var newsecs = document.cu.elements[i+1].value;
-			var numsplit;
-                        if (newsecs != null && newsecs != "") {
-                            numsplit = newsecs.split(/,/g);
-                            numsec = numsec + numsplit.length;
-                        }
-
-                        if ((role == 'st') && (numsec > 1)) {
-                            alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.")
-                            return;
-                        }
-                        else if (numsplit != null) {
-                            for (var j=0; j<numsplit.length; j++) {
-                                if ((numsplit[j] == 'all') ||
-                                    (numsplit[j] == 'none')) {
-                                    alert("'"+numsplit[j]+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
-                                    return;
-                                }
-                                for (var k=0; k<groups.length; k++) {
-                                    if (numsplit[j] == groups[k]) {
-                                        alert("'"+numsplit[j]+"' may not be used as a section name, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name.");
-                                        return;
-                                    }
-                                }
-                            }
-                        }
-                        document.cu.elements[i+2].value = sections;
-                    }
-                }
-            }
-        }
-        document.cu.submit();
-    }
-ENDSECCODE
+        $nondc_setsection_code = 
+            &Apache::lonuserutils::setsections_javascript('cu',$groupslist);
     }
     my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
                                    $nondc_setsection_code,$groupslist);
@@ -776,9 +707,11 @@ $loginscript
 <input type='hidden' name='makeuser' value='1' />
 <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain</h2>
 ENDTITLE
-        $r->print('<div class="LC_left_float">'.
-                  &personal_data_display($ccuname,$ccdomain,$newuser,
-                                         %inst_results));
+        $r->print('<div class="LC_left_float">');
+        my $personal_table = 
+            &personal_data_display($ccuname,$ccdomain,$newuser,
+                                   $context,%inst_results);
+        $r->print($personal_table);
         my ($home_server_pick,$numlib) = 
             &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
                                                       'default','hide');
@@ -855,10 +788,15 @@ $crumbs
 $forminfo
 <h2>$lt{'cup'} "$ccuname" $lt{'id'} "$ccdomain"</h2>
 ENDCHANGEUSER
-        $r->print('<div class="LC_left_float">'.
-                  &personal_data_display($ccuname,$ccdomain,$newuser,
-                                         %inst_results).
-                  '</div>');
+        $r->print('<div class="LC_left_float">');
+        my ($personal_table,$showforceid) = 
+            &personal_data_display($ccuname,$ccdomain,$newuser,
+                                   $context,%inst_results);
+        $r->print($personal_table);
+        if ($showforceid) {
+            $r->print(&Apache::lonuserutils::forceid_change($context));
+        }
+        $r->print('</div>');
         my $user_auth_text = 
             &user_authentication($ccuname,$ccdomain,$krbdefdom,\%abv_auth);
         my $user_quota_text;
@@ -1209,7 +1147,7 @@ ENDNOPORTPRIV
         }
     } else {
         $r->print(&course_level_table(%inccourses));
-        $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setSections()" />'."\n");
+        $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setSections(this.form)" />'."\n");
     }
     $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
     $r->print('<input type="hidden" name="currstate" value="" />');
@@ -1266,10 +1204,8 @@ $lt{'uuas'} ($currentauth). $lt{'adcs'}.
 ENDBADAUTH
         }
     } else { # Authentication type is valid
-        my $authformcurrent='';
-        my $authform_other='';
-        &initialize_authen_forms($ccdomain,$currentauth);
-        my ($authformcurrent,$authform_other,$can_modify) =
+        &initialize_authen_forms($ccdomain,$currentauth,'modifyuser');
+        my ($authformcurrent,$can_modify,@authform_others) =
             &modify_login_block($ccdomain,$currentauth);
         if (&Apache::lonnet::allowed('mau',$ccdomain)) {
             # Current user has login modification privileges
@@ -1293,13 +1229,15 @@ ENDBADAUTH
                             '<td>'.$authformcurrent.'</td>'.
                             &Apache::loncommon::end_data_table_row()."\n";
             } else {
-                $outcome .= '&nbsp;('.$authformcurrent.')</td>';
+                $outcome .= '&nbsp;('.$authformcurrent.')</td>'.
+                            &Apache::loncommon::end_data_table_row()."\n";
             }
-            if ($authform_other ne '') {
-                $outcome .= $authform_other;
+            foreach my $item (@authform_others) { 
+                $outcome .= &Apache::loncommon::start_data_table_row().
+                            '<td>'.$item.'</td>'.
+                            &Apache::loncommon::end_data_table_row()."\n";
             }
-            $outcome .= &Apache::loncommon::end_data_table_row().
-                        &Apache::loncommon::end_data_table();
+            $outcome .= &Apache::loncommon::end_data_table();
         } else {
             if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
                 my %lt=&Apache::lonlocal::texthash(
@@ -1322,18 +1260,14 @@ sub modify_login_block {
     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
     my ($authnum,%can_assign) =
         &Apache::loncommon::get_assignable_auth($dom);
-    my ($authformcurrent,$authform_other,$show_override_msg);
+    my ($authformcurrent,@authform_others,$show_override_msg);
     if ($currentauth=~/^krb(4|5):/) {
         $authformcurrent=$authformkrb;
         if ($can_assign{'int'}) {
-            $authform_other = &Apache::loncommon::start_data_table_row().
-                              '<td>'.$authformint.'</td>'.
-                              &Apache::loncommon::end_data_table_row()."\n"
+            push(@authform_others,$authformint);
         }
         if ($can_assign{'loc'}) {
-            $authform_other .= &Apache::loncommon::start_data_table_row().
-                               '<td>'.$authformloc.'</td>'.
-                               &Apache::loncommon::end_data_table_row()."\n";
+            push(@authform_others,$authformloc);
         }
         if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
             $show_override_msg = 1;
@@ -1341,14 +1275,10 @@ sub modify_login_block {
     } elsif ($currentauth=~/^internal:/) {
         $authformcurrent=$authformint;
         if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
-            $authform_other = &Apache::loncommon::start_data_table_row().
-                              '<td>'.$authformkrb.'</td>'.
-                              &Apache::loncommon::end_data_table_row()."\n";
+            push(@authform_others,$authformkrb);
         }
         if ($can_assign{'loc'}) {
-            $authform_other .= &Apache::loncommon::start_data_table_row().
-                               '<td>'.$authformloc.'</td>'.
-                               &Apache::loncommon::end_data_table_row()."\n";
+            push(@authform_others,$authformloc);
         }
         if ($can_assign{'int'}) {
             $show_override_msg = 1;
@@ -1356,19 +1286,13 @@ sub modify_login_block {
     } elsif ($currentauth=~/^unix:/) {
         $authformcurrent=$authformfsys;
         if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
-            $authform_other = &Apache::loncommon::start_data_table_row().
-                              '<td>'.$authformkrb.'</td>'.
-                              &Apache::loncommon::end_data_table_row()."\n";
+            push(@authform_others,$authformkrb);
         }
         if ($can_assign{'int'}) {
-            $authform_other .= &Apache::loncommon::start_data_table_row().
-                               '<td>'.$authformint.'</td>'.
-                               &Apache::loncommon::end_data_table_row()."\n"
+            push(@authform_others,$authformint);
         }
         if ($can_assign{'loc'}) {
-            $authform_other .= &Apache::loncommon::start_data_table_row().
-                               '<td>'.$authformloc.'</td>'.
-                               &Apache::loncommon::end_data_table_row()."\n";
+            push(@authform_others,$authformloc);
         }
         if ($can_assign{'fsys'}) {
             $show_override_msg = 1;
@@ -1376,35 +1300,38 @@ sub modify_login_block {
     } elsif ($currentauth=~/^localauth:/) {
         $authformcurrent=$authformloc;
         if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
-            $authform_other = &Apache::loncommon::start_data_table_row().
-                              '<td>'.$authformkrb.'</td>'.
-                              &Apache::loncommon::end_data_table_row()."\n";
+            push(@authform_others,$authformkrb);
         }
         if ($can_assign{'int'}) {
-            $authform_other .= &Apache::loncommon::start_data_table_row().
-                               '<td>'.$authformint.'</td>'.
-                               &Apache::loncommon::end_data_table_row()."\n"
+            push(@authform_others,$authformint);
         }
         if ($can_assign{'loc'}) {
             $show_override_msg = 1;
         }
     }
     if ($show_override_msg) {
-        $authformcurrent.= ' <span class="LC_cusr_emph">'.
+        $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
+                           '</td></tr>'."\n".
+                           '<tr><td>&nbsp;&nbsp;&nbsp;</td>'.
+                           '<td><b>'.&mt('Currently in use').'</b></td>'.
+                           '<td align="right"><span class="LC_cusr_emph">'.
                             &mt('will override current values').
-                            '</span><br />';
+                            '</span></td></tr></table>';
     }
-    return ($authformcurrent,$authform_other,$show_override_msg); 
+    return ($authformcurrent,$show_override_msg,@authform_others); 
 }
 
 sub personal_data_display {
-    my ($ccuname,$ccdomain,$newuser,%inst_results) = @_; 
-    my ($output,%userenv);
+    my ($ccuname,$ccdomain,$newuser,$context,%inst_results) = @_; 
+    my ($output,$showforceid,%userenv,%domconfig);
     if (!$newuser) {
         # Get the users information
         %userenv = &Apache::lonnet::get('environment',
                    ['firstname','middlename','lastname','generation',
                     'permanentemail','id'],$ccdomain,$ccuname);
+        %domconfig =
+            &Apache::lonnet::get_dom('configuration',['usermodification'],
+                                     $ccdomain);
     }
     my %lt=&Apache::lonlocal::texthash(
                 'pd'             => "Personal Data",
@@ -1442,21 +1369,47 @@ sub personal_data_display {
                 $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
             }
         } else {
+            my $canmodify = 0;
             if (&Apache::lonnet::allowed('mau',$ccdomain)) {
+                $canmodify = 1;
+            } else {
+                if (ref($domconfig{'usermodification'}) eq 'HASH') {
+                    if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
+                        foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
+                            if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
+                                if ($domconfig{'usermodification'}{$context}{$key}{$item}) { 
+                                    $canmodify = 1;
+                                    last;
+                                }
+                            }
+                        }
+                    }
+                } elsif ($context eq 'course') {
+                    $canmodify = 1;
+                }
+            }
+            if ($canmodify) {
                 $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
             } else {
                 $output .= $userenv{$item};
             }
+            if ($item eq 'id') {
+                $showforceid = $canmodify; 
+            } 
         }
         $output .= &Apache::lonhtmlcommon::row_closure(1);
     }
     $output .= &Apache::lonhtmlcommon::end_pick_box();
-    return $output;
+    if (wantarray) {
+        return ($output,$showforceid);
+    } else {
+        return $output;
+    }
 }
 
 # ================================================================= Phase Three
 sub update_user_data {
-    my ($r) = @_; 
+    my ($r,$context) = @_; 
     my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
                                           $env{'form.ccdomain'});
     # Error messages
@@ -1585,26 +1538,30 @@ sub update_user_data {
         my %checkhash;
         my %checks = ('id' => 1);
         %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
-            'status' => 'new', 
-            'id' => $env{'form.cid'}
+            'newuser' => 1, 
+            'id' => $env{'form.cid'},
         );
-        &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
-                                      \%rulematch,\%inst_results,\%curr_rules);
-        if (ref($alerts{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}) eq 'HASH') {
-            if ($alerts{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}{'id'}) {
-                my $domdesc =
-                    &Apache::lonnet::domain($env{'form.ccdomain'},'description');
-                my $userchkmsg;
-                if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
-                    $userchkmsg  = 
-                        &Apache::loncommon::instrule_disallow_msg('id',
-                                                                  $domdesc,1).
-                        &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
-                            $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
-                } 
-                $r->print($error.&mt('Invalid ID format').$end.
-                          $userchkmsg.$rtnlink);
-                return;
+        if ($env{'form.cid'} ne '') {
+            &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
+                                          \%rulematch,\%inst_results,\%curr_rules);
+            if (ref($alerts{'id'}) eq 'HASH') {
+                if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
+                    my $domdesc =
+                        &Apache::lonnet::domain($env{'form.ccdomain'},'description');
+                    if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
+                        my $userchkmsg;
+                        if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
+                            $userchkmsg  = 
+                                &Apache::loncommon::instrule_disallow_msg('id',
+                                                                    $domdesc,1).
+                                &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
+                                    $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
+                        }
+                        $r->print($error.&mt('Invalid ID format').$end.
+                                  $userchkmsg.$rtnlink);
+                        return;
+                    }
+                }
             }
         }
 	# Call modifyuser
@@ -1644,22 +1601,158 @@ sub update_user_data {
         # Check for need to change
         my %userenv = &Apache::lonnet::get
             ('environment',['firstname','middlename','lastname','generation',
-             'permanentemail','portfolioquota','inststatus'],
+             'id','permanentemail','portfolioquota','inststatus'],
               $env{'form.ccdomain'},$env{'form.ccuname'});
         my ($tmp) = keys(%userenv);
         if ($tmp =~ /^(con_lost|error)/i) { 
             %userenv = ();
         }
-        # Check to see if we need to change user information
-        foreach my $item ('firstname','middlename','lastname','generation','permanentemail') {
+        my $no_forceid_alert;
+        # Check to see if user information can be changed
+        my %domconfig =
+            &Apache::lonnet::get_dom('configuration',['usermodification'],
+                                     $env{'form.ccdomain'});
+        my @roletypes = ('active','future');
+        my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@roletypes,undef,$env{'request.role.domain'});
+        my @userroles;
+        my ($cnum,$cdom,$auname,$audom);
+        if ($context eq 'course') {
+            $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+            $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+            if ($cnum eq '' || $cdom eq '') {
+                my $cid = $env{'request.course.id'};
+                my %coursehash =
+                     &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
+                $cdom = $coursehash{'domain'};
+                $cnum = $coursehash{'num'};
+            } 
+        } elsif ($context eq 'author') {
+            $auname = $env{'user.name'};
+            $audom = $env{'user.domain'};     
+        }
+        foreach my $item (keys(%roles)) {
+            my ($rolenum,$roledom,$role) = split(/:/,$item);
+            if ($context eq 'course') {
+                if ($cnum ne '' && $cdom ne '') {
+                    if ($rolenum eq $cnum && $roledom eq $cdom) {
+                        if (!grep(/^\Q$role\E$/,@userroles)) {
+                            push(@userroles,$role);
+                        }
+                    }
+                }
+            } elsif ($context eq 'author') {
+                if ($rolenum eq $auname && $roledom eq $audom) {
+                    if (!grep(/^\Q$role\E$/,@userroles)) { 
+                        push(@userroles,$role);
+                    }
+                }
+            }
+        }
+        # Check for course or co-author roles being activated or re-enabled
+        if ($context eq 'author' || $context eq 'course') {
+            foreach my $key (keys(%env)) {
+                if ($context eq 'author') {
+                    if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
+                        if (!grep(/^\Q$1\E$/,@userroles)) {
+                            push(@userroles,$1);
+                        }
+                    } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
+                        if (!grep(/^\Q$1\E$/,@userroles)) {
+                            push(@userroles,$1);
+                        }
+                    }
+                } elsif ($context eq 'course') {
+                    if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
+                        if (!grep(/^\Q$1\E$/,@userroles)) {
+                            push(@userroles,$1);
+                        }
+                    } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
+                        if (!grep(/^\Q$1\E$/,@userroles)) {
+                            push(@userroles,$1);
+                        }
+                    }
+                }
+            }
+        }
+        #Check to see if we can change personal data for the user 
+        my (@mod_disallowed,@longroles);
+        foreach my $role (@userroles) {
+            if ($role eq 'cr') {
+                push(@longroles,'Custom');
+            } else {
+                push(@longroles,&Apache::lonnet::plaintext($role)); 
+            }
+        }
+        foreach my $item ('firstname','middlename','lastname','generation','permanentemail','id') {
+            my $canmodify = 0;
+            if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
+                $canmodify = 1;
+            } else {
+                if ($context eq 'course' || $context eq 'author') {
+                    if (ref($domconfig{'usermodification'}) eq 'HASH') {
+                        if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
+                            foreach my $role (@userroles) {
+                                if (ref($domconfig{'usermodification'}{$context}{$role}) eq 'HASH') {
+                                    if ($domconfig{'usermodification'}{$context}{$role}{$item}) {
+                                        $canmodify = 1;
+                                        last;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                } elsif ($context eq 'course') {
+                    if (grep(/^st$/,@userroles)) {
+                        $canmodify = 1;
+                    }
+                }
+            }
             # Strip leading and trailing whitespace
-            $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g; 
+            $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
+            if (!$canmodify) {
+                if ($env{'form.c'.$item} ne $userenv{$item}) {
+                    push(@mod_disallowed,$item);
+                }
+                $env{'form.c'.$item} = $userenv{$item};
+            }
+        }
+        # Check to see if we can change the ID/student number
+        my $forceid = $env{'form.forceid'};
+        my $recurseid = $env{'form.recurseid'};
+        my $newuser = 0;
+        my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
+        my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
+                                            $env{'form.ccuname'});
+        if (($uidhash{$env{'form.ccuname'}}) && 
+            ($uidhash{$env{'form.ccuname'}}!~/error\:/) && 
+            (!$forceid)) {
+            if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
+                $env{'form.cid'} = $userenv{'id'};
+                $no_forceid_alert = &mt('New student/employeeID does not match existing ID for this user.').'<br />'.&mt('Change is not permitted without checking the \'Force ID change\' checkbox on the previous page.').'<br />'."\n";        
+            }
+        }
+        if ($env{'form.cid'} ne $userenv{'id'}) {
+            my $checkhash;
+            my $checks = { 'id' => 1 };
+            $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} = 
+                   { 'newuser' => $newuser,
+                     'id'  => $env{'form.cid'}, 
+                   };
+            &Apache::loncommon::user_rule_check($checkhash,$checks,
+                \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
+            if (ref($alerts{'id'}) eq 'HASH') {
+                if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
+                   $env{'form.cid'} = $userenv{'id'};
+                }
+            }
         }
         my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota,
-            $inststatus,$isdefault,$defquotatext);
+            $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
+            $newdefquotatext);
         my ($defquota,$settingstatus) = 
             &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
         my %changeHash;
+        $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
         if ($userenv{'portfolioquota'} ne '') {
             $oldportfolioquota = $userenv{'portfolioquota'};
             if ($env{'form.customquota'} == 1) {
@@ -1669,15 +1762,16 @@ sub update_user_data {
                     $newportfolioquota = $env{'form.portfolioquota'};
                     $newportfolioquota =~ s/[^\d\.]//g;
                 }
-                if ($newportfolioquota != $userenv{'portfolioquota'}) {
+                if ($newportfolioquota != $oldportfolioquota) {
                     $quotachanged = &quota_admin($newportfolioquota,\%changeHash);
                 }
             } else {
                 $quotachanged = &quota_admin('',\%changeHash);
                 $newportfolioquota = $defquota;
-                $isdefault = 1; 
+                $newisdefault = 1; 
             }
         } else {
+            $oldisdefault = 1;
             $oldportfolioquota = $defquota;
             if ($env{'form.customquota'} == 1) {
                 if ($env{'form.portfolioquota'} eq '') {
@@ -1689,41 +1783,47 @@ sub update_user_data {
                 $quotachanged = &quota_admin($newportfolioquota,\%changeHash);
             } else {
                 $newportfolioquota = $defquota;
-                $isdefault = 1;
+                $newisdefault = 1;
             }
         }
-        if ($isdefault) {
-            if ($settingstatus eq '') {
-                $defquotatext = &mt('(default)');
-            } else {
-                my ($usertypes,$order) = 
-                    &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
-                if ($usertypes->{$settingstatus} eq '') {
-                    $defquotatext = &mt('(default)');
-                } else { 
-                    $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
-                }
-            }
+        if ($oldisdefault) {
+            $olddefquotatext = &get_defaultquota_text($settingstatus);
         }
-        if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) && 
-            ($env{'form.cfirstname'}  ne $userenv{'firstname'}  ||
-             $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
-             $env{'form.clastname'}   ne $userenv{'lastname'}   ||
-             $env{'form.cgeneration'} ne $userenv{'generation'} ||
-             $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} )) {
+        if ($newisdefault) {
+            $newdefquotatext = &get_defaultquota_text($settingstatus);
+        }
+        if ($env{'form.cfirstname'}  ne $userenv{'firstname'}  ||
+            $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
+            $env{'form.clastname'}   ne $userenv{'lastname'}   ||
+            $env{'form.cgeneration'} ne $userenv{'generation'} ||
+            $env{'form.cid'} ne $userenv{'id'}                 ||
+            $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} ) {
             $namechanged = 1;
         }
-        if ($namechanged) {
-            # Make the change
+        if ($namechanged || $quotachanged) {
             $changeHash{'firstname'}  = $env{'form.cfirstname'};
             $changeHash{'middlename'} = $env{'form.cmiddlename'};
             $changeHash{'lastname'}   = $env{'form.clastname'};
             $changeHash{'generation'} = $env{'form.cgeneration'};
+            $changeHash{'id'}         = $env{'form.cid'};
             $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
-            my $putresult = &Apache::lonnet::put
-                ('environment',\%changeHash,
-                 $env{'form.ccdomain'},$env{'form.ccuname'});
-            if ($putresult eq 'ok') {
+            my ($quotachgresult,$namechgresult);
+            if ($quotachanged) {
+                $quotachgresult = 
+                    &Apache::lonnet::put('environment',\%changeHash,
+                                  $env{'form.ccdomain'},$env{'form.ccuname'});
+            }
+            if ($namechanged) {
+            # Make the change
+                $namechgresult =
+                    &Apache::lonnet::modifyuser($env{'form.ccdomain'},
+                        $env{'form.ccuname'},$changeHash{'id'},undef,undef,
+                        $changeHash{'firstname'},$changeHash{'middlename'},
+                        $changeHash{'lastname'},$changeHash{'generation'},
+                        $changeHash{'id'},undef,$changeHash{'permanentemail'});
+            }
+            if (($namechanged && $namechgresult eq 'ok') || 
+                ($quotachanged && $quotachgresult eq 'ok')) {
             # Tell the user we changed the name
 		my %lt=&Apache::lonlocal::texthash(
                              'uic'  => "User Information Changed",             
@@ -1731,38 +1831,70 @@ sub update_user_data {
                              'mddl' => "middle",
                              'lst'  => "last",
 			     'gen'  => "generation",
+                             'id'   => "ID/Student number",
                              'mail' => "permanent e-mail",
                              'disk' => "disk space allocated to portfolio files",
                              'prvs' => "Previous",
                              'chto' => "Changed To"
 						   );
+                $r->print('<h4>'.$lt{'uic'}.'</h4>'.
+                          &Apache::loncommon::start_data_table().
+                          &Apache::loncommon::start_data_table_header_row());
                 $r->print(<<"END");
-<table border="2">
-<caption>$lt{'uic'}</caption>
-<tr><th>&nbsp;</th>
+    <th>&nbsp;</th>
     <th>$lt{'frst'}</th>
     <th>$lt{'mddl'}</th>
     <th>$lt{'lst'}</th>
     <th>$lt{'gen'}</th>
+    <th>$lt{'id'}</th>
     <th>$lt{'mail'}</th>
-    <th>$lt{'disk'}</th></tr>
-<tr><td>$lt{'prvs'}</td>
+    <th>$lt{'disk'}</th>
+END
+                $r->print(&Apache::loncommon::end_data_table_header_row().
+                          &Apache::loncommon::start_data_table_row());
+                $r->print(<<"END");
+    <td><b>$lt{'prvs'}</b></td>
     <td>$userenv{'firstname'}  </td>
     <td>$userenv{'middlename'} </td>
     <td>$userenv{'lastname'}   </td>
     <td>$userenv{'generation'} </td>
+    <td>$userenv{'id'}</td>
     <td>$userenv{'permanentemail'} </td>
-    <td>$oldportfolioquota Mb</td>
-</tr>
-<tr><td>$lt{'chto'}</td>
+    <td>$oldportfolioquota Mb $olddefquotatext </td>
+END
+                $r->print(&Apache::loncommon::end_data_table_row().
+                          &Apache::loncommon::start_data_table_row());
+                $r->print(<<"END");
+    <td><b>$lt{'chto'}</b></td>
     <td>$env{'form.cfirstname'}  </td>
     <td>$env{'form.cmiddlename'} </td>
     <td>$env{'form.clastname'}   </td>
     <td>$env{'form.cgeneration'} </td>
+    <td>$env{'form.cid'} </td>
     <td>$env{'form.cpermanentemail'} </td>
-    <td>$newportfolioquota Mb $defquotatext </td></tr>
-</table>
+    <td>$newportfolioquota Mb $newdefquotatext </td>
 END
+                $r->print(&Apache::loncommon::end_data_table_row().
+                          &Apache::loncommon::end_data_table().'<br />');
+                if ($env{'form.cid'} ne $userenv{'id'}) {
+                    &Apache::lonnet::idput($env{'form.ccdomain'},
+                         ($env{'form.ccuname'} => $env{'form.cid'}));
+                    if (($recurseid) &&
+                        (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
+                        my %userupdate = (
+                                  lastname   => $env{'form.clasaname'},
+                                  middlename => $env{'form.cmiddlename'},
+                                  firstname  => $env{'form.cfirstname'},
+                                  generation => $env{'fora.cgeneration'},
+                                  id         => $env{'form.cid'},
+                             );
+                        my $idresult = 
+                            &Apache::lonuserutils::propagate_id_change(
+                                $env{'form.ccuname'},$env{'form.ccdomain'},
+                                \%userupdate);
+                        $r->print('<br />'.$idresult.'<br />');
+                    }
+                }
                 if (($env{'form.ccdomain'} eq $env{'user.domain'}) && 
                     ($env{'form.ccuname'} eq $env{'user.name'})) {
                     my %newenvhash;
@@ -1774,32 +1906,47 @@ END
             } else { # error occurred
                 $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
                       $env{'form.ccuname'}.' '.&mt('in domain').' '.
-                      $env{'form.ccdomain'}.'</span>');
+                      $env{'form.ccdomain'}.'</span><br />');
             }
         }  else { # End of if ($env ... ) logic
-            my $putresult;
-            if ($quotachanged) {
-                $putresult = &Apache::lonnet::put
-                                 ('environment',\%changeHash,
-                                  $env{'form.ccdomain'},$env{'form.ccuname'});
-            }
-            # They did not want to change the users name but we can
-            # still tell them what the name is
+            # They did not want to change the users name or quota but we can
+            # still tell them what the name and quota are 
 	    my %lt=&Apache::lonlocal::texthash(
+                           'id'   => "ID/Student number",
                            'mail' => "Permanent e-mail",
                            'disk' => "Disk space allocated to user's portfolio files",
 					       );
             $r->print(<<"END");
-<h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}&nbsp;&nbsp;($lt{'mail'}: $userenv{'permanentemail'})</h4>
+<h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
 END
-            if ($putresult eq 'ok') {
-                if ($oldportfolioquota != $newportfolioquota) {
-                    $r->print('<h4>'.$lt{'disk'}.': '.$newportfolioquota.' Mb '. 
-                              $defquotatext.'</h4>');
-                    &Apache::lonnet::appenv('environment.portfolioquota' => $changeHash{'portfolioquota'});
-                }
+            if ($userenv{'permanentemail'} ne '') {
+                $r->print('<br />['.$lt{'mail'}.': '.
+                          $userenv{'permanentemail'}.']');
+            }
+            $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '. 
+                 $olddefquotatext.']</h4>');
+        }
+        if (@mod_disallowed) {
+            my ($rolestr,$contextname);
+            if (@longroles > 0) {
+                $rolestr = join(', ',@longroles);
+            } else {
+                $rolestr = &mt('No roles');
+            }
+            if ($context eq 'course') {
+                $contextname = &mt('course');
+            } elsif ($context eq 'author') {
+                $contextname = &mt('co-author');
+            }
+            $r->print(&mt('The following fields were not updated: ').'<ul>');
+            my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
+            foreach my $field (@mod_disallowed) {
+                $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n"); 
             }
+            $r->print('</ul>'.&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles: <span class=\"LC_cusr_emph\">[_2]</span>.",$contextname,$rolestr).'<br />'.&mt('Contact your <a href="[_1]">helpdesk</a> for more information.',"javascript:helpMenu('display')").'<br />');
         }
+        $r->print($no_forceid_alert.
+                  &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts, \%curr_rules));
     }
     ##
     my $now=time;
@@ -1820,11 +1967,13 @@ END
 	        $r->print(&mt('Revoking [_1] in [_2]: [_3]',
 			      $role,$scope,'<b>'.$result.'</b>').'<br />');
 		if ($role eq 'st') {
-		    my $result = &classlist_drop($scope,$env{'form.ccuname'},
-						 $env{'form.ccdomain'},$now);
+		    my $result = 
+                        &Apache::lonuserutils::classlist_drop($scope,
+                            $env{'form.ccuname'},$env{'form.ccdomain'},
+			    $now);
 		    $r->print($result);
 		}
-	    } 
+	    }
 	    if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
 # Revoke custom role
 		$r->print(&mt('Revoking custom role:').
@@ -1845,8 +1994,10 @@ END
 	        $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
 			      '<b>'.$result.'</b>').'<br />');
 		if ($role eq 'st') {
-		    my $result = &classlist_drop($scope,$env{'form.ccuname'},
-						 $env{'form.ccdomain'},$now);
+		    my $result = 
+                        &Apache::lonuserutils::classlist_drop($scope,
+                            $env{'form.ccuname'},$env{'form.ccdomain'},
+			    $now);
 		    $r->print($result);
 		}
             }
@@ -2023,6 +2174,23 @@ END
     $r->print(&Apache::loncommon::end_page());
 }
 
+sub get_defaultquota_text {
+    my ($settingstatus) = @_;
+    my $defquotatext; 
+    if ($settingstatus eq '') {
+        $defquotatext = &mt('(default)');
+    } else {
+        my ($usertypes,$order) =
+            &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
+        if ($usertypes->{$settingstatus} eq '') {
+            $defquotatext = &mt('(default)');
+        } else {
+            $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
+        }
+    }
+    return $defquotatext;
+}
+
 sub update_result_form {
     my ($uhome) = @_;
     my $outcome = 
@@ -2045,30 +2213,6 @@ sub update_result_form {
     return $outcome;
 }
 
-sub classlist_drop {
-    my ($scope,$uname,$udom,$now) = @_;
-    my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
-    my $cid=$cdom.'_'.$cnum;
-    my $user = $uname.':'.$udom;
-    if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
-	my $result = 
-	    &Apache::lonnet::cput('classlist',
-				  { $user => $now },
-				  $env{'course.'.$cid.'.domain'},
-				  $env{'course.'.$cid.'.num'});
-	return &mt('Drop from classlist: [_1]',
-		   '<b>'.$result.'</b>').'<br />';
-    }
-}
-
-sub active_student_roles {
-    my ($cnum,$cdom,$uname,$udom) = @_;
-    my %roles = 
-	&Apache::lonnet::get_my_roles($uname,$udom,'userroles',
-				      ['future','active'],['st']);
-    return exists($roles{"$cnum:$cdom:st"});
-}
-
 sub quota_admin {
     my ($setquota,$changeHash) = @_;
     my $quotachanged;
@@ -2412,16 +2556,18 @@ sub handler {
     if ($env{'request.course.id'}) {
         $context = 'course';
     } elsif ($env{'request.role'} =~ /^au\./) {
-        $context = 'construction_space';
+        $context = 'author';
     } else {
         $context = 'domain';
     }
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
-                                            ['action','state']);
+        ['action','state','callingform','roletype','showrole','bulkaction']);
     &Apache::lonhtmlcommon::clear_breadcrumbs();
-    &Apache::lonhtmlcommon::add_breadcrumb
-        ({href=>"/adm/createuser",
-          text=>"User Management"});
+    if ($env{'form.action'} ne 'dateselect') {
+        &Apache::lonhtmlcommon::add_breadcrumb
+            ({href=>"/adm/createuser",
+              text=>"User Management"});
+    }
     my ($permission,$allowed) = &get_permission($context);
     if (!$allowed) {
         $env{'user.error.msg'}=
@@ -2471,7 +2617,7 @@ sub handler {
         if (! exists($env{'form.state'})) {
             &Apache::lonuserutils::print_expire_menu($r,$context);
         } elsif ($env{'form.state'} eq 'done') {
-            &Apache::lonuserutils::expire_user_list($r);
+            &Apache::lonuserutils::expire_user_list($r,$context);
         } else {
             &Apache::lonuserutils::print_expire_menu($r,$context);
         }
@@ -2511,7 +2657,7 @@ sub handler {
                         $response = '';
                     }
                     &print_user_modification_page($r,$ccuname,$ccdomain,
-                                                  $srch,$response);
+                                                  $srch,$response,$context);
                 } elsif ($currstate eq 'query') {
                     &print_user_query_page($r,'createuser');
                 } else {
@@ -2521,10 +2667,11 @@ sub handler {
             } elsif ($env{'form.phase'} eq 'userpicked') {
                 my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
                 my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
-                &print_user_modification_page($r,$ccuname,$ccdomain,$srch);
+                &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
+                                              $context);
             }
         } elsif ($env{'form.phase'} eq 'update_user_data') {
-            &update_user_data($r);
+            &update_user_data($r,$context);
         } else {
             &print_username_entry_form($r,undef,$srch);
         }
@@ -2535,31 +2682,46 @@ sub handler {
             &custom_role_editor($r);
         }
     } elsif ($env{'form.action'} eq 'listusers' && $permission->{'view'}) {
-        my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
-        my $formname = 'studentform';
-        if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
-            ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) = 
-                &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
-                                                        $formname);
-            my $js = &add_script($jscript).$cb_jscript;
-            my $loadcode = 
-                &Apache::lonuserutils::course_selector_loadcode($formname);
-            if ($loadcode ne '') {
-                $r->print(&header($js,{'onload' => $loadcode,}));
+        if ($env{'form.phase'} eq 'bulkchange') {
+            &Apache::lonhtmlcommon::add_breadcrumb
+                ({href=>'backPage(document.studentform)',
+                  text=>"List Users"});
+            my $setting = $env{'form.roletype'};
+            my $choice = $env{'form.bulkaction'};
+            $r->print(&header());
+            $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
+                                                          'User_Management_List'));
+            if ($permission->{'cusr'}) {
+                &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
+            }
+        } else {
+            &Apache::lonhtmlcommon::add_breadcrumb
+                ({href=>'/adm/createuser?action=listusers',
+                  text=>"List Users"});
+            my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
+            my $formname = 'studentform';
+            if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
+                ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) = 
+                    &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
+                                                            $formname);
+                $jscript .= &verify_user_display();
+                my $js = &add_script($jscript).$cb_jscript;
+                my $loadcode = 
+                    &Apache::lonuserutils::course_selector_loadcode($formname);
+                if ($loadcode ne '') {
+                    $r->print(&header($js,{'onload' => $loadcode,}));
+                } else {
+                    $r->print(&header($js));
+                }
             } else {
-                $r->print(&header($js));
+                $r->print(&header(&add_script(&verify_user_display())));
             }
-        } else {
-            $r->print(&header());
+            $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
+                                                          'User_Management_List'));
+            &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
+                         $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
+            $r->print(&Apache::loncommon::end_page());
         }
-        &Apache::lonhtmlcommon::add_breadcrumb
-            ({href=>'/adm/createuser?action=listusers',
-              text=>"List Users"});
-        $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
-                                                      'User_Management_List'));
-        &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
-                     $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
-        $r->print(&Apache::loncommon::end_page());
     } elsif ($env{'form.action'} eq 'expire' && $permission->{'cusr'}) {
         $r->print(&header());
         &Apache::lonhtmlcommon::add_breadcrumb
@@ -2570,26 +2732,37 @@ sub handler {
         if (! exists($env{'form.state'})) {
             &Apache::lonuserutils::print_expire_menu($r,$context);
         } elsif ($env{'form.state'} eq 'done') {
-            &Apache::lonuserutiles::expire_user_list($r);
+            &Apache::lonuserutiles::expire_user_list($r,$context);
         } else {
             &print_expire_menu($r,$context);
         }
         $r->print(&Apache::loncommon::end_page());
+    } elsif ($env{'form.action'} eq 'dateselect') {
+        if ($permission->{'cusr'}) {
+            $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
+                      &Apache::lonuserutils::date_section_selector($context).
+                      &Apache::loncommon::end_page());
+        } else {
+            $r->print(&header().
+                     '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'. 
+                     &Apache::loncommon::end_page());
+        }
     } else {
         $r->print(&header());
-        $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));            $r->print(&print_main_menu($permission));
+        $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
+        $r->print(&print_main_menu($permission));
         $r->print(&Apache::loncommon::end_page());
     }
     return OK;
 }
 
 sub header {
-    my ($jscript,$loaditems) = @_;
+    my ($jscript,$loaditems,$args) = @_;
     my $start_page;
     if (ref($loaditems) eq 'HASH') {
-        $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems,});
+        $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
     } else {
-        $start_page=&Apache::loncommon::start_page('User Management',$jscript);
+        $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
     }
     return $start_page;
 }
@@ -2599,6 +2772,20 @@ sub add_script {
     return '<script type="text/javascript">'."\n".$js."\n".'</script>';
 }
 
+sub verify_user_display {
+    my $output = <<"END";
+
+function display_update() {
+    document.studentform.action.value = 'listusers';
+    document.studentform.phase.value = 'display';
+    document.studentform.submit();
+}
+
+END
+    return $output;
+
+}
+
 ###############################################################
 ###############################################################
 #  Menu Phase One
@@ -2680,7 +2867,7 @@ sub get_permission {
                 }
             }
         }
-    } elsif ($context eq 'construction_space') {
+    } elsif ($context eq 'author') {
         $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
         $permission{'view'} = $permission{'cusr'};
     } else {
@@ -3173,7 +3360,9 @@ sub course_level_table {
 <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
 	        if ($role ne 'cc') {
                     if (%sections_count) {
-                        my $currsec = &course_sections(\%sections_count,$protectedcourse.'_'.$role);
+                        my $currsec = 
+                            &Apache::lonuserutils::course_sections(\%sections_count,
+                                                        $protectedcourse.'_'.$role);
                         $table .= 
                     '<td><table class="LC_createuser">'.
                      '<tr class="LC_section_row">
@@ -3213,7 +3402,9 @@ ENDTIMEENTRY
 <td>'.$plrole.'</td>
 <td>'.$area.'</td>'."\n";
                 if (%sections_count) {
-                    my $currsec = &course_sections(\%sections_count,$customrole);
+                    my $currsec = 
+                        &Apache::lonuserutils::course_sections(\%sections_count,
+                                                               $customrole);
                     $table.=
                    '<td><table class="LC_createuser">'.
                    '<tr class="LC_section_row"><td valign="top">'.
@@ -3257,28 +3448,6 @@ $table.
     return $result;
 }
 
-sub course_sections {
-    my ($sections_count,$role) = @_;
-    my $output = '';
-    my @sections = (sort {$a <=> $b} keys %{$sections_count});
-    if (scalar(@sections) == 1) {
-        $output = '<select name="currsec_'.$role.'" >'."\n".
-                  '  <option value="">Select</option>'."\n".
-                  '  <option value="">No section</option>'."\n".
-                  '  <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
-    } else {
-        $output = '<select name="currsec_'.$role.'" ';
-        my $multiple = 4;
-        if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
-        $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
-        foreach my $sec (@sections) {
-            $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
-        }
-    }
-    $output .= '</select>'; 
-    return $output;
-}
-
 sub course_level_dc {
     my ($dcdom) = @_;
     my %customroles=&Apache::lonuserutils::my_custom_roles();