--- loncom/auth/lonroles.pm 2004/07/21 19:54:43 1.95
+++ loncom/auth/lonroles.pm 2005/06/05 07:10:32 1.120
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.95 2004/07/21 19:54:43 albertel Exp $
+# $Id: lonroles.pm,v 1.120 2005/06/05 07:10:32 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,14 +30,16 @@
package Apache::lonroles;
use strict;
-use Apache::lonnet();
+use Apache::lonnet;
use Apache::lonuserstate();
use Apache::Constants qw(:common);
use Apache::File();
use Apache::lonmenu;
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) = @_;
@@ -46,8 +48,11 @@ sub redirect_user {
&Apache::loncommon::no_cache($r);
$r->send_http_header;
my $swinfo=&Apache::lonmenu::rawconfig();
+ my $navwindow;
if ($launch_nav eq 'on') {
- $swinfo.=&Apache::lonnavmaps::launch_win('now','no');
+ $navwindow.=&Apache::lonnavmaps::launch_win('now');
+ } else {
+ $navwindow.=&Apache::lonnavmaps::close();
}
my $bodytag=&Apache::loncommon::bodytag('Switching Role');
# Note to style police:
@@ -59,9 +64,10 @@ sub redirect_user {
$bodytag
-
+$navwindow
$msg
Continue
@@ -75,60 +81,70 @@ sub handler {
my $r = shift;
my $now=time;
- my $then=$ENV{'user.login.time'};
+ my $then=$env{'user.login.time'};
my $envkey;
-
+ my %dcroles = ();
+ my $numdc = &check_fordc(\%dcroles,$then);
# ================================================================== Roles Init
-
- if ($ENV{'form.selectrole'}) {
- if ($ENV{'request.course.id'}) {
- my %temp=('logout_'.$ENV{'request.course.id'} => time);
+ if ($env{'form.selectrole'}) {
+ 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::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'});
- foreach $envkey (keys %ENV) {
+ "request.role.adv" => $env{'user.adv'},
+ "request.role.domain" => $env{'user.domain'});
+
+# 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) {
next if ($envkey!~/^user\.role\./);
- my (undef,undef,$role,@pwhere)=split(/\./,$envkey);
- my $where=join('.',@pwhere);
- my $trolecode=$role.'.'.$where;
- if ($ENV{'form.'.$trolecode}) {
- my ($tstart,$tend)=split(/\./,$ENV{$envkey});
- my $tstatus='is';
- if ($tstart) {
- if ($tstart>$then) {
- $tstatus='future';
- }
- }
- if ($tend) {
- if ($tend<$then) { $tstatus='expired'; }
- if ($tend<$now) { $tstatus='will_not'; }
- }
+ my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
+ &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
+ if ($env{'form.'.$trolecode}) {
if ($tstatus eq 'is') {
$where=~s/^\///;
my ($cdom,$cnum,$csec)=split(/\//,$where);
+# 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);
@@ -140,11 +156,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') {
@@ -190,7 +206,7 @@ $swinfo