--- loncom/auth/lonroles.pm 2009/05/22 17:57:03 1.225
+++ loncom/auth/lonroles.pm 2010/01/02 18:49:20 1.231.4.6
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.225 2009/05/22 17:57:03 bisitz Exp $
+# $Id: lonroles.pm,v 1.231.4.6 2010/01/02 18:49:20 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -157,8 +157,9 @@ sub redirect_user {
} else {
$navwindow.=&Apache::lonnavmaps::close();
}
+
my $start_page = &Apache::loncommon::start_page('Switching Role',undef,
- {'redirect' => [1,$url],});
+ {'redirect' => [1,$url]});
my $end_page = &Apache::loncommon::end_page();
# Note to style police:
@@ -191,9 +192,10 @@ sub error_page {
'// ]]>'.
''.
'
'.&mt('The following problems occurred:').
+ '
'.
$error.
'
'.&mt('Continue').''.
- &Apache::loncommon::end_page());
+ &Apache::loncommon::end_page());
}
sub handler {
@@ -202,6 +204,10 @@ sub handler {
my $now=time;
my $then=$env{'user.login.time'};
+ my $refresh=$env{'user.refresh.time'};
+ if (!$refresh) {
+ $refresh = $then;
+ }
my $envkey;
my %dcroles = ();
my $numdc = &check_fordc(\%dcroles,$then);
@@ -220,7 +226,7 @@ sub handler {
# 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);
+ &adhoc_course_role($refresh,$then);
}
}
my %temp=('logout_'.$env{'request.course.id'} => time);
@@ -242,7 +248,7 @@ sub handler {
($envkey =~ m-^form\.cc\./($match_domain)/($match_courseid)$-)) {
if ($dcroles{$domain}) {
&Apache::lonnet::check_adhoc_privs($domain,$coursenum,
- $then,$now,'cc');
+ $then,$refresh,$now,'cc');
}
last;
}
@@ -283,7 +289,7 @@ sub handler {
my ($server_status,$home) = &check_author_homeserver($user,$domain);
if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
&Apache::lonnet::check_adhoc_privs($domain,$user,$then,
- $now,'ca');
+ $refresh,$now,'ca');
if ($server_status eq 'switchserver') {
my $trolecode = 'ca./'.$domain.'/'.$user;
my $switchserver = '/adm/switchserver?'
@@ -304,7 +310,7 @@ sub handler {
foreach $envkey (keys %env) {
next if ($envkey!~/^user\.role\./);
my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
- &Apache::lonnet::role_status($envkey,$then,$now,\$role,\$where,
+ &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
\$trolecode,\$tstatus,\$tstart,\$tend);
if ($env{'form.'.$trolecode}) {
if ($tstatus eq 'is') {
@@ -653,11 +659,12 @@ ENDHEADER
if ($reinit) {
$r->print(
''.
- &mt('As your session file for the course has expired, you will need to re-select the course.').'
');
+ &mt('As your session file for the course or community has expired, you will need to re-select the course.').'');
} else {
$r->print(
''.
- &mt('You need to choose another user role or enter a specific course for this function').'
');
+ &mt('You need to choose another user role or enter a specific course or community for this function.').
+ '');
}
}
}
@@ -676,173 +683,14 @@ ENDHEADER
$r->print('');
$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;
- my %timezones;
- foreach $envkey (sort keys %env) {
- my $button = 1;
- my $switchserver='';
- my ($roletext,$roletext_end);
- my $sortkey;
- if ($envkey=~/^user\.role\./) {
- my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);
- &Apache::lonnet::role_status($envkey,$then,$now,\$role,\$where,
- \$trolecode,\$tstatus,\$tstart,\$tend);
- next if (!defined($role) || $role eq '' || $role =~ /^gr/);
- my $timezone = &role_timezone($where,\%timezones);
- $tremark='';
- $tpstart=' ';
- $tpend=' ';
- if ($tstart) {
- $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
- }
- if ($tend) {
- $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
- }
- if ($env{'request.role'} eq $trolecode) {
- $tstatus='selected';
- }
- my $tbg;
- if (($tstatus eq 'is')
- || ($tstatus eq 'selected')
- || ($tstatus eq 'will')
- || ($tstatus eq 'future')
- || ($env{'form.showall'})) {
- if ($tstatus eq 'is') {
- $tbg='LC_roles_is';
- $possiblerole=$trolecode;
- $countactive++;
- } elsif ($tstatus eq 'future') {
- $tbg='LC_roles_future';
- $button=0;
- $futureroles{$trolecode} = $tstart.':'.$tend;
- $countfuture ++;
- } elsif ($tstatus eq 'will') {
- $tbg='LC_roles_will';
- $tremark.=&mt('Active at next login.').' ';
- $roles_nextlogin{$trolecode} = $tstart.':'.$tend;
- $countwill ++;
- } elsif ($tstatus eq 'expired') {
- $tbg='LC_roles_expired';
- $button=0;
- } elsif ($tstatus eq 'will_not') {
- $tbg='LC_roles_will_not';
- $tremark.=&mt('Expired after logout.').' ';
- } elsif ($tstatus eq 'selected') {
- $tbg='LC_roles_selected';
- $inrole=1;
- $countactive++;
- $tremark.=&mt('Currently selected.').' ';
- }
- my $trole;
- if ($role =~ /^cr\//) {
- my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
- if ($tremark) { $tremark.='
'; }
- $tremark.=&mt('Defined by [_1] at [_2].',$rauthor,$rdomain);
- }
- $trole=Apache::lonnet::plaintext($role);
- my $ttype;
- my $twhere;
- my ($tdom,$trest,$tsection)=
- split(/\//,Apache::lonnet::declutter($where));
- # First, Co-Authorship roles
- if (($role eq 'ca') || ($role eq 'aa')) {
- my $home = &Apache::lonnet::homeserver($trest,$tdom);
- my $allowed=0;
- my @ids=&Apache::lonnet::current_machine_ids();
- foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
- if (!$allowed) {
- $button=0;
- $switchserver='otherserver='.$home.'&role='.$trolecode;
- }
- #next if ($home eq 'no_host');
- $home = &Apache::lonnet::hostname($home);
- $ttype='Construction Space';
- $twhere=&mt('User').': '.$trest.'
'.&mt('Domain').
- ': '.$tdom.'
'.
- ' '.&mt('Server').': '.$home;
- $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
- $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
- $sortkey=$role."$trest:$tdom";
- } elsif ($role eq 'au') {
- # Authors
- my $home = &Apache::lonnet::homeserver
- ($env{'user.name'},$env{'user.domain'});
- my $allowed=0;
- my @ids=&Apache::lonnet::current_machine_ids();
- foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
- if (!$allowed) {
- $button=0;
- $switchserver='otherserver='.$home.'&role='.$trolecode;
- }
- #next if ($home eq 'no_host');
- $home = &Apache::lonnet::hostname($home);
- $ttype='Construction Space';
- $twhere=&mt('Domain').': '.$tdom.'
'.&mt('Server').
- ': '.$home;
- $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
- $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
- $sortkey=$role;
- } elsif ($trest) {
- my $tcourseid=$tdom.'_'.$trest;
- $ttype = &Apache::loncommon::course_type($tcourseid);
- $trole = &Apache::lonnet::plaintext($role,$ttype);
- if ($env{'course.'.$tcourseid.'.description'}) {
- $twhere=$env{'course.'.$tcourseid.'.description'};
- $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
- unless ($twhere eq &mt('Currently not available')) {
- $twhere.=' '.
- &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
- '';
- }
- } else {
- my %newhash=&Apache::lonnet::coursedescription($tcourseid);
- if (%newhash) {
- $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
- "\0".$envkey;
- $twhere=$newhash{'description'}.
- ' '.
- &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
- '';
- $ttype = $newhash{'type'};
- $trole = &Apache::lonnet::plaintext($role,$ttype);
- } else {
- $twhere=&mt('Currently not available');
- $env{'course.'.$tcourseid.'.description'}=$twhere;
- $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
- $ttype = 'Unavailable';
- }
- }
- if ($tsection) {
- $twhere.='
'.&mt('Section').': '.$tsection;
- }
- if ($role ne 'st') { $twhere.="
".&mt('Domain').":".$tdom; }
- } elsif ($tdom) {
- $ttype='Domain';
- $twhere=$tdom;
- $sortkey=$role.$twhere;
- } else {
- $ttype='System';
- $twhere=&mt('system wide');
- $sortkey=$role.$twhere;
- }
- ($roletext,$roletext_end) =
- &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
- $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
- $tpend,$nochoose,$button,$switchserver,$reinit);
- $roletext{$envkey}=[$roletext,$roletext_end];
- if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
- $sortrole{$sortkey}=$envkey;
- $roleclass{$envkey}=$ttype;
- }
- }
- }
+
+ my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
+ my ($countactive,$countfuture,$inrole,$possiblerole) =
+ &gather_roles($then,$refresh,$now,$reinit,$nochoose,\%roletext,\%sortrole,\%roleclass,
+ \%futureroles,\%timezones);
+
+ $refresh = $now;
+ &Apache::lonnet::appenv({'user.refresh.time' => $refresh});
if ($env{'user.adv'}) {
$r->print(
'');
+ }
+ }
+ return;
+}
+
sub queued_selfenrollment {
my ($r) = @_;
my %selfenrollrequests = &Apache::lonnet::dump('selfenrollrequests');
@@ -1358,21 +1441,21 @@ sub check_fordc {
}
sub adhoc_course_role {
- my ($then) = @_;
+ my ($refresh,$then) = @_;
my ($cdom,$cnum);
$cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
$cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- if (&check_forcc($cdom,$cnum,$then)) {
+ if (&check_forcc($cdom,$cnum,$refresh,$then)) {
my $setprivs;
if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
$setprivs = 1;
} else {
my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
- if (($start && ($start>$then || $start == -1)) ||
+ if (($start && ($start>$refresh || $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*)$-) {
my $role = $1;
@@ -1402,7 +1485,7 @@ sub adhoc_course_role {
}
&Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
&Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
- my $adhocstart = $then-1;
+ my $adhocstart = $refresh-1;
$userroles{'user.role.'.$spec} = $adhocstart.'.';
&Apache::lonnet::appenv(\%userroles,[$role,'cm']);
}
@@ -1412,7 +1495,7 @@ sub adhoc_course_role {
}
sub check_forcc {
- my ($cdom,$cnum,$then) = @_;
+ my ($cdom,$cnum,$refresh,$then) = @_;
my $is_cc;
if ($cdom ne '' && $cnum ne '') {
if (&Apache::lonnet::is_course($cdom,$cnum)) {
@@ -1420,7 +1503,7 @@ sub check_forcc {
if (defined($env{$envkey})) {
$is_cc = 1;
my ($tstart,$tend)=split(/\./,$env{$envkey});
- if ($tstart && $tstart>$then) { $is_cc = 0; }
+ if ($tstart && $tstart>$refresh) { $is_cc = 0; }
if ($tend && $tend <$then) { $is_cc = 0; }
}
}
@@ -1443,8 +1526,8 @@ sub courselink {
sub coursepick_jscript {
my %lt = &Apache::lonlocal::texthash(
- plsu => "Please use the 'Select Course' link to open a separate pick course window where you may select the course you wish to enter.",
- youc => 'You can only use this screen to select courses in the current domain.',
+ plsu => "Please use the 'Select Course/Community' link to open a separate pick course window where you may select the course or community you wish to enter.",
+ youc => 'You can only use this screen to select courses and communities in the current domain.',
);
my $verify_script = <<"END";