--- loncom/auth/lonroles.pm 2008/05/14 19:18:37 1.189
+++ loncom/auth/lonroles.pm 2008/07/05 17:50:57 1.198
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.189 2008/05/14 19:18:37 www Exp $
+# $Id: lonroles.pm,v 1.198 2008/07/05 17:50:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -137,39 +137,36 @@ 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
-
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});
- }
- 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
+ # 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;
}
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;
- }
+ 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;
}
@@ -504,17 +501,14 @@ ENDHEADER
$r->print('');
$r->print('');
}
- if ($env{'user.adv'}) {
- $r->print(
- '
');
- }
-
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='';
@@ -551,9 +545,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';
@@ -669,6 +667,18 @@ ENDHEADER
}
}
}
+ if ($env{'user.adv'}) {
+ $r->print(
+ '
');
+ } else {
+ if ($countactive > 0) {
+ my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
+ $r->print('
'.&mt('[_1]Visit the [_2]Course Catalog[_3] to view all [_4] LON-CAPA courses.','','','',$domdesc).'
'.&mt('If a course is [_1]not[_2] in your list of current courses below, you may be able to enroll if self-enrollment is permitted.','','').'
'); } - $r->print(' | '.&mt('User Role').' | '.&mt('Extent'). - ' | '.&mt('Start').' | '.&mt('End').' |
---|---|---|---|---|
". - &mt('Recent Roles')." | "); + &mt('Recent Roles')."||||
".&mt($type)." | '); + &mt('Select').'" name="cm" />'); } else { $r->print(' | '); } } $r->print(' | '.&mt('No role specified'). - ' | '.$tremark. + ' | '.$tremark. ' | '."\n"); $r->print('
This is LON-CAPA '.
- $r->dir_config('lonVersion').'
'.
- ''.&mt('Logout').'
'
+ .&mt('This is LON-CAPA [_1]',$r->dir_config('lonVersion'))
+ .'
'
+ .''.&mt('Logout').' '
+ .''.&mt('Course Catalog')
+ .'
'); } + $r->print(' | '.&mt('User Role').' | '.&mt('Extent') + .' | '.&mt('Start').' | '.&mt('End') + .' | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
". + &mt($type)." | '; + $trolecode."','".$buttonname.'\');" />'; } elsif ($tryagain) { $roletext.= ' | '; + $trolecode."','".$buttonname.'\');" />'; } elsif ($advanced) { $roletext.= ' | '; + $trolecode."','".$buttonname.'\');" />'; } else { $roletext.=' | '; } @@ -932,18 +1014,21 @@ sub build_roletext { return $roletext; } -sub is_author_homeserver { +sub check_author_homeserver { my ($uname,$udom)=@_; + if (($uname eq '') || ($udom eq '')) { + return ('fail',''); + } my $home = &Apache::lonnet::homeserver($uname,$udom); + if (&Apache::lonnet::host_domain($home) ne $udom) { + return ('fail',$home); + } my @ids=&Apache::lonnet::current_machine_ids(); - foreach my $id (@ids) { - if ($id eq $home) { - if (-e "/home/".$uname."/public_html") { - return 1; - } - } + if (grep(/^\Q$home\E$/,@ids)) { + return ('ok',$home); + } else { + return ('switchserver',$home); } - return 0; } sub check_privs { @@ -988,17 +1073,17 @@ sub adhoc_course_role { my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; if (&check_forcc($cdom,$cnum,$then)) { my $setprivs; - if (!defined($env{'user.role.'.$env{'form.selectrole'}})) { + if (!defined($env{'user.role.'.$env{'form.switchrole'}})) { $setprivs = 1; } else { - my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.selectrole'}}); + my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}}); if (($start && ($start>$then || $start == -1)) || ($end && $end<$then)) { $setprivs = 1; } } if ($setprivs) { - if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E(/?\w*)$-) { + if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) { my $role = $1; my $custom_role = $2; my $usec = $3; @@ -1045,7 +1130,7 @@ sub check_forcc { } sub courselink { - my ($dcdom,$rowtype,$selecttype) = @_; + my ($dcdom,$rowtype) = @_; my $courseform=&Apache::loncommon::selectcourse_link ('rolechoice','dccourse'.$rowtype.'_'.$dcdom, 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'. @@ -1097,6 +1182,13 @@ END return $verify_script; } +sub coauthorlink { + my ($dcdom,$rowtype) = @_; + my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom); + my $hiddenitems = ''; + return $coauthorform.$hiddenitems; +} + sub display_cc_role { my $rolekey = shift; my $roletext; @@ -1129,28 +1221,22 @@ sub display_cc_role { return ($roletext); } -sub allcourses_row { +sub adhoc_roles_row { my ($dcdom,$rowtype) = @_; my $output = ' | |||||||||||||||||||
'; - my $selectlink = &courselink($dcdom,$rowtype); + ' |
| ||||||||||||||||||||||