--- loncom/interface/loncreateuser.pm 2007/12/24 16:00:13 1.224 +++ loncom/interface/loncreateuser.pm 2007/12/31 01:58:17 1.225 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.224 2007/12/24 16:00:13 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.225 2007/12/31 01:58:17 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2030,15 +2030,18 @@ END if ($env{'form.action'} eq 'singlestudent') { &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser); } else { - my $rolechanges = &update_roles($r); - if (!$rolechanges && $namechanged) { + my @rolechanges = &update_roles($r); + if ($namechanged) { if ($context eq 'course') { if (@userroles > 0) { - if (grep(/^st$/,@userroles)) { - my $classlistupdated = - &Apache::lonuserutils::update_classlist($cdom, + if ((@rolechanges == 0) || + (!(grep(/^st$/,@rolechanges)))) { + if (grep(/^st$/,@userroles)) { + my $classlistupdated = + &Apache::lonuserutils::update_classlist($cdom, $cnum,$env{'form.ccdomain'}, $env{'form.ccuname'},\%userupdate); + } } } } @@ -2050,7 +2053,7 @@ END sub update_roles { my ($r) = @_; my $now=time; - my $rolechanges = 0; + my @rolechanges; my %disallowed; $r->print('

'.&mt('Modifying Roles').'

'); foreach my $key (keys (%env)) { @@ -2074,6 +2077,9 @@ sub update_roles { $now); $r->print($result); } + if (!grep(/^\Q$role\E$/,@rolechanges)) { + push(@rolechanges,$role); + } } if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) { # Revoke custom role @@ -2082,8 +2088,10 @@ sub update_roles { &Apache::lonnet::revokecustomrole($env{'form.ccdomain'}, $env{'form.ccuname'},$1,$2,$3,$4). '
'); + if (!grep(/^cr$/,@rolechanges)) { + push(@rolechanges,'cr'); + } } - $rolechanges ++; } elsif ($key=~/^form\.del/) { if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) { # Delete standard role @@ -2101,6 +2109,9 @@ sub update_roles { $now); $r->print($result); } + if (!grep(/^\Q$role\E$/,@rolechanges)) { + push(@rolechanges,$role); + } } if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) { my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4); @@ -2110,8 +2121,10 @@ sub update_roles { &Apache::lonnet::assigncustomrole($env{'form.ccdomain'}, $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now, 0,1).'
'); + if (!grep(/^cr$/,@rolechanges)) { + push(@rolechanges,'cr'); + } } - $rolechanges ++; } elsif ($key=~/^form\.ren/) { my $udom = $env{'form.ccdomain'}; my $uname = $env{'form.ccuname'}; @@ -2144,6 +2157,9 @@ sub update_roles { $role,$url,$result).'
'; } $r->print($output); + if (!grep(/^\Q$role\E$/,@rolechanges)) { + push(@rolechanges,$role); + } } # Re-enable custom role if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) { @@ -2153,8 +2169,10 @@ sub update_roles { $url,$rdom,$rnam,$rolename,0,$now); $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : [_5]', $rolename,$rnam,$rdom,$url,$result).'
'); + if (!grep(/^cr$/,@rolechanges)) { + push(@rolechanges,'cr'); + } } - $rolechanges ++; } elsif ($key=~/^form\.act/) { my $udom = $env{'form.ccdomain'}; my $uname = $env{'form.ccuname'}; @@ -2189,6 +2207,9 @@ sub update_roles { $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end)); } } + if (!grep(/^cr$/,@rolechanges)) { + push(@rolechanges,'cr'); + } } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) { # Activate roles for sections with 3 id numbers # set start, end times, and the url for the class @@ -2227,7 +2248,10 @@ sub update_roles { if ($emptysec) { $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'')); } - } + } + if (!grep(/^\Q$three\E$/,@rolechanges)) { + push(@rolechanges,$three); + } } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) { # Activate roles for sections with two id numbers # set start, end times, and the url for the class @@ -2237,26 +2261,31 @@ sub update_roles { my $end = ( $env{'form.end_'.$1.'_'.$2} ? $env{'form.end_'.$1.'_'.$2} : 0 ); - my $url='/'.$1.'/'; + my $one = $1; + my $two = $2; + my $url='/'.$one.'/'; # split multiple sections my %sections = (); - my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2); + my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two); if ($num_sections == 0) { - $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,'')); + $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'')); } else { my $emptysec = 0; foreach my $sec (sort {$a cmp $b} keys %sections) { if ($sec ne '') { my $securl = $url.'/'.$sec; - $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec)); + $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec)); } else { $emptysec = 1; } } if ($emptysec) { - $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,'')); + $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'')); } } + if (!grep(/^\Q$two\E$/,@rolechanges)) { + push(@rolechanges,$two); + } } else { $r->print('

'.&mt('ERROR').': '.&mt('Unknown command').' '.$key.'


'); } @@ -2268,15 +2297,14 @@ sub update_roles { } $r->print(' '.&mt('Please go back and choose a different section name.').'


'); } - $rolechanges ++; } } # End of foreach (keys(%env)) # Flush the course logs so reverse user roles immediately updated &Apache::lonnet::flushcourselogs(); - if (!$rolechanges) { + if (@rolechanges == 0) { $r->print(&mt('No roles to modify')); } - return $rolechanges; + return @rolechanges; } sub enroll_single_student {