--- loncom/auth/lonroles.pm 2006/06/02 13:58:37 1.153
+++ loncom/auth/lonroles.pm 2008/05/12 23:47:37 1.188
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.153 2006/06/02 13:58:37 raeburn Exp $
+# $Id: lonroles.pm,v 1.188 2008/05/12 23:47:37 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -40,8 +40,9 @@ use Apache::lonhtmlcommon;
use Apache::lonannounce;
use Apache::lonlocal;
use Apache::lonpageflip();
+use Apache::lonnavdisplay();
use GDBM_File;
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
sub redirect_user {
@@ -53,8 +54,8 @@ sub redirect_user {
my $swinfo=&Apache::lonmenu::rawconfig();
my $navwindow;
if ($launch_nav eq 'on') {
- $navwindow.=&Apache::lonnavmaps::launch_win('now',undef,undef,
- ($url =~ m-^/adm/whatsnew-));
+ $navwindow.=&Apache::lonnavdisplay::launch_win('now',undef,undef,
+ ($url =~ m-^/adm/whatsnew-));
} else {
$navwindow.=&Apache::lonnavmaps::close();
}
@@ -88,7 +89,7 @@ sub error_page {
&Apache::lonmenu::rawconfig().''.
'
'.&mt('The following problems occurred:').
$error.
- '
'.&mt('Continue').''.
&Apache::loncommon::end_page());
}
@@ -105,29 +106,62 @@ sub handler {
# ================================================================== Roles Init
if ($env{'form.selectrole'}) {
+
+ my $locknum=&Apache::lonnet::get_locks();
+ if ($locknum) { return 409; }
+
if ($env{'form.newrole'}) {
$env{'form.'.$env{'form.newrole'}}=1;
}
if ($env{'request.course.id'}) {
+ # Check if user is CC trying to select a course role
+ if ($env{'form.switchrole'}) {
+ if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
+ &adhoc_course_role($then);
+ }
+ }
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'});
-
-# Check if user is a DC trying to enter a course and needs privs to be created
+ &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'}});
+# Check if user is a DC trying to enter a course or author space and needs privs to be created
if ($numdc > 0) {
foreach my $envkey (keys %env) {
+# Is this an ad-hoc CC-role?
if (my ($domain,$coursenum) =
- ($envkey =~ m-^form\.cc\./(\w+)/(\w+)$-)) {
+ ($envkey =~ m-^form\.cc\./($match_domain)/($match_courseid)$-)) {
if ($dcroles{$domain}) {
- &check_privs($domain,$coursenum,$then,$now);
+ &check_privs($domain,$coursenum,$then,$now,'cc');
+ }
+ last;
+ }
+# Is this a recent ad-hoc CA-role?
+ if (my ($domain,$user) =
+ ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
+ if (($dcroles{$domain}) && (&is_author_homeserver($user,$domain))) {
+ &check_privs($domain,$user,$then,$now,'ca');
+ } else {
+ delete($env{$envkey});
+ }
+ last;
+ }
+# Is this a new ad-hoc CA-role?
+ if (my ($domain) =
+ ($envkey =~ m-^form\.adhocca\./($match_domain)$-)) {
+ if ($dcroles{$domain}) {
+ my $user=$env{'form.adhoccauname.'.$domain};
+ if (!$user) { $user=$env{'form.adhoccaunamerecent.'.$domain} };
+ if (($user) && ($user=~/$match_username/) && (&is_author_homeserver($user,$domain))) {
+ &check_privs($domain,$user,$then,$now,'ca');
+ $env{'form.ca./'.$domain.'/'.$user}=1;
+ }
}
last;
}
@@ -149,8 +183,10 @@ sub handler {
# store role if recent_role list being kept
if ($env{'environment.recentroles'}) {
+ my %frozen_roles =
+ &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
&Apache::lonhtmlcommon::store_recent('roles',
- $trolecode,' ');
+ $trolecode,' ',$frozen_roles{$trolecode});
}
@@ -162,7 +198,7 @@ sub handler {
my $authnum=$cnum;
if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
($authnum,$authdom)=
- split(/\W/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
+ split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
}
# check with key authority
unless (&Apache::lonnet::validate_access_key(
@@ -198,7 +234,7 @@ sub handler {
}
$r->print(<
+