--- loncom/auth/lonroles.pm 2014/05/05 11:44:18 1.269.2.19
+++ loncom/auth/lonroles.pm 2014/05/22 14:32:48 1.307
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.269.2.19 2014/05/05 11:44:18 raeburn Exp $
+# $Id: lonroles.pm,v 1.307 2014/05/22 14:32:48 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -128,7 +128,7 @@ package Apache::lonroles;
use strict;
use Apache::lonnet;
use Apache::lonuserstate();
-use Apache::Constants qw(:common);
+use Apache::Constants qw(:common REDIRECT);
use Apache::File();
use Apache::lonmenu;
use Apache::loncommon;
@@ -143,7 +143,7 @@ use Apache::lonrss;
use GDBM_File;
use LONCAPA qw(:DEFAULT :match);
use HTML::Entities;
-
+
sub redirect_user {
my ($r,$title,$url,$msg) = @_;
@@ -151,7 +151,6 @@ sub redirect_user {
&Apache::loncommon::content_type($r,'text/html');
&Apache::loncommon::no_cache($r);
$r->send_http_header;
- my $swinfo=&Apache::lonmenu::rawconfig();
# Breadcrumbs
my $brcrum = [{'href' => $url,
@@ -166,11 +165,6 @@ sub redirect_user {
$url=~s/ /\%20/g;
$r->print(<
-//
-
$msg
$end_page
ENDREDIR
@@ -208,6 +202,14 @@ sub handler {
my $r = shift;
+ # Check for critical messages and redirect if present.
+ my ($redirect,$url) = &Apache::loncommon::critical_redirect(300);
+ if ($redirect) {
+ &Apache::loncommon::content_type($r,'text/html');
+ $r->header_out(Location => $url);
+ return REDIRECT;
+ }
+
my $now=time;
my $then=$env{'user.login.time'};
my $refresh=$env{'user.refresh.time'};
@@ -221,7 +223,7 @@ sub handler {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
-# -------------------------------------------------- Check if setting hot list
+# -------------------------------------------------- Check if setting hot list
my $hotlist;
if ($env{'form.action'} eq 'verify_and_change_rolespref') {
$hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r);
@@ -253,7 +255,7 @@ sub handler {
my $envkey;
my %dcroles = ();
my $numdc = &check_fordc(\%dcroles,$update,$then);
- my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'};
+ my $loncaparev = $r->dir_config('lonVersion');
# ================================================================== Roles Init
if ($env{'form.selectrole'}) {
@@ -526,10 +528,10 @@ ENDENTERKEY
if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
my $msg;
- my ($furl,$ferr)=
- &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
+ my ($furl,$ferr)=
+ &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
unless ($ferr) {
- unless (($env{'form.switchrole'}) ||
+ unless (($env{'form.switchrole'}) ||
($env{"environment.internal.$cdom.$cnum.$role.adhoc"})) {
&Apache::lonnet::put('nohist_crslastlogin',
{$env{'user.name'}.':'.$env{'user.domain'}.
@@ -552,7 +554,7 @@ ENDENTERKEY
}
if (($env{'form.orgurl'}) &&
($env{'form.orgurl'}!~/^\/adm\/flip/) &&
- ($env{'form.orgurl'} ne '/adm/roles')) {
+ ($env{'form.orgurl'} ne '/adm/roles')) {
my $dest=$env{'form.orgurl'};
if ($env{'form.symb'}) {
if ($dest =~ /\?/) {
@@ -618,7 +620,7 @@ ENDENTERKEY
if ($env{'request.role.adv'}) {
$dest = &Apache::lonenc::unencrypted($dest);
if ($destsymb eq '') {
- ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/);
+ ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/);
$destsymb = &unescape($destsymb);
}
}
@@ -643,14 +645,14 @@ ENDENTERKEY
}
}
}
- unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) {
+ 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.'.$env{'request.course.id'}.'.description'}),
+ $env{'course.'.$cdom.'_'.$cnum.'.description'}),
$dest, $msg);
return OK;
}
@@ -685,7 +687,7 @@ ENDENTERKEY
} elsif (!&Apache::lonnet::allowed('bre',$furl)) {
$furl = &Apache::lonpageflip::first_accessible_resource();
}
-
+
$msg = &mt('Entering [_1] ...',
$env{'course.'.$cdom.'_'.$cnum.'.description'});
&redirect_user($r, &mt('Entering [_1]',
@@ -743,7 +745,7 @@ ENDENTERKEY
$crumbtext = 'Courses';
$pagetitle = 'My Courses';
$recent = &mt('Recent Courses');
- $standby = &mt('Course selected. Please stand by.');
+ $standby = &mt('Course selected. Please stand by.');
}
my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
@@ -791,7 +793,7 @@ function rolesView (caller) {
document.rolechoice.display.value = caller;
} else {
if ((caller == 'doupdate') || (caller == 'requestauthor') ||
- (caller == 'queued')) {
+ (caller == 'queued')) {
document.rolechoice.state.value = caller;
}
}
@@ -875,7 +877,7 @@ ENDHEADER
}
if ($hotlist) {
$showresult .= $hotlist;
- }
+ }
$showresult .= '';
$r->print($showresult);
} elsif ($env{'form.state'} eq 'queued') {
@@ -924,12 +926,7 @@ ENDHEADER
# No active roles
if ($countactive==0) {
- if ($inrole) {
- $r->print(''.&mt('Currently no additional roles, courses or communities').'
');
- } else {
- $r->print(''.&mt('Currently no active roles, courses or communities').'
');
- }
- &requestcourse_advice($r,$cattype);
+ &requestcourse_advice($r,$cattype,$inrole);
$r->print('');
if ($countfuture) {
$r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
@@ -1442,29 +1439,26 @@ sub findcourse_advice {
}
sub requestcourse_advice {
- my ($r,$cattype) = @_;
+ my ($r,$cattype,$inrole) = @_;
my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
- my (%can_request,%request_doms);
+ my (%can_request,%request_doms,$output);
&Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
if (keys(%request_doms) > 0) {
my ($types,$typename) = &Apache::loncommon::course_types();
if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
- $r->print(''.&mt('Request creation of a course or community').'
'.
- ''.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').'
');
my (@reqdoms,@reqtypes);
foreach my $type (sort(keys(%request_doms))) {
push(@reqtypes,$type);
if (ref($request_doms{$type}) eq 'ARRAY') {
my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
- $r->print(
+ $output .=
'- '
.&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
'',
'',
''.$domstr.'')
- .'
'
- );
+ .'';
foreach my $dom (@{$request_doms{$type}}) {
unless (grep(/^\Q$dom\E/,@reqdoms)) {
push(@reqdoms,$dom);
@@ -1487,10 +1481,25 @@ sub requestcourse_advice {
}
if (@reqdoms == 1 || @showtypes > 0) {
$requrl .= '&state=crstype&action=new';
- }
- $r->print('
'.&mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.','','').'
');
+ }
+ if ($output) {
+ $r->print(''.&mt('Request creation of a course or community').'
'.
+ ''.
+ &mt('You have rights to request the creation of courses and/or communities in the following domain(s):').
+ '
'.
+ &mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.',
+ '','').
+ '');
+ }
}
} elsif (!$env{'user.adv'}) {
+ if ($inrole) {
+ $r->print(''.&mt('Currently no additional roles, courses or communities').'
');
+ } else {
+ $r->print(''.&mt('Currently no active roles, courses or communities').'
');
+ }
&findcourse_advice($r,$cattype);
}
return;
@@ -1773,7 +1782,7 @@ sub check_release_required {
(($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
my $cdom = $env{'course.'.$tcourseid.'.domain'};
if ($cdom ne $env{'user.domain'}) {
- my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
+ my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
@@ -2236,7 +2245,7 @@ sub update_session_roles {
&curr_role_status($currstart,$currend,$refresh,$update);
my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/);
my ($role,$rest)=split(m{\./},$rolekey,2);
- $rest = '/'.$rest;
+ $rest = '/'.$rest;
if (&Apache::lonnet::delenv($envkey,undef,[$role])) {
if ($status_in_env eq 'active') {
if ($role eq 'gr') {
@@ -2436,15 +2445,15 @@ sub update_session_roles {
}
my $groupdesc;
unless (ref($curr_groups{$cdom.'_'.$cnum}) eq 'HASH') {
- %{$curr_groups{$cdom.'_'.$cnum}} =
+ %{$curr_groups{$cdom.'_'.$cnum}} =
&Apache::longroup::coursegroups($cdom,$cnum);
}
unless ((ref($groupdescs{$cdom.'_'.$cnum}) eq 'HASH') &&
($groupdescs{$cdom.'_'.$cnum}{$group})) {
- my %groupinfo =
+ my %groupinfo =
&Apache::longroup::get_group_settings($curr_groups{$cdom.'_'.$cnum}{$group});
- $groupdescs{$cdom.'_'.$cnum}{$group} =
+ $groupdescs{$cdom.'_'.$cnum}{$group} =
&unescape($groupinfo{'description'});
}
$groupdesc = $groupdescs{$cdom.'_'.$cnum}{$group};
@@ -2563,7 +2572,7 @@ sub update_session_roles {
my $cdom = $env{'course.'.$cid.'.domain'};
my $cnum = $env{'course.'.$cid.'.num'};
my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
- my %groupdesc;
+ my %groupdesc;
if (ref($groupchange{$crs}) eq 'HASH') {
$groupchgmsg .= ''.&mt('Course/Community: [_1]',''.$crsdesc.'');
foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
@@ -2781,7 +2790,7 @@ sub get_queued {
if (ref($history{'details'}) eq 'HASH') {
$description = $history{details}{'cdescr'};
}
- @{$reqcrs{$reqtime}} = ($description,$showtype);
+ @{$reqcrs{$reqtime}} = ($description,$showtype);
}
}
my @sortedtimes = sort {$a <=> $b} (keys(%reqcrs));