--- loncom/auth/lonroles.pm 2008/05/12 23:47:37 1.188
+++ loncom/auth/lonroles.pm 2008/05/19 17:55:38 1.193
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.188 2008/05/12 23:47:37 www Exp $
+# $Id: lonroles.pm,v 1.193 2008/05/19 17:55:38 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -137,31 +137,48 @@ sub handler {
# 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,'cc');
}
last;
}
-# Is this a recent ad-hoc CA-role?
+# Is this an 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});
+ # Check if author blocked ca-access
+ 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;
}
- 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;
- }
+ my ($server_status,$home) = &check_author_homeserver($user,$domain);
+ if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
+ &check_privs($domain,$user,$then,$now,'ca');
+ if ($server_status eq 'switchserver') {
+ my $trolecode = 'ca./'.$domain.'/'.$user;
+ my $switchserver = '/adm/switchserver?'
+ .'otherserver='.$home.'&role='.$trolecode;
+ $r->internal_redirect($switchserver);
+ }
+ } else {
+ delete($env{$envkey});
+ }
+ } else {
+ delete($env{$envkey});
}
last;
}
@@ -505,8 +522,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='';
@@ -543,9 +564,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';
@@ -668,7 +693,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')) {
@@ -686,21 +734,7 @@ ENDHEADER
unless ((!&Apache::lonmenu::show_course()) || ($nochoose)) {
$r->print("".&mt('Select a Course to Enter')."
\n");
}
- $r->print('
');
@@ -793,6 +806,87 @@ ENDHEADER
return OK;
}
+sub roletable_headers {
+ my ($r,$roleclass,$sortrole,$nochoose) = @_;
+ my $doheaders;
+ if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
+ $r->print('