--- loncom/auth/lonroles.pm 2004/11/09 18:18:02 1.104 +++ loncom/auth/lonroles.pm 2004/11/11 23:17:13 1.107 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.104 2004/11/09 18:18:02 raeburn Exp $ +# $Id: lonroles.pm,v 1.107 2004/11/11 23:17:13 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -83,7 +83,8 @@ sub handler { my $then=$ENV{'user.login.time'}; my $envkey; my $dcselect=''; - + my %dcroles = (); + my $numdc = &check_fordc(\%dcroles,$then); # ================================================================== Roles Init if ($ENV{'form.selectrole'}) { @@ -120,6 +121,33 @@ sub handler { "request.role" => 'cm', "request.role.adv" => $ENV{'user.adv'}, "request.role.domain" => $ENV{'user.domain'}); + +# Check to see if the user is a DC trying to enter a course and needs privs to be created + if ($numdc > 0) { + foreach my $envkey (keys %ENV) { + if ($envkey =~ m-^form\.cc\./(\w+)/(\w+)$-) { + if ($dcroles{$1}) { + unless ($ENV{'user.role.cc./'.$1.'/'.$2}) { + &set_privileges($1,$2); + } + } + last; + } + } + } + + if ($ENV{'form.dccourse'}) { + my $dcdom = $ENV{'form.dcdomain'}; + my $pickedcourse = $ENV{'form.dccourse'}; + if ($dcdom && $pickedcourse) { + unless ($ENV{'user.role.cc./'.$dcdom.'/'.$pickedcourse}) { + if ($ENV{'user.role.dc./'.$dcdom.'/'}) { + &set_privileges($dcdom,$pickedcourse); + } + } + } + } + foreach $envkey (keys %ENV) { next if ($envkey!~/^user\.role\./); my ($where,$trolecode,$role,$tstatus,$tend,$tstart); @@ -264,7 +292,6 @@ ENDENTERKEY } # Check to see if the user is a DC coming from the # course selection page - my $dcflag = 0; if ($ENV{'form.dccourse'}) { my $formaction = '/adm/roles/'; my ($dcdom,$pickedcourse) = split/_/,$courseid; @@ -408,9 +435,6 @@ ENDHEADER $r->print('>'); } - my %dcroles = (); - my $numdc = &check_fordc(\%dcroles,$then); - my (%roletext,%sortrole,%roleclass); my $countactive=0; my $inrole=0; @@ -539,8 +563,7 @@ ENDHEADER ''; } } else { - my %newhash=Apache::lonnet::coursedescription - ($tcourseid); + my %newhash=&Apache::lonnet::coursedescription($tcourseid); if (%newhash) { $sortkey=$role."\0".$tdom."\0".$newhash{'description'}. "\0".$envkey; @@ -676,7 +699,7 @@ ENDHEADER foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) { my $skiprole = 0; foreach my $dcdom (keys %dcroles) { - if ($sortrole{$which} =~ m-(dc|cc)\./$dcdom/-) { + if ($sortrole{$which} =~ m-(dc)\./$dcdom/-) { $skiprole = 1; last; } @@ -707,7 +730,7 @@ ENDHEADER $r->print("