--- loncom/auth/lonroles.pm 2017/05/19 19:53:00 1.269.2.34
+++ loncom/auth/lonroles.pm 2024/09/07 01:49:32 1.269.2.39.2.10
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.269.2.34 2017/05/19 19:53:00 raeburn Exp $
+# $Id: lonroles.pm,v 1.269.2.39.2.10 2024/09/07 01:49:32 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -144,6 +144,93 @@ use GDBM_File;
use LONCAPA qw(:DEFAULT :match);
use HTML::Entities;
+sub start_loading_course {
+ my ($r,$title,$only_body) = @_;
+ &Apache::loncommon::content_type($r,'text/html');
+ &Apache::loncommon::no_cache($r);
+ $r->send_http_header;
+ if ($only_body) {
+ $r->print(&Apache::loncommon::start_page($title,undef,{'only_body' => 1,
+ 'add_progressbar' => 1}));
+ } else {
+ my $swinfo=&Apache::lonmenu::rawconfig();
+ # Breadcrumbs
+ my $brcrum = [{'href' => '',
+ 'text' => $title},];
+ my $start_page = &Apache::loncommon::start_page($title,undef,
+ {'bread_crumbs' => $brcrum,
+ 'bread_crumbs_nomenu' => 1,
+ 'links_disabled' => 1});
+ $r->print(< '.&mt('The following problems occurred:').
- ' $lt{'tfp'}
+ '.
+ &mt('Could not initialize [_1] at this time.',
+ $env{'course.'.$cdom.'_'.$cnum.'.description'}).
+ ' '.
+ &mt('Please try again.').' '.&mt('Entering [_1] ...',
+ $env{'course.'.$cdom.'_'.$cnum.'.description'}).
+ ' '
- .&mt('Could not initialize [_1] at this time.',
- $env{'course.'.$cdom.'_'.$cnum.'.description'})
- .' '.&mt('Please try again.').' '.$ferr.' '.
+ &mt('Could not initialize [_1] at this time.',
+ $env{'course.'.$cdom.'_'.$cnum.'.description'}).
+ ' '.&mt('Entering [_1] ...',
+ $env{'course.'.$cdom.'_'.$cnum.'.description'}).
+ ' '.&mt('Entering [_1] ...',
+ $env{'course.'.$cdom.'_'.$cnum.'.description'}).
+ ' '.&mt('Entering [_1] ...',
+ $env{'course.'.$cdom.'_'.$cnum.'.description'}).
+ ' '.&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).'
'.
- $error.
- '
'.&mt('Continue').''
+ my %lt = &Apache::lonlocal::texthash(
+ pdc => 'Problems during Course Initialization',
+ tfp => 'The following problems occurred:',
+ con => 'Continue',
);
- $r->print(&Apache::loncommon::end_page());
+ my $end_page = &Apache::loncommon::end_page();
+ $dest = &HTML::Entities::encode($dest,'"<>&');
+ $r->print(<
+$error
+
$lt{'con'}
+$end_page
+END
+ return;
}
sub handler {
@@ -209,7 +289,7 @@ sub handler {
my $r = shift;
# Check for critical messages and redirect if present.
- my ($redirect,$url) = &Apache::loncommon::critical_redirect(300);
+ my ($redirect,$url) = &Apache::loncommon::critical_redirect(300,'roles');
if ($redirect) {
&Apache::loncommon::content_type($r,'text/html');
$r->header_out(Location => $url);
@@ -227,6 +307,127 @@ sub handler {
$update = $then;
}
+ my ($norolelist,$blocked_by_ip,$blocked_type,$clientip);
+ $clientip = &Apache::lonnet::get_requestor_ip($r);
+ if (($env{'request.course.id'}) && ($env{'request.deeplink.login'})) {
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
+ my $deeplink_symb = &Apache::loncommon::deeplink_login_symb($cnum,$cdom);
+ if ($deeplink_symb) {
+ my ($menucoll,$deeplinkmenu,$menuref) = &Apache::loncommon::menucoll_in_effect();
+ if (ref($menuref) eq 'HASH') {
+ unless (($menuref->{'role'}) || ($env{'request.role.adv'})) {
+ foreach my $envkey (keys(%env)) {
+ next unless ($envkey =~ /^form\./);
+ if ($envkey =~ m{\./($match_domain)/($match_courseid)(?:/(\w+)|$)}) {
+ unless (($1 eq $cdom) && ($2 eq $cnum)) {
+ delete($env{$envkey});
+ }
+ }
+ }
+ if ($env{'form.selectrole'}) {
+ if ($env{'form.switchrole'} =~ m{\./($match_domain)/($match_courseid)(?:/(\w+)|$)}) {
+ unless (($1 eq $cdom) && ($2 eq $cnum)) {
+ delete($env{'form.selectrole'});
+ delete($env{'form.switchrole'});
+ }
+ } elsif ($env{'form.newrole'} =~ m{\./($match_domain)/($match_courseid)(?:/(\w+)|$)}) {
+ unless (($1 eq $cdom) && ($2 eq $cnum)) {
+ delete($env{'form.selectrole'});
+ delete($env{'form.newrole'});
+ }
+ }
+ }
+ $norolelist = 1;
+ }
+ }
+ }
+ }
+
+ if ($env{'form.selectrole'}) {
+ my ($role,$cdom,$cnum,$rest);
+ if ($env{'form.switchrole'} =~ m{^(co|cc|in|ta|ep|ad|st|cr).*?\./($match_domain)/($match_courseid)(/(\w+)|$)}) {
+ ($role,$cdom,$cnum,$rest) = ($1,$2,$3,$4);
+ } elsif ($env{'form.newrole'} =~ m{^(co|cc|in|ta|ep|ad|st|cr).*?\./($match_domain)/($match_courseid)(/(\w+)|$)}) {
+ ($role,$cdom,$cnum,$rest) = ($1,$2,$3,$4);
+ }
+ if ($cdom ne '') {
+ my ($has_evb,$check_ipaccess,$showrole);
+ $showrole = 1;
+ my $checkrole = "cm./$cdom/$cnum";
+ if ($rest ne '') {
+ $checkrole .= "/$rest";
+ }
+ if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
+ ($role ne 'st')) {
+ $has_evb = 1;
+ }
+ unless ($has_evb) {
+ my @machinedoms = &Apache::lonnet::current_machine_domains();
+ my $udom = $env{'user.domain'};
+ if ($udom eq $cdom) {
+ $check_ipaccess = 1;
+ } elsif (($udom ne '') && (grep(/^\Q$udom\E$/,@machinedoms))) {
+ $check_ipaccess = 1;
+ } else {
+ my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
+ my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
+ my $cprim = &Apache::lonnet::domain($cdom,'primary');
+ my $cintdom = &Apache::lonnet::internet_dom($cprim);
+ if (($cintdom ne '') && (ref($internet_names) eq 'ARRAY')) {
+ if (grep(/^\Q$cintdom\E$/,@{$internet_names})) {
+ $check_ipaccess = 1;
+ }
+ }
+ }
+ if ($check_ipaccess) {
+ my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$cdom);
+ unless (defined($cached)) {
+ my %domconfig =
+ &Apache::lonnet::get_dom('configuration',['ipaccess'],$cdom);
+ $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$cdom,$domconfig{'ipaccess'},1800);
+ }
+ if (ref($ipaccessref) eq 'HASH') {
+ foreach my $id (keys(%{$ipaccessref})) {
+ if (ref($ipaccessref->{$id}) eq 'HASH') {
+ my $range = $ipaccessref->{$id}->{'ip'};
+ if ($range) {
+ my $type = 'exclude';
+ if (&Apache::lonnet::ip_match($clientip,$range)) {
+ $type = 'include';
+ }
+ if (ref($ipaccessref->{$id}->{'courses'}) eq 'HASH') {
+ if ($ipaccessref->{$id}->{'courses'}{$cdom.'_'.$cnum}) {
+ if ($type eq 'include') {
+ $showrole = 1;
+ last;
+ } else {
+ $showrole = 0;
+ }
+ } else {
+ if ($type eq 'include') {
+ $showrole = 0;
+ } else {
+ $showrole = 1;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ unless ($showrole) {
+ $blocked_by_ip = 1;
+ $blocked_type = &Apache::loncommon::course_type($cdom.'_'.$cnum);
+ delete($env{'form.selectrole'});
+ delete($env{'form.newrole'});
+ }
+ }
+ }
+
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
# -------------------------------------------------- Check if setting hot list
@@ -307,6 +508,7 @@ sub handler {
"request.course.sec" => '',
"request.course.tied" => '',
"request.course.timechecked" => '',
+ "request.course.suppupdated" => '',
"request.role" => 'cm',
"request.role.adv" => $env{'user.adv'},
"request.role.domain" => $env{'user.domain'}});
@@ -495,6 +697,7 @@ sub handler {
my $end_page=&Apache::loncommon::end_page();
my $buttontext=&mt('Enter Course');
my $message=&mt('Successfully registered key');
+ my $ip = &Apache::lonnet::get_requestor_ip();
my $assignresult=
&Apache::lonnet::assign_access_key(
$env{'form.newkey'},
@@ -503,8 +706,8 @@ sub handler {
$env{'user.domain'},
$env{'user.name'},
&mt('Assigned from [_1] at [_2] for [_3]'
- ,$ENV{'REMOTE_ADDR'}
- ,&Apache::lonlocal::locallocaltime()
+ ,$ip
+ ,&Apache::lonlocal::locallocaltime($now)
,$trolecode)
);
unless ($assignresult eq 'ok') {
@@ -580,20 +783,87 @@ ENDENTERKEY
}
}
}
- my $msg;
+ my $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
+ $crstype = lc($crstype);
+ my ($msg,$critmsg_check,$title,$loadmsg,$only_body);
+ $critmsg_check = 1;
+ $title = &mt("Loading $crstype");
+ $loadmsg = &mt("Please be patient while your $crstype loads");
+ if (($env{'request.deeplink.login'}) && ($env{'request.linkprot'})) {
+ if ($env{'request.linkprot'} =~ /^\d+(c|d):\Q$env{'form.destinationurl'}\E$/) {
+ $title = &mt('Loading LON-CAPA session');
+ $loadmsg = &mt('Please be patient while LON-CAPA loads');
+ $only_body = 1;
+ $critmsg_check = 0;
+ }
+ }
+ my $preamble = '
'.
+ $loadmsg.
+ '".&mt('Sorry ...')."
\n".
- &mt('This action is currently not authorized.').''.
- &Apache::loncommon::end_page());
+ &mt('This action is currently not authorized.').'');
+ if ($error && $norolelist) {
+ $r->print(''.
+ &mt('As your session was launched from a web page external to LON-CAPA some course content may be unavailable, including the resource you were trying to access.').
+ '
'.
+ ''.
+ &mt('You may need to login to LON-CAPA directly, or re-launch from a different external system.').
+ '
');
+ }
+ $r->print(&Apache::loncommon::end_page());
return OK;
} else {
if ($updateresult || $reqauthor || $hotlist) {
@@ -967,6 +1341,16 @@ ENDHEADER
$r->print('');
$r->print('');
$r->print('');
+ if ($blocked_by_ip) {
+ my $blocked_role = 'student';
+ if ($blocked_type eq 'Community') {
+ $blocked_role = 'member';
+ }
+ $r->print(''.
+ &mt('The [_1] you selected is not available for access with a [_2] role from your current IP address: [_3].',
+ lc($blocked_type),$blocked_role,$clientip).
+ '
');
+ }
}
$r->rflush();
@@ -998,9 +1382,33 @@ ENDHEADER
}
}
+ if ($norolelist) {
+ if ($env{'request.role'}) {
+ my ($roletext,$role_text_end) = &display_curr_role($env{'request.role'});
+ if ($roletext) {
+ $r->print(&Apache::loncommon::start_data_table('LC_textsize_mobile').
+ &Apache::loncommon::start_data_table_row().
+ $roletext.
+ &Apache::loncommon::end_data_table_row());
+ if ($role_text_end) {
+ $r->print(&Apache::loncommon::continue_data_table_row().
+ $role_text_end.
+ &Apache::loncommon::end_data_table_row());
+ }
+ $r->print(&Apache::loncommon::end_data_table());
+ }
+ }
+ $r->print(&Apache::loncommon::end_page());
+ return OK;
+ }
+
# 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));
@@ -1237,6 +1645,7 @@ sub gather_roles {
$trole=Apache::lonnet::plaintext($role);
my $ttype;
my $twhere;
+ my $skipcal;
my ($tdom,$trest,$tsection)=
split(/\//,Apache::lonnet::declutter($where));
# First, Co-Authorship roles
@@ -1291,9 +1700,9 @@ sub gather_roles {
foreach my $rolename (sort(keys(%{$domdef{'adhocroles'}}))) {
if (ref($domdef{'adhocroles'}{$rolename}) eq 'HASH') {
$adhocdesc{$tdom}{$rolename} = $domdef{'adhocroles'}{$rolename}{'desc'};
- $desc = $adhocdesc{$tdom}{$rolename};
}
}
+ $desc = $adhocdesc{$tdom}{$rolename};
}
}
if ($desc ne '') {
@@ -1351,6 +1760,7 @@ sub gather_roles {
$env{'course.'.$tcourseid.'.description'}=$twhere;
$sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
$ttype = 'Unavailable';
+ $skipcal = 1;
}
}
if ($tsection) {
@@ -1369,7 +1779,8 @@ sub gather_roles {
($role_text,$role_text_end) =
&build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
- $tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning);
+ $tpend,$nochoose,$button,$switchserver,$reinit,
+ $switchwarning,$skipcal);
$roletext->{$envkey}=[$role_text,$role_text_end];
if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
$sortrole->{$sortkey}=$envkey;
@@ -1518,20 +1929,26 @@ sub print_rolerows {
}
sub findcourse_advice {
- my ($r,$cattype) = @_;
+ my ($r,$cattype,$elapsed) = @_;
my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
- $r->print(&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).'
+ $r->print('
');
+
'.&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.').'