--- loncom/auth/lonroles.pm 2012/08/14 15:45:25 1.270
+++ loncom/auth/lonroles.pm 2013/05/21 23:13:40 1.286
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.270 2012/08/14 15:45:25 raeburn Exp $
+# $Id: lonroles.pm,v 1.286 2013/05/21 23:13:40 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -138,10 +138,12 @@ 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) = @_;
@@ -211,9 +213,17 @@ sub handler {
$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.doupdate'}) {
+ if ($env{'form.state'} eq 'doupdate') {
my $show_course=&Apache::loncommon::show_course();
my $checkingtxt;
if ($show_course) {
@@ -221,105 +231,22 @@ sub handler {
} else {
$checkingtxt = &mt('Checking for new roles ...');
}
- $updateresult = ''.$checkingtxt.'';
+ $updateresult = $checkingtxt;
$updateresult .= &update_session_roles();
&Apache::lonnet::appenv({'user.update.time' => $now});
$update = $now;
- &reqauthor_check();
+ &Apache::loncoursequeueadmin::reqauthor_check();
}
# -------------------------------------------------- Check for author requests
-
my $reqauthor;
- if ($env{'form.requestauthor'}) {
- if ($env{'environment.canrequest.author'}) {
- unless (&is_active_author()) {
- my $queued = &reqauthor_check();
- my $skipreq;
- if ($queued =~ /^approval:\d+$/) {
- my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
- if ($status eq 'approval') {
- $reqauthor = ''.
- &mt('A request for authoring space submitted on [_1] is awaiting approval',
- &Apache::lonlocal::locallocaltime($timestamp)).
- '';
- }
- $skipreq = 1;
- } elsif ($queued =~ /^approved:\d+$/) {
- my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
- ['active'],['au'],[$env{'user.domain'}]);
- if (keys(%roleshash) > 0) {
- $skipreq = 1;
- }
- }
- unless ($skipreq) {
- my (@inststatuses,%domconfig);
- %domconfig =
- &Apache::lonnet::get_dom('configuration',
- ['requestauthor'],$env{'user.domain'});
- my $val = &Apache::loncoursequeueadmin::get_processtype('requestauthor',$env{'user.name'},
- $env{'user.domain'},$env{'user.adv'},
- $env{'user.domain'},undef,
- \@inststatuses,\%domconfig);
- if ($val eq 'automatic') {
- if (&Apache::lonnet::assignrole($env{'user.domain'},$env{'user.name'},'/'.$env{'user.domain'}.'/',
- 'au',undef,$now,undef,undef,'requestauthor') eq 'ok') {
- $reqauthor = ''.
- &mt('Access to authoring space has been activated').'
';
- &update_session_roles();
- &Apache::lonnet::appenv({'user.update.time' => $now});
- $update = $now;
- } else {
- $reqauthor = ''.
- &mt('An error occurred while activating your access to authoring space');
- }
- } elsif ($val eq 'approval') {
- my $domconfiguser = &Apache::lonnet::get_domainconfiguser($env{'user.domain'});
- if (&Apache::lonnet::put('requestauthorqueue',{ $env{'user.name'}.'_'.$val => $now },
- $env{'user.domain'},$domconfiguser) eq 'ok') {
- my %userrequest = (
- author => {
- timestamp => $now,
- status => $val,
- },
- author_status => $val,
- );
- my $req_notifylist;
- if (ref($domconfig{'requestauthor'}) eq 'HASH') {
- if (ref($domconfig{'requestauthor'}{'notify'}) eq 'HASH') {
- my $req_notifylist = $domconfig{'requestauthor'}{'notify'}{'approval'};
- if ($req_notifylist) {
- my $fullname = &Apache::loncommon::plainname($env{'user.name'},
- $env{'user.domain'});
- my $sender = $env{'user.name'}.':'.$env{'user.domain'};
- my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
- &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,
- "$fullname ($env{'user.name'}:$env{'user.domain'})",undef,$domdesc,
- $now,'authorreq',$sender);
- }
- }
- }
- my $userresult =
- &Apache::lonnet::put('requestauthor',\%userrequest,$env{'user.domain'},$env{'user.name'});
- $reqauthor = ''.
- &mt('Your request for authoring space has been submitted for approval.').
- '';
- &Apache::lonnet::appenv({'environment.requestauthorqueued' => $val.':'.$now});
- } else {
- $reqauthor = ''.
- &mt('An error occurred saving your request for authoring space.').
- '';
- }
- }
- }
- }
- }
+ if ($env{'form.state'} eq 'requestauthor') {
+ $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update);
}
my $envkey;
my %dcroles = ();
my $numdc = &check_fordc(\%dcroles,$update,$then);
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'};
# ================================================================== Roles Init
@@ -366,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,
- $update,$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;
}
@@ -382,6 +311,7 @@ sub handler {
my $trolecode = 'au./'.$domain.'/';
my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
$r->internal_redirect($switchserver);
+ return OK;
}
last;
}
@@ -393,6 +323,7 @@ sub handler {
my $trolecode = 'ca./'.$domain.'/'.$user;
my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
$r->internal_redirect($switchserver);
+ return OK;
}
last;
}
@@ -414,6 +345,7 @@ sub handler {
my $switchserver = '/adm/switchserver?'
.'otherserver='.$home.'&role='.$trolecode;
$r->internal_redirect($switchserver);
+ return OK;
}
} else {
delete($env{$envkey});
@@ -590,6 +522,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'};
@@ -646,11 +599,52 @@ 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'}),
@@ -736,15 +730,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(<
';
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.').'
'.&mt('Course/Community requests').'
'.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ '
'.&mt('Enrollment requests').'
'.
+ $queuedselfenroll.'
'.&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 .= '