--- loncom/auth/lonroles.pm 2017/05/19 19:20:42 1.330
+++ loncom/auth/lonroles.pm 2021/04/22 20:14:22 1.348
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.330 2017/05/19 19:20:42 raeburn Exp $
+# $Id: lonroles.pm,v 1.348 2021/04/22 20:14:22 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -145,6 +145,51 @@ use GDBM_File;
use LONCAPA qw(:DEFAULT :match);
use HTML::Entities;
+my $registered_cleanup;
+my $rosterupdates;
+
+sub start_loading_course {
+ my ($r,$title) = @_;
+ &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' => '',
+ 'text' => $title},];
+ my $start_page = &Apache::loncommon::start_page($title,undef,
+ {'bread_crumbs' => $brcrum,});
+ $r->print(< $msg
'.&mt('The following problems occurred:').
- '
'.
- $error.
- '
$lt{'tfp'}
+
+$error
+
'. + &mt('Could not initialize [_1] at this time.', + $env{'course.'.$cdom.'_'.$cnum.'.description'}). + '
'. + ''. + &mt('Please try again.').'
'. + &Apache::loncommon::end_page()); + } + } else { + if (($env{'request.lti.login'}) && + ($env{'request.lti.rosterid'} || $env{'request.lti.passbackid'})) { + &process_lti($r,$cdom,$cnum); + } + $msg = ''.&mt('Entering [_1] ...', + $env{'course.'.$cdom.'_'.$cnum.'.description'}). + '
'; + &finish_loading_course($r,$msg,$dest); + } } + $r->rflush(); return OK; } else { if (!$env{'request.course.id'}) { &Apache::lonnet::appenv( {"request.course.id" => $cdom.'_'.$cnum}); - $furl='/adm/roles?tryagain=1'; - $msg='' - .&mt('Could not initialize [_1] at this time.', - $env{'course.'.$cdom.'_'.$cnum.'.description'}) - .'
' - .''.&mt('Please try again.').'
' - .''.$ferr.'
'; } if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; } &Apache::lonnet::appenv({'request.role.adv'=>$tadv}); - - if (($ferr) && ($tadv)) { - &error_page($r,$ferr,$furl); + if ($ferr) { + if ($tadv) { + &error_page($r,$ferr,$furl); + } else { + $r->print(''. + &mt('Could not initialize [_1] at this time.', + $env{'course.'.$cdom.'_'.$cnum.'.description'}). + '
'. + ''. + &Apache::loncommon::end_page()); + } } else { + if (($env{'request.lti.login'}) && + ($env{'request.lti.rosterid'} || $env{'request.lti.passbackid'})) { + &process_lti($r,$cdom,$cnum); + } # Check to see if the user is a CC entering a course # for the first time if ((($role eq 'cc') || ($role eq 'co')) @@ -656,9 +808,11 @@ ENDENTERKEY my ($score,$incomplete) = &Apache::lonplacementtest::check_completion(undef,undef,1); if (($incomplete) && ($incomplete < 100)) { - &redirect_user($r, &mt('Entering [_1]', - $env{'course.'.$cdom.'_'.$cnum.'.description'}), - '/adm/placement', $msg); + $msg = ''.&mt('Entering [_1] ...', + $env{'course.'.$cdom.'_'.$cnum.'.description'}). + '
'; + &finish_loading_course($r,$msg,'/adm/placement'); + $r->rflush(); return OK; } } @@ -677,9 +831,11 @@ ENDENTERKEY if (($dest =~ m{^\Q/public/$cdom/$cnum/syllabus\E.*(\?|\&)usehttp=1}) || ($dest =~ m{^\Q/adm/wrapper/ext/\E(?!https:)})) { if ($ENV{'SERVER_PORT'} == 443) { - my $hostname = $r->hostname(); - if ($hostname ne '') { - $dest = 'http://'.$hostname.$dest; + unless (&Apache::lonnet::uses_sts()) { + my $hostname = $r->hostname(); + if ($hostname ne '') { + $dest = 'http://'.$hostname.$dest; + } } } } @@ -718,9 +874,13 @@ ENDENTERKEY $dest .= (($dest =~/\?/)? '&':'?').'symb='.$esc_symb; } } - &redirect_user($r, &mt('Entering [_1]', - $env{'course.'.$cdom.'_'.$cnum.'.description'}), - $dest, $msg); + unless ($env{'request.lti.login'}) { + $msg = ''.&mt('Entering [_1] ...', + $env{'course.'.$cdom.'_'.$cnum.'.description'}). + '
'; + } + &finish_loading_course($r,$msg,$dest); + $r->rflush(); return OK; } if (&Apache::lonnet::allowed('whn', @@ -731,10 +891,11 @@ ENDENTERKEY ) { my $startpage = &courseloadpage($env{'request.course.id'}); unless ($startpage eq 'firstres') { - $msg = &mt('Entering [_1] ...', - $env{'course.'.$env{'request.course.id'}.'.description'}); - &redirect_user($r, &mt('New in course'), - '/adm/whatsnew?refpage=start', $msg); + $msg = ''.&mt('Entering [_1] ...', + $env{'course.'.$cdom.'_'.$cnum.'.description'}). + '
'; + &finish_loading_course($r,$msg,'/adm/whatsnew?refpage=start'); + $r->rflush(); return OK; } } @@ -758,12 +919,17 @@ ENDENTERKEY } elsif ($access eq 'B') { $furl = '/adm/navmaps?showOnlyHomework=1'; } - $msg = &mt('Entering [_1] ...', - $env{'course.'.$cdom.'_'.$cnum.'.description'}); - &redirect_user($r, &mt('Entering [_1]', - $env{'course.'.$cdom.'_'.$cnum.'.description'}), - $furl, $msg); + if ($env{'request.lti.login'}) { + undef($msg); + &finish_loading_course($r,$msg,$furl); + } else { + $msg = ''.&mt('Entering [_1] ...', + $env{'course.'.$cdom.'_'.$cnum.'.description'}). + '
'; + &finish_loading_course($r,$msg,$furl); + } } + $r->rflush(); return OK; } } @@ -827,7 +993,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}]; @@ -1054,7 +1220,11 @@ ENDHEADER # No active roles if ($countactive==0) { - &requestcourse_advice($r,$cattype,$inrole); + my $elapsed = 0; + if ($now && $update) { + $elapsed = $now - $update; + } + &requestcourse_advice($r,$cattype,$inrole,$elapsed); $r->print(''); if ($countfuture) { $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture)); @@ -1240,6 +1410,7 @@ sub gather_roles { my $advanced = $env{'user.adv'}; my $tryagain = $env{'form.tryagain'}; my @ids = &Apache::lonnet::current_machine_ids(); + my (%willtrust,%trustchecked); if (ref($roles_in_env) eq 'HASH') { my %adhocdesc; foreach my $envkey (sort(keys(%{$roles_in_env}))) { @@ -1308,10 +1479,23 @@ sub gather_roles { if (($role eq 'ca') || ($role eq 'aa')) { my $home = &Apache::lonnet::homeserver($trest,$tdom); my $allowed=0; + my $prohibited; foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } if (!$allowed) { $button=0; - $switchserver='otherserver='.$home.'&role='.$trolecode; + unless ($trustchecked{$tdom}) { + if ((&Apache::lonnet::will_trust('othcoau',$env{'user.domain'},$tdom)) && + (&Apache::lonnet::will_trust('coaurem',$tdom,$env{'user.domain'}))) { + $willtrust{$tdom} = 1; + $trustchecked{$tdom} = 1; + } + } + if ($willtrust{$tdom}) { + $switchserver='otherserver='.$home.'&role='.$trolecode; + } else { + $prohibited = 1; + $tremark .= &mt('Session switch required but prohibited.'); + } } #next if ($home eq 'no_host'); $home = &Apache::lonnet::hostname($home); @@ -1320,7 +1504,9 @@ sub gather_roles { ': '.$tdom.''.&mt('If you were expecting to see an active role listed for a particular course in the [_1] domain, it may be missing for one of the following reasons:',$domdesc).'
'.&mt('If you were expecting to see an active role listed for a particular course, that course may not have been created yet.').'
'); + if ($elapsed > 600) { + $r->print(''.&mt('You may also have been assigned to a course in the time since you last logged-in, or checked for changes').
+ '
'.
+ &mt('If that is the case you can use the "Check for changes" link in the gray Functions bar to update the list of your available course roles.').'