--- loncom/auth/lonroles.pm 2004/11/11 22:18:23 1.106 +++ loncom/auth/lonroles.pm 2006/01/06 21:04:33 1.145 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.106 2004/11/11 22:18:23 raeburn Exp $ +# $Id: lonroles.pm,v 1.145 2006/01/06 21:04:33 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -30,7 +30,7 @@ package Apache::lonroles; use strict; -use Apache::lonnet(); +use Apache::lonnet; use Apache::lonuserstate(); use Apache::Constants qw(:common); use Apache::File(); @@ -39,6 +39,7 @@ use Apache::loncommon; use Apache::lonhtmlcommon; use Apache::lonannounce; use Apache::lonlocal; +use GDBM_File; sub redirect_user { my ($r,$title,$url,$msg,$launch_nav) = @_; @@ -49,7 +50,8 @@ sub redirect_user { my $swinfo=&Apache::lonmenu::rawconfig(); my $navwindow; if ($launch_nav eq 'on') { - $navwindow.=&Apache::lonnavmaps::launch_win('now'); + $navwindow.=&Apache::lonnavmaps::launch_win('now',undef,undef, + ($url =~ m-^/adm/whatsnew-)); } else { $navwindow.=&Apache::lonnavmaps::close(); } @@ -80,97 +82,78 @@ sub handler { my $r = shift; my $now=time; - my $then=$ENV{'user.login.time'}; + my $then=$env{'user.login.time'}; my $envkey; - my $dcselect=''; - + my %dcroles = (); + my $numdc = &check_fordc(\%dcroles,$then); # ================================================================== Roles Init - if ($ENV{'form.selectrole'}) { - if ($ENV{'form.dcselected'}) { - my $dcdom = $ENV{'form.dcselected'}; - my $dckey = 'user.role.dc./'.$dcdom.'/'; - if ($ENV{$dckey}) { - my ($dcstart,$dcend)=split(/\./,$ENV{$dckey}); - my $active_dc = 1; - if ($dcstart) { - if ($dcstart>$then) { - $active_dc = 0; - } - } - if ($dcend) { - if ($dcend < $then) { - $active_dc = 0; - } - } - if ($active_dc) { - $dcselect = $dcdom; - } - } - } - if ($ENV{'request.course.id'}) { - my %temp=('logout_'.$ENV{'request.course.id'} => time); + if ($env{'form.selectrole'}) { + if ($env{'form.newrole'}) { + $env{'form.'.$env{'form.newrole'}}=1; + } + if ($env{'request.course.id'}) { + my %temp=('logout_'.$env{'request.course.id'} => time); &Apache::lonnet::put('email_status',\%temp); - &Apache::lonnet::delenv('user.state.'.$ENV{'request.course.id'}); + &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'}); } &Apache::lonnet::appenv("request.course.id" => '', "request.course.fn" => '', "request.course.uri" => '', "request.course.sec" => '', "request.role" => 'cm', - "request.role.adv" => $ENV{'user.adv'}, - "request.role.domain" => $ENV{'user.domain'}); + "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 -# course selection page - my $dcflag = 0; - 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); - my $msg=&mt('Entering course ...'); - my ($furl,$ferr)=&Apache::lonuserstate::readmap($dcdom.'/'.$pickedcourse); - my $formaction = '/adm/roles/'; - my $courseid = $dcdom.'_'.$pickedcourse; - &Apache::lonhtmlcommon::store_recent('cc_pickby_dc_'.$dcdom, - $courseid,$formaction); - # Send the user to the course they selected - &redirect_user($r,&mt('Entering Course'), - $furl,$msg, - $ENV{'environment.remotenavmap'}); - return OK; +# Check if 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}) { + my $cckey = 'user.role.cc./'.$1.'/'.$2; + &check_privs($cckey,$then,$now); } + last; } } } - foreach $envkey (keys %ENV) { + foreach $envkey (keys %env) { next if ($envkey!~/^user\.role\./); my ($where,$trolecode,$role,$tstatus,$tend,$tstart); &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend); - if ($ENV{'form.'.$trolecode}) { + if ($env{'form.'.$trolecode}) { if ($tstatus eq 'is') { $where=~s/^\///; my ($cdom,$cnum,$csec)=split(/\//,$where); +# check for course groups + my %coursegroups = &Apache::lonnet::get_active_groups( + $env{'user.domain'},$env{'user.name'},$cdom, $cnum); + my $cgrps = join(':',keys(%coursegroups)); + +# store role if recent_role list being kept + if ($env{'environment.recentroles'}) { + &Apache::lonhtmlcommon::store_recent('roles', + $trolecode,' '); + } + + # check for keyed access if (($role eq 'st') && - ($ENV{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) { + ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) { # who is key authority? my $authdom=$cdom; my $authnum=$cnum; - if ($ENV{'course.'.$cdom.'_'.$cnum.'.keyauth'}) { + if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) { ($authnum,$authdom)= - split(/\W/,$ENV{'course.'.$cdom.'_'.$cnum.'.keyauth'}); + split(/\W/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'}); } # check with key authority unless (&Apache::lonnet::validate_access_key( - $ENV{'environment.key.'.$cdom.'_'.$cnum}, + $env{'environment.key.'.$cdom.'_'.$cnum}, $authdom,$authnum)) { # there is no valid key - if ($ENV{'form.newkey'}) { + if ($env{'form.newkey'}) { # student attempts to register a new key &Apache::loncommon::content_type($r,'text/html'); &Apache::loncommon::no_cache($r); @@ -182,11 +165,11 @@ sub handler { my $message=&mt('Successfully registered key'); my $assignresult= &Apache::lonnet::assign_access_key( - $ENV{'form.newkey'}, + $env{'form.newkey'}, $authdom,$authnum, $cdom,$cnum, - $ENV{'user.domain'}, - $ENV{'user.name'}, + $env{'user.domain'}, + $env{'user.name'}, 'Assigned from '.$ENV{'REMOTE_ADDR'}.' at '.localtime().' for '. $trolecode); unless ($assignresult eq 'ok') { @@ -232,7 +215,7 @@ $swinfo