--- loncom/auth/lonroles.pm 2014/05/05 11:44:18 1.269.2.19
+++ loncom/auth/lonroles.pm 2016/08/13 21:17:38 1.269.2.26
@@ -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.269.2.26 2016/08/13 21:17:38 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;
@@ -208,6 +208,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'};
@@ -253,7 +261,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'}) {
@@ -284,14 +292,15 @@ sub handler {
&Apache::lonnet::put('email_status',\%temp);
&Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
}
- &Apache::lonnet::appenv({"request.course.id" => '',
- "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'}});
+ &Apache::lonnet::appenv({"request.course.id" => '',
+ "request.course.fn" => '',
+ "request.course.uri" => '',
+ "request.course.sec" => '',
+ "request.course.tied" => '',
+ "request.course.timechecked" => '',
+ "request.role" => 'cm',
+ "request.role.adv" => $env{'user.adv'},
+ "request.role.domain" => $env{'user.domain'}});
# Check if user is a DC trying to enter a course or author space and needs privs to be created
if ($numdc > 0) {
foreach my $envkey (keys(%env)) {
@@ -380,30 +389,13 @@ sub handler {
my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
my ($switchserver,$switchwarning) =
- &check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,$curr_reqd_hash{'internal.releaserequired'});
+ &Apache::loncommon::check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,
+ $curr_reqd_hash{'internal.releaserequired'});
if ($switchwarning ne '' || $switchserver ne '') {
&Apache::loncommon::content_type($r,'text/html');
&Apache::loncommon::no_cache($r);
$r->send_http_header;
- my $end_page=&Apache::loncommon::end_page();
- $r->print(&Apache::loncommon::start_page('Selected course unavailable on this server').
- '
');
- if ($switchwarning) {
- $r->print($switchwarning.'
');
- if (&Apache::loncommon::show_course()) {
- $r->print(&mt('Display courses'));
- } else {
- $r->print(&mt('Display roles'));
- }
- $r->print('');
- } elsif ($switchserver) {
- $r->print(&mt('This course requires a newer version of LON-CAPA than is installed on this server.').
- '
'.
- ''.
- &mt('Switch Server').
- '');
- }
- $r->print('
'.&Apache::loncommon::end_page());
+ $r->print(&Apache::loncommon::check_release_result($switchwarning,$switchserver));
return OK;
}
}
@@ -650,7 +642,7 @@ ENDENTERKEY
}
}
&redirect_user($r, &mt('Entering [_1]',
- $env{'course.'.$env{'request.course.id'}.'.description'}),
+ $env{'course.'.$cdom.'_'.$cnum.'.description'}),
$dest, $msg);
return OK;
}
@@ -671,6 +663,7 @@ ENDENTERKEY
}
}
# Are we allowed to look at the first resource?
+ my $access;
if ($furl =~ m{^(/adm/wrapper|)/ext/}) {
# If it's an external resource,
# strip off the symb argument and possible query
@@ -678,14 +671,16 @@ ENDENTERKEY
# Unencode $symb
$symb = &unescape($symb);
# Then check for permission
- if (!&Apache::lonnet::allowed('bre',$exturl,$symb)) {
- $furl = &Apache::lonpageflip::first_accessible_resource();
- }
+ $access = &Apache::lonnet::allowed('bre',$exturl,$symb);
# For other resources just check for permission
- } elsif (!&Apache::lonnet::allowed('bre',$furl)) {
+ } else {
+ $access = &Apache::lonnet::allowed('bre',$furl);
+ }
+ if (!$access) {
$furl = &Apache::lonpageflip::first_accessible_resource();
+ } elsif ($access eq 'B') {
+ $furl = '/adm/navmaps?showOnlyHomework=1';
}
-
$msg = &mt('Entering [_1] ...',
$env{'course.'.$cdom.'_'.$cnum.'.description'});
&redirect_user($r, &mt('Entering [_1]',
@@ -751,14 +746,20 @@ ENDENTERKEY
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 %domdefs=&Apache::lonnet::get_domain_defaults($env{'user.domain'});
my $cattype = 'std';
if ($domdefs{'catauth'}) {
$cattype = $domdefs{'catauth'};
}
my $funcs = &get_roles_functions($showcount,$cattype);
- $standby=~s/\n/\\n/g;
+ my $crumbsright;
+ if ($env{'browser.mobile'}) {
+ $crumbsright = $funcs;
+ undef($funcs);
+ }
+ my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum,
+ bread_crumbs_component=>$crumbsright});
+ &js_escape(\$standby);
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(<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));
@@ -1070,11 +1066,7 @@ ENDHEADER
my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
$r->print(''
.&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
- .'
'
- .''.&mt('Logout').' '
- .''
- .&mt('Course/Community Catalog')
- .'
');
+ .'');
}
$r->print(&Apache::loncommon::end_page());
return OK;
@@ -1218,7 +1210,7 @@ sub gather_roles {
my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
if ($required ne '') {
($switchserver,$switchwarning) =
- &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
+ &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
if ($switchserver || $switchwarning) {
$button = 0;
}
@@ -1241,7 +1233,7 @@ sub gather_roles {
my $required = $newhash{'internal.releaserequired'};
if ($required ne '') {
($switchserver,$switchwarning) =
- &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
+ &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
if ($switchserver || $switchwarning) {
$button = 0;
}
@@ -1342,7 +1334,7 @@ sub roletable_headers {
my $doheaders;
if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
$r->print('
'
- .&Apache::loncommon::start_data_table()
+ .&Apache::loncommon::start_data_table('LC_textsize_mobile')
.&Apache::loncommon::start_data_table_header_row()
);
if (!$nochoose) { $r->print(' | '); }
@@ -1442,29 +1434,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 +1476,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;
@@ -1645,7 +1649,7 @@ sub check_fordc {
my ($dcroles,$update,$then) = @_;
my $numdc = 0;
if ($env{'user.adv'}) {
- foreach my $envkey (sort keys %env) {
+ foreach my $envkey (sort(keys(%env))) {
if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
my $dcdom = $1;
my $livedc = 1;
@@ -1754,58 +1758,6 @@ sub check_forcc {
return $is_cc;
}
-sub check_release_required {
- my ($loncaparev,$tcourseid,$trolecode,$required) = @_;
- my ($switchserver,$warning);
- if ($required ne '') {
- my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
- my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
- if ($reqdmajor ne '' && $reqdminor ne '') {
- my $otherserver;
- if (($major eq '' && $minor eq '') ||
- (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
- my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
- my $switchlcrev =
- &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
- $userdomserver);
- my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
- if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
- (($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 $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
- my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
- my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
- my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
- my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
- my $canhost =
- &Apache::lonnet::can_host_session($env{'user.domain'},
- $coursedomserver,
- $remoterev,
- $udomdefaults{'remotesessions'},
- $defdomdefaults{'hostedsessions'});
-
- if ($canhost) {
- $otherserver = $coursedomserver;
- } else {
- $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$tcourseid.'.internal.releaserequired'}).'
'. &mt("No suitable server could be found amongst servers in either your own domain or in the course's domain.");
- }
- } else {
- $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$tcourseid.'.internal.releaserequired'}).'
'.&mt("No suitable server could be found amongst servers in your own domain (which is also the course's domain).");
- }
- } else {
- $otherserver = $userdomserver;
- }
- }
- if ($otherserver ne '') {
- $switchserver = 'otherserver='.$otherserver.'&role='.$trolecode;
- }
- }
- }
- return ($switchserver,$warning);
-}
-
sub courselink {
my ($dcdom,$rowtype) = @_;
my $courseform=&Apache::loncommon::selectcourse_link
@@ -1820,10 +1772,11 @@ sub courselink {
}
sub coursepick_jscript {
- my %lt = &Apache::lonlocal::texthash(
+ my %js_lt = &Apache::lonlocal::texthash(
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.',
);
+ &js_escape(\%js_lt);
my $verify_script = <<"END";