--- loncom/auth/lonroles.pm 2012/08/14 17:35:04 1.271
+++ loncom/auth/lonroles.pm 2012/12/27 18:31:09 1.278
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.271 2012/08/14 17:35:04 raeburn Exp $
+# $Id: lonroles.pm,v 1.278 2012/12/27 18:31:09 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -141,7 +141,7 @@ use Apache::loncoursequeueadmin;
use GDBM_File;
use LONCAPA qw(:DEFAULT :match);
use HTML::Entities;
-
+
sub redirect_user {
my ($r,$title,$url,$msg) = @_;
@@ -211,9 +211,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,106 +229,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') {
- my $start = $now-1;
- if (&Apache::lonnet::assignrole($env{'user.domain'},$env{'user.name'},'/'.$env{'user.domain'}.'/',
- 'au',undef,$start,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
@@ -367,8 +291,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;
}
@@ -591,6 +517,12 @@ ENDENTERKEY
my $msg;
my ($furl,$ferr)=
&Apache::lonuserstate::readmap($cdom.'/'.$cnum);
+ unless (($ferr) || ($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);
+ }
if (($env{'form.orgurl'}) &&
($env{'form.orgurl'}!~/^\/adm\/flip/)) {
my $dest=$env{'form.orgurl'};
@@ -647,11 +579,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);
+ my $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'}),
@@ -737,15 +710,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 .= '