--- 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("". "".&mt($type).""); } - $r->print($output); + $r->print($output); } } } @@ -810,11 +833,9 @@ sub role_status { $$trolecode=$$role.'.'.$$where; ($$tstart,$$tend)=split(/\./,$ENV{$rolekey}); $$tstatus='is'; - if ($$tstart) { - if ($$tstart>$then) { - $$tstatus='future'; - if ($$tstart<$now) { $$tstatus='will'; } - } + if ($$tstart && $$tstart>$then) { + $$tstatus='future'; + if ($$tstart<$now) { $$tstatus='will'; } } if ($$tend) { if ($$tend<$then) { @@ -848,19 +869,11 @@ sub check_fordc { my $dcdom = $1; my $livedc = 1; my ($tstart,$tend)=split(/\./,$ENV{$envkey}); - if ($tstart) { - if ($tstart>$then) { - $livedc = 0; - } - } - if ($tend) { - if ($tend<$then) { - $livedc = 0; - } - } + if ($tstart && $tstart>$then) { $livedc = 0; } + if ($tend && $tend <$then) { $livedc = 0; } if ($livedc) { $$dcroles{$dcdom} = $envkey; - $numdc ++; + $numdc++; } } } @@ -1020,6 +1033,35 @@ sub recent_filename { return 'nohist_recent_'.&Apache::lonnet::escape($area); } +sub set_privileges { + my ($dcdom,$pickedcourse) = @_; + my $area = '/'.$dcdom.'/'.$pickedcourse; + my $role = 'cc'; + my $spec = $role.'.'.$area; + my $userroles = &Apache::lonnet::set_arearole($role,$area,'','',$dcdom,$ENV{'user.name'}); + my %ccrole = (); + &Apache::lonnet::standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area); + my ($author,$adv)= &Apache::lonnet::set_userprivs(\$userroles,\%ccrole); + my @newprivs = split/\n/,$userroles; + my %newccroles = (); + foreach (@newprivs) { + my ($key,$val) = split/=/,$_; + $newccroles{$key} = $val; + } + &Apache::lonnet::appenv(%newccroles); + &Apache::lonnet::log($ENV{'user.domain'}, + $ENV{'user.name'}, + $ENV{'user.home'}, + "Role ".$role); + &Apache::lonnet::appenv( + 'request.role' => $role, + 'request.role.domain' => $dcdom, + 'request.course.sec' => ''); + my $tadv=0; + if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; } + &Apache::lonnet::appenv('request.role.adv' => $tadv); +} + 1; __END__