--- loncom/auth/lonroles.pm 2007/11/09 20:56:34 1.181
+++ loncom/auth/lonroles.pm 2008/05/14 23:52:52 1.191
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.181 2007/11/09 20:56:34 albertel Exp $
+# $Id: lonroles.pm,v 1.191 2008/05/14 23:52:52 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -106,29 +106,87 @@ 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\./($match_domain)/($match_courseid)$-)) {
+ # See if that is even allowed
+ my %crsenv=&Apache::lonnet::get('environment',['internal.courseowner'],$domain,$coursenum);
+ # First find course owner
+ my ($owneruser,$ownerdomain)=split(/\:/,$crsenv{'internal.courseowner'});
+ # Check if course owner blocked cc-access
+ if (($owneruser) && ($ownerdomain)) {
+ my %blocked=&Apache::lonnet::get('environment',['domcoord.cc'],$ownerdomain,$owneruser);
+ if ($blocked{'domcoord.cc'} eq 'blocked') {
+ $env{'user.error.msg'}=':::1:Course owner '.$owneruser.' in domain '.$ownerdomain.' blocked domain coordinator access';
+ last;
+ }
+ }
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)$-)) {
+ # See if still allowed
+ my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
+ if ($blocked{'domcoord.author'} eq 'blocked') {
+ delete($env{$envkey});
+ $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
+ last;
+ }
+ 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)$-)) {
+ my $user=$env{'form.adhoccauname.'.$domain};
+ if (!$user) { $user=$env{'form.adhoccaunamerecent.'.$domain} };
+ # See if that is even allowed
+ my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
+ if ($blocked{'domcoord.author'} eq 'blocked') {
+ $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
+ last;
+ }
+ if ($dcroles{$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;
}
@@ -245,10 +303,10 @@ ENDENTERKEY
"Role ".$trolecode);
&Apache::lonnet::appenv(
- 'request.role' => $trolecode,
- 'request.role.domain' => $cdom,
- 'request.course.sec' => $csec,
- 'request.course.groups' => $cgrps);
+ {'request.role' => $trolecode,
+ 'request.role.domain' => $cdom,
+ 'request.course.sec' => $csec,
+ 'request.course.groups' => $cgrps});
my $tadv=0;
if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
@@ -259,7 +317,7 @@ ENDENTERKEY
($env{'form.orgurl'}!~/^\/adm\/flip/)) {
my $dest=$env{'form.orgurl'};
if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
- &Apache::lonnet::appenv('request.role.adv'=>$tadv);
+ &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
if (($ferr) && ($tadv)) {
&error_page($r,$ferr,$dest);
} else {
@@ -269,7 +327,7 @@ ENDENTERKEY
} else {
if (!$env{'request.course.id'}) {
&Apache::lonnet::appenv(
- "request.course.id" => $cdom.'_'.$cnum);
+ {"request.course.id" => $cdom.'_'.$cnum});
$furl='/adm/roles?tryagain=1';
$msg=
'
'.
@@ -278,7 +336,7 @@ ENDENTERKEY
'
'.&mt('Please try again.').'
'.$ferr;
}
if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
- &Apache::lonnet::appenv('request.role.adv'=>$tadv);
+ &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
if (($ferr) && ($tadv)) {
&error_page($r,$ferr,$furl);
@@ -295,6 +353,14 @@ ENDENTERKEY
$furl = "/adm/helper/course.initialization.helper";
# Send the user to the course they selected
} elsif ($env{'request.course.id'}) {
+ if ($env{'form.destinationurl'}) {
+ my $dest = $env{'form.destinationurl'};
+ &redirect_user($r,&mt('Entering [_1]',
+ $env{'course.'.$courseid.'.description'}),
+ $dest,$msg,
+ $env{'environment.remotenavmap'});
+ return OK;
+ }
if (&Apache::lonnet::allowed('whn',
$env{'request.course.id'})
|| &Apache::lonnet::allowed('whn',
@@ -365,7 +431,7 @@ ENDENTERKEY
my $start_page=&Apache::loncommon::start_page('User Roles');
my $standby=&mt('Role selected. Please stand by.');
$standby=~s/\n/\\n/g;
- my $noscript=''.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'
'.&mt('As this is not the case, most functionality in the system will ba unavailable.').'
';
+ my $noscript=''.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'
'.&mt('As this is not the case, most functionality in the system will be unavailable.').'
';
$r->print(<print("LON-CAPA Access Control
");
+ $r->print("".&mt('LON-CAPA Access Control')."
");
$r->print("
");
if ($priv ne '') {
- $r->print("Access : ".&Apache::lonnet::plaintext($priv)."\n");
+ $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n");
}
if ($fn ne '') {
- $r->print("Resource: ".&Apache::lonenc::check_encrypt($fn)."\n");
+ $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
}
if ($msg ne '') {
- $r->print("Action : $msg\n");
+ $r->print(&mt('Action : ').$msg."\n");
}
$r->print("
");
my $url=$fn;
@@ -464,8 +530,12 @@ ENDHEADER
my (%roletext,%sortrole,%roleclass);
my $countactive=0;
+ my $countfuture=0;
+ my $countwill=0;
my $inrole=0;
my $possiblerole='';
+ my %futureroles;
+ my %roles_nextlogin;
foreach $envkey (sort keys %env) {
my $button = 1;
my $switchserver='';
@@ -502,9 +572,13 @@ ENDHEADER
} elsif ($tstatus eq 'future') {
$tbg='#FFFF77';
$button=0;
+ $futureroles{$trolecode} = $tstart.':'.$tend;
+ $countfuture ++;
} elsif ($tstatus eq 'will') {
$tbg='#FFAA77';
$tremark.=&mt('Active at next login. ');
+ $roles_nextlogin{$trolecode} = $tstart.':'.$tend;
+ $countwill ++;
} elsif ($tstatus eq 'expired') {
$tbg='#FF7777';
$tfont='#330000';
@@ -627,7 +701,30 @@ ENDHEADER
} else {
$r->print(''.&mt('Currently no active roles or courses').'
');
}
- $r->print(''.&Apache::loncommon::end_page());
+ &findcourse_advice($r);
+ $r->print('');
+ if ($countfuture) {
+ $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
+ my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
+ $nochoose);
+ &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
+ \%roletext);
+ my $tremark='';
+ my $tfont='#003300';
+ if ($env{'request.role'} eq 'cm') {
+ $r->print('');
+ $tremark=&mt('Currently selected. ');
+ $tfont='#002200';
+ } else {
+ $r->print('
');
+ }
+ $r->print(' | '.&mt('No role specified').
+ ' | '.$tremark.
+ ' |
'."\n");
+
+ $r->print('');
+ }
+ $r->print(&Apache::loncommon::end_page());
return OK;
# Is there only one choice?
} elsif (($countactive==1) && ($env{'request.role'} eq 'cm')) {
@@ -645,21 +742,7 @@ ENDHEADER
unless ((!&Apache::lonmenu::show_course()) || ($nochoose)) {
$r->print("".&mt('Select a Course to Enter')."
\n");
}
- $r->print('