--- loncom/auth/lonroles.pm 2014/05/05 11:37:41 1.256.2.8
+++ loncom/auth/lonroles.pm 2013/05/09 05:24:42 1.284
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.256.2.8 2014/05/05 11:37:41 raeburn Exp $
+# $Id: lonroles.pm,v 1.284 2013/05/09 05:24:42 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -57,8 +57,7 @@ course they should act on, etc. Both in
handler determines via C's C<&allowed> function that a certain
action is not allowed, C is used as error handler. This
allows the user to select another role which may have permission to do
-what they were trying to do. C can also be accessed via the
-B button in the Remote Control.
+what they were trying to do.
=begin latex
@@ -139,25 +138,19 @@ use Apache::lonlocal;
use Apache::lonpageflip();
use Apache::lonnavdisplay();
use Apache::loncoursequeueadmin;
+use Apache::longroup;
+use Apache::lonrss;
use GDBM_File;
use LONCAPA qw(:DEFAULT :match);
use HTML::Entities;
sub redirect_user {
- my ($r,$title,$url,$msg,$launch_nav) = @_;
+ my ($r,$title,$url,$msg) = @_;
$msg = $title if (! defined($msg));
&Apache::loncommon::content_type($r,'text/html');
&Apache::loncommon::no_cache($r);
$r->send_http_header;
- my $swinfo=&Apache::lonmenu::rawconfig();
- my $navwindow;
- if ($launch_nav eq 'on') {
- $navwindow.=&Apache::lonnavdisplay::launch_win('now',undef,undef,
- ($url =~ m-^/adm/whatsnew-));
- } else {
- $navwindow.=&Apache::lonnavmaps::close();
- }
# Breadcrumbs
my $brcrum = [{'href' => $url,
@@ -172,12 +165,6 @@ sub redirect_user {
$url=~s/ /\%20/g;
$r->print(<
-//
-
-$navwindow
$msg
$end_page
ENDREDIR
@@ -218,13 +205,48 @@ sub handler {
my $now=time;
my $then=$env{'user.login.time'};
my $refresh=$env{'user.refresh.time'};
+ my $update=$env{'user.update.time'};
if (!$refresh) {
$refresh = $then;
}
+ if (!$update) {
+ $update = $then;
+ }
+
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
+
+# -------------------------------------------------- Check if setting hot list
+ my $hotlist;
+ if ($env{'form.action'} eq 'verify_and_change_rolespref') {
+ $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r);
+ }
+
+# -------------------------------------------------------- Check for new roles
+ my $updateresult;
+ if ($env{'form.state'} eq 'doupdate') {
+ my $show_course=&Apache::loncommon::show_course();
+ my $checkingtxt;
+ if ($show_course) {
+ $checkingtxt = &mt('Checking for new courses ...');
+ } else {
+ $checkingtxt = &mt('Checking for new roles ...');
+ }
+ $updateresult = $checkingtxt;
+ $updateresult .= &update_session_roles();
+ &Apache::lonnet::appenv({'user.update.time' => $now});
+ $update = $now;
+ &Apache::loncoursequeueadmin::reqauthor_check();
+ }
+
+# -------------------------------------------------- Check for author requests
+ my $reqauthor;
+ if ($env{'form.state'} eq 'requestauthor') {
+ $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update);
+ }
+
my $envkey;
my %dcroles = ();
- my $numdc = &check_fordc(\%dcroles,$then);
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
+ my $numdc = &check_fordc(\%dcroles,$update,$then);
my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'};
# ================================================================== Roles Init
@@ -243,13 +265,13 @@ sub handler {
if (defined($env{'user.role.'.$env{'form.switchrole'}})) {
my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
if (!$end || $end > $now) {
- if (!$start || $start < $refresh) {
+ if (!$start || $start < $update) {
$switch_is_active = 1;
}
}
}
unless ($switch_is_active) {
- &adhoc_course_role($refresh,$then);
+ &adhoc_course_role($refresh,$update,$then);
}
}
my %temp=('logout_'.$env{'request.course.id'} => time);
@@ -260,6 +282,7 @@ sub handler {
"request.course.fn" => '',
"request.course.uri" => '',
"request.course.sec" => '',
+ "request.course.tied" => '',
"request.role" => 'cm',
"request.role.adv" => $env{'user.adv'},
"request.role.domain" => $env{'user.domain'}});
@@ -270,8 +293,10 @@ sub handler {
if (my ($ccrole,$domain,$coursenum) =
($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
if ($dcroles{$domain}) {
- &Apache::lonnet::check_adhoc_privs($domain,$coursenum,
- $then,$refresh,$now,$ccrole);
+ if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,
+ $update,$refresh,$now,$ccrole)) {
+ &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time});
+ }
}
last;
}
@@ -311,7 +336,7 @@ sub handler {
if ($dcroles{$domain}) {
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,
+ &Apache::lonnet::check_adhoc_privs($domain,$user,$update,
$refresh,$now,'ca');
if ($server_status eq 'switchserver') {
my $trolecode = 'ca./'.$domain.'/'.$user;
@@ -333,7 +358,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,$refresh,$now,\$role,\$where,
+ &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
\$trolecode,\$tstatus,\$tstart,\$tend);
if ($env{'form.'.$trolecode}) {
if ($tstatus eq 'is') {
@@ -494,6 +519,27 @@ ENDENTERKEY
my $msg;
my ($furl,$ferr)=
&Apache::lonuserstate::readmap($cdom.'/'.$cnum);
+ unless ($ferr) {
+ unless (($env{'form.switchrole'}) ||
+ ($env{"environment.internal.$cdom.$cnum.$role.adhoc"})) {
+ &Apache::lonnet::put('nohist_crslastlogin',
+ {$env{'user.name'}.':'.$env{'user.domain'}.
+ ':'.$csec.':'.$role => $now},$cdom,$cnum);
+ }
+ my ($feeds,$syllabus_time);
+ &Apache::lonrss::advertisefeeds($cnum,$cdom,undef,\$feeds);
+ &Apache::lonnet::appenv({'request.course.feeds' => $feeds});
+ unless ($env{'course.'.$cdom.'_'.$cnum.'.updatedsyllabus'}) {
+ unless (($env{'course.'.$cdom.'_'.$cnum.'.externalsyllabus'}) ||
+ ($env{'course.'.$cdom.'_'.$cnum.'.uploadedsyllabus'})) {
+ my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
+ $syllabus_time = $syllabus{'uploaded.lastmodified'};
+ if ($syllabus_time) {
+ &Apache::lonnet::appenv({'request.course.syllabustime' => $syllabus_time});
+ }
+ }
+ }
+ }
if (($env{'form.orgurl'}) &&
($env{'form.orgurl'}!~/^\/adm\/flip/)) {
my $dest=$env{'form.orgurl'};
@@ -513,7 +559,8 @@ ENDENTERKEY
if ($dest =~ m{^/adm/coursedocs\?folderpath}) {
if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
- &update_content_constraints($cdom,$cnum,$chome,$cdom.'_'.$cnum);
+ &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,
+ $cdom.'_'.$cnum);
}
}
$r->internal_redirect($dest);
@@ -549,16 +596,56 @@ 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'};
- if ($env{'form.destsymb'} ne '') {
- my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&');
- $dest .= '?symb='.$esc_symb;
+ my ($dest,$destsymb,$checkenc);
+ $dest = $env{'form.destinationurl'};
+ $destsymb = $env{'form.destsymb'};
+ if ($dest ne '') {
+ if ($env{'form.switchrole'}) {
+ if ($destsymb ne '') {
+ if ($destsymb !~ m{^/enc/}) {
+ unless ($env{'request.role.adv'}) {
+ $checkenc = 1;
+ }
+ }
+ }
+ if ($dest =~ m{^/enc/}) {
+ if ($env{'request.role.adv'}) {
+ $dest = &Apache::lonenc::unencrypted($dest);
+ if ($destsymb eq '') {
+ ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/);
+ $destsymb = &unescape($destsymb);
+ }
+ }
+ } else {
+ if ($destsymb eq '') {
+ ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]+)/);
+ $destsymb = &unescape($destsymb);
+ }
+ unless ($env{'request.role.adv'}) {
+ $checkenc = 1;
+ }
+ }
+ if (($checkenc) && ($destsymb ne '')) {
+ my ($encstate,$unencsymb,$res);
+ $unencsymb = &Apache::lonnet::symbclean($destsymb);
+ (undef,undef,$res) = &Apache::lonnet::decode_symb($unencsymb);
+ &Apache::lonnet::symbverify($unencsymb,$res,\$encstate);
+ if ($encstate) {
+ if (($dest ne '') && ($dest !~ m{^/enc/})) {
+ $dest=&Apache::lonenc::encrypted($dest);
+ }
+ }
+ }
+ }
+ unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) {
+ if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) {
+ my $esc_symb = &escape($destsymb);
+ $dest .= '?symb='.$esc_symb;
+ }
}
&redirect_user($r, &mt('Entering [_1]',
$env{'course.'.$courseid.'.description'}),
- $dest, $msg,
- $env{'environment.remotenavmap'});
+ $dest, $msg);
return OK;
}
if (&Apache::lonnet::allowed('whn',
@@ -571,26 +658,22 @@ ENDENTERKEY
unless ($startpage eq 'firstres') {
$msg = &mt('Entering [_1] ...',
$env{'course.'.$courseid.'.description'});
- &redirect_user($r,&mt('New in course'),
- '/adm/whatsnew?refpage=start',$msg,
- $env{'environment.remotenavmap'});
+ &redirect_user($r, &mt('New in course'),
+ '/adm/whatsnew?refpage=start', $msg);
return OK;
}
}
}
# Are we allowed to look at the first resource?
- if (($furl !~ m|^/adm/|) ||
- (($env{'environment.remotenavmap'} eq 'on') &&
- ($furl =~ m{^/adm/navmaps}))) {
+ if ($furl !~ m|^/adm/|) {
# Guess not ...
$furl=&Apache::lonpageflip::first_accessible_resource();
}
$msg = &mt('Entering [_1] ...',
$env{'course.'.$courseid.'.description'});
- &redirect_user($r,&mt('Entering [_1]',
- $env{'course.'.$courseid.'.description'}),
- $furl,$msg,
- $env{'environment.remotenavmap'});
+ &redirect_user($r, &mt('Entering [_1]',
+ $env{'course.'.$courseid.'.description'}),
+ $furl, $msg);
}
return OK;
}
@@ -600,10 +683,9 @@ ENDENTERKEY
if ($role =~ /^(au|ca|aa)$/) {
my $redirect_url = '/priv/';
if ($role eq 'au') {
- $redirect_url.=$env{'user.name'};
+ $redirect_url.=$env{'user.domain'}.'/'.$env{'user.name'};
} else {
- $where =~ /\/(.*)$/;
- $redirect_url .= $1;
+ $redirect_url .= $where;
}
$redirect_url .= '/';
&redirect_user($r,&mt('Entering Construction Space'),
@@ -645,15 +727,20 @@ ENDENTERKEY
$recent = &mt('Recent Courses');
}
my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
+
+ my %roles_in_env;
+ my $showcount = &roles_from_env(\%roles_in_env,$update);
+
my $swinfo=&Apache::lonmenu::rawconfig();
my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});
+ my $funcs = &get_roles_functions($showcount);
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 be 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(<
+$funcs
@@ -673,8 +760,22 @@ function enterrole (thisform,rolecode,bu
thisform.submit();
} else {
alert('$standby');
- }
+ }
}
+
+function rolesView (caller) {
+ if ((caller == 'showall') || (caller == 'noshowall')) {
+ document.rolechoice.display.value = caller;
+ } else {
+ if ((caller == 'doupdate') || (caller == 'requestauthor') ||
+ (caller == 'queued')) {
+ document.rolechoice.state.value = caller;
+ }
+ }
+ document.rolechoice.selectrole.value='';
+ document.rolechoice.submit();
+}
+
// ]]>
ENDHEADER
@@ -735,39 +836,49 @@ ENDHEADER
}
}
}
-# -------------------------------------------------------- Choice or no choice?
if ($nochoose) {
$r->print("
".&mt('Sorry ...')."
\n".
&mt('This action is currently not authorized.').''.
&Apache::loncommon::end_page());
return OK;
} else {
+ if ($updateresult || $reqauthor || $hotlist) {
+ my $showresult = '
';
+ $r->print($showresult);
+ } elsif ($env{'form.state'} eq 'queued') {
+ $r->print(&get_queued());
+ }
if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
$fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
}
+ my $display = ($env{'form.display'} =~ /^(showall)$/);
$r->print(''.
+ ''.
+ ''.
+ ''.
+ &mt('Your section has changed for your current [_1] role in [_2].',$rolename,$coursedesc).' ';
+ my $button = '';
+ if ($newsec[0] eq 'none') {
+ $msg .= &mt('[_1] to continue with your new section-less role.',$button);
+ } else {
+ $msg .= &mt('[_1] to continue with your new role in section ([_2]).',$button,$newsec[0]);
+ }
+ $msg .= '
';
+ if (&Apache::loncommon::show_course()) {
+ $msg .= &mt('Your role in the current course has expired.');
+ } else {
+ $msg .= &mt('Your current role has expired.');
+ }
+ $msg .= ' '.&mt('However you can continue to use this role until you logout, click the "Re-Select" button, or your session has been idle for more than 24 hours.').'
';
+ }
+ &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
+ my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
+ $curr_author = $env{'user.author'};
+ if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
+ ($env{'request.role'} =~/^aa/)) {
+ $curr_role_author=1;
+ }
+ $curr_is_adv = $env{'user.adv'};
+ $curr_role_adv = $env{'request.role.adv'};
+ if (keys(%userroles) > 0) {
+ foreach my $role (@changed_roles) {
+ unless(grep(/^\Q$role\E$/,@rolecodes)) {
+ push(@rolecodes,$role);
+ }
+ }
+ unless(grep(/^\Qcm\E$/,@rolecodes)) {
+ push(@rolecodes,'cm');
+ }
+ &Apache::lonnet::appenv(\%userroles,\@rolecodes);
+ }
+ my %newenv;
+ if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
+ unless ($curr_is_adv) {
+ $newenv{'user.adv'} = 1;
+ }
+ } elsif ($curr_is_adv && !$curr_role_adv) {
+ &Apache::lonnet::delenv('user.adv');
+ }
+ my %authorroleshash =
+ &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
+ if (keys(%authorroleshash)) {
+ unless ($curr_author) {
+ $newenv{'user.author'} = 1;
+ }
+ } elsif ($curr_author && !$curr_role_author) {
+ &Apache::lonnet::delenv('user.author');
+ }
+ if ($env{'request.course.id'}) {
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my (@activecrsgroups,$crsgroupschanged);
+ if ($env{'request.course.groups'}) {
+ @activecrsgroups = split(/:/,$env{'request.course.groups'});
+ foreach my $item (keys(%deletedroles)) {
+ if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
+ if (grep(/^\Q$1\E$/,@activecrsgroups)) {
+ $crsgroupschanged = 1;
+ last;
+ }
+ }
+ }
+ }
+ unless ($crsgroupschanged) {
+ foreach my $item (keys(%newgroup)) {
+ if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
+ if ($newgroup{$item} eq 'active') {
+ $crsgroupschanged = 1;
+ last;
+ }
+ }
+ }
+ }
+ if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
+ (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
+ ($crsgroupschanged)) {
+ my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
+ ['active'],['gr'],[$cdom],1);
+ my @activegroups;
+ foreach my $item (keys(%grouproles)) {
+ next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
+ my $group;
+ my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
+ if ($remainder =~ /:/) {
+ (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
+ } else {
+ $group = $remainder;
+ }
+ if ($group ne '') {
+ push(@activegroups,$group);
+ }
+ }
+ $newenv{'request.course.groups'} = join(':',@activegroups);
+ }
+ }
+ if (keys(%newenv)) {
+ &Apache::lonnet::appenv(\%newenv);
+ }
+ if (!@changed_roles || !(keys(%changed_groups))) {
+ my ($rolesmsg,$groupsmsg);
+ if (!@changed_roles) {
+ if (&Apache::loncommon::show_course()) {
+ $rolesmsg = &mt('No new courses or communities');
+ } else {
+ $rolesmsg = &mt('No role changes');
+ }
+ }
+ if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
+ $groupsmsg = &mt('No changes in course/community groups');
+ }
+ if (!@changed_roles && !(keys(%changed_groups))) {
+ if (($msg ne '') || ($groupsmsg ne '')) {
+ $msg .= '
';
+ if ($rolesmsg) {
+ $msg .= '
'.$rolesmsg.'
';
+ }
+ if ($groupsmsg) {
+ $msg .= '
'.$groupsmsg.'
';
+ }
+ $msg .= '
';
+ } else {
+ $msg = ' '.$rolesmsg.' ';
+ }
+ return $msg;
+ }
+ }
+ my $changemsg;
+ if (@changed_roles > 0) {
+ if (keys(%newgroup) > 0) {
+ my $groupmsg;
+ my (%curr_groups,%groupdescs,$currcrs);
+ foreach my $item (sort(keys(%newgroup))) {
+ if (&is_active_course($item,$refresh,$update,\%roleshash)) {
+ if ($item =~ m{^gr\./($match_domain/$match_courseid)/(\w+)$}) {
+ my ($cdom,$cnum) = split(/\//,$1);
+ my $group = $2;
+ if ($currcrs ne $cdom.'_'.$cnum) {
+ if ($currcrs) {
+ $groupmsg .= '
';
+ }
+ if ($env{'environment.canrequest.author'}) {
+ unless (&Apache::loncoursequeueadmin::is_active_author()) {
+ my $requestauthor;
+ my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
+ if (($status eq 'approval') || ($status eq 'approved')) {
+ $output .= '
'.&mt('Author role request').' ';
+ if ($status eq 'approval') {
+ $output .= &mt('A request for authoring space submitted on [_1] is awaiting approval',
+ &Apache::lonlocal::locallocaltime($timestamp));
+ } elsif ($status eq 'approved') {
+ my %roleshash =
+ &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
+ ['active'],['au'],[$env{'user.domain'}]);
+ if (keys(%roleshash)) {
+ $output .= ''.
+ &mt('Your request for an author role has been approved.').' '.
+ &mt('Use the "Check for changes" link to update your list of roles.').
+ '';
+ }
+ }
+ $output .= '
';
+ }
+ }
+ }
+ unless ($output) {
+ if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} ||
+ $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) {
+ $output = &mt('No requests for courses, communities or authoring currently queued');
+ } else {
+ $output = &mt('No enrollment requests currently queued awaiting approval');
+ }
+ }
+ return ' ';
+}
+
1;
__END__
@@ -1849,8 +2826,7 @@ course they should act on, etc. Both in
handler determines via C's C<&allowed> function that a certain
action is not allowed, C is used as error handler. This
allows the user to select another role which may have permission to do
-what they were trying to do. C can also be accessed via the
-B button in the Remote Control.
+what they were trying to do.
=begin latex