--- loncom/auth/lonroles.pm 2024/12/29 02:02:29 1.269.2.42
+++ loncom/auth/lonroles.pm 2017/02/20 18:29:28 1.326
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.269.2.42 2024/12/29 02:02:29 raeburn Exp $
+# $Id: lonroles.pm,v 1.326 2017/02/20 18:29:28 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -140,65 +140,11 @@ use Apache::lonnavdisplay();
use Apache::loncoursequeueadmin;
use Apache::longroup;
use Apache::lonrss;
+use Apache::lonplacementtest;
use GDBM_File;
use LONCAPA qw(:DEFAULT :match);
use HTML::Entities;
-
-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,
- 'bread_crumbs_nomenu' => 1,
- 'links_disabled' => 1});
- $r->print(< $msg $lt{'tfp'}
- '.&mt('The following problems occurred:').
+ ' '.
- &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).'
+ $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).'
-$error
-
$lt{'con'}
-$end_page
-END
- return;
+ $r->print(
+ ''.
+ '
'.
+ $error.
+ '
'.&mt('Continue').''
+ );
+ $r->print(&Apache::loncommon::end_page());
}
sub handler {
@@ -275,95 +222,9 @@ sub handler {
$update = $then;
}
- my ($blocked_by_ip,$blocked_type,$clientip);
- $clientip = &Apache::lonnet::get_requestor_ip($r);
-
- 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
+# -------------------------------------------------- Check if setting hot list
my $hotlist;
if ($env{'form.action'} eq 'verify_and_change_rolespref') {
$hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r);
@@ -394,8 +255,8 @@ sub handler {
my $envkey;
my %dcroles = ();
- my %helpdeskroles = ();
- my ($numdc,$numhelpdesk,$numadhoc) =
+ my %helpdeskroles = ();
+ my ($numdc,$numhelpdesk,$numadhoc) =
&check_for_adhoc(\%dcroles,\%helpdeskroles,$update,$then);
my $loncaparev = $r->dir_config('lonVersion');
@@ -453,7 +314,7 @@ sub handler {
if ($custom_adhoc) {
my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum,1);
if (ref($possroles) eq 'ARRAY') {
- if (grep(/^\Q$rolename\E$/,@{$possroles})) {
+ if (grep(/^\Q$rolename\E$/,@{$possroles})) {
if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now,
"cr/$cdom/$cdom".'-domainconfig/'.$rolename,undef,$sec)) {
&Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig/'."$rolename.adhoc" => time});
@@ -465,8 +326,8 @@ sub handler {
# Check if user is a DC trying to enter a course or author space and needs privs to be created
# Check if user is a DH or DA trying to enter a course and needs privs to be created
foreach my $envkey (keys(%env)) {
- if ($numdc) {
# Is this an ad-hoc Coordinator role?
+ if ($numdc) {
if (my ($ccrole,$domain,$coursenum) =
($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
if ($dcroles{$domain}) {
@@ -557,10 +418,9 @@ sub handler {
}
last;
}
- }
+ }
}
}
-
foreach $envkey (keys(%env)) {
next if ($envkey!~/^user\.role\./);
my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
@@ -629,7 +489,6 @@ 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'},
@@ -638,8 +497,8 @@ sub handler {
$env{'user.domain'},
$env{'user.name'},
&mt('Assigned from [_1] at [_2] for [_3]'
- ,$ip
- ,&Apache::lonlocal::locallocaltime($now)
+ ,$ENV{'REMOTE_ADDR'}
+ ,&Apache::lonlocal::locallocaltime()
,$trolecode)
);
unless ($assignresult eq 'ok') {
@@ -715,62 +574,16 @@ ENDENTERKEY
}
}
}
- my $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
- $crstype = lc($crstype);
- my $preamble = '
'.
- &mt("Please be patient while your $crstype loads").
- '
'.&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.').'
';
@@ -1120,7 +906,7 @@ function rolesView (caller) {
document.rolechoice.display.value = caller;
} else {
if ((caller == 'doupdate') || (caller == 'requestauthor') ||
- (caller == 'queued')) {
+ (caller == 'queued')) {
document.rolechoice.state.value = caller;
}
}
@@ -1204,7 +990,7 @@ ENDHEADER
}
if ($hotlist) {
$showresult .= $hotlist;
- }
+ }
$showresult .= '';
$r->print($showresult);
} elsif ($env{'form.state'} eq 'queued') {
@@ -1220,16 +1006,6 @@ 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();
@@ -1239,7 +1015,21 @@ ENDHEADER
\%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev);
$refresh = $now;
&Apache::lonnet::appenv({'user.refresh.time' => $refresh});
- if ((($cattype eq 'std') || ($cattype eq 'domonly')) && (!$env{'user.adv'})) {
+ if ($countactive == 1) {
+ if ($env{'request.course.id'}) {
+ if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') {
+ $placementonly = 1;
+ }
+ } elsif ($possiblerole) {
+ if ($possiblerole =~ m{^st\./($match_domain)/($match_courseid)(?:/|$)}) {
+ if ($env{'course.'.$1.'_'.$2.'.type'} eq 'Placement') {
+ $placementonly = 1;
+ }
+ }
+ }
+ }
+ if ((($cattype eq 'std') || ($cattype eq 'domonly')) && (!$env{'user.adv'}) &&
+ (!$placementonly)) {
if ($countactive > 0) {
my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
@@ -1263,11 +1053,7 @@ ENDHEADER
# No active roles
if ($countactive==0) {
- my $elapsed = 0;
- if ($now && $update) {
- $elapsed = $now - $update;
- }
- &requestcourse_advice($r,$cattype,$inrole,$elapsed);
+ &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));
@@ -1296,15 +1082,23 @@ ENDHEADER
}
$r->print(&Apache::loncommon::end_page());
return OK;
+ } elsif (($placementonly) && ($env{'request.role'} eq 'cm')) {
+ $r->print(''.&mt('Please stand by.').'
+
+ ');
+ $r->rflush();
+ $r->print('');
+ $r->print(&Apache::loncommon::end_page());
+ return OK;
}
# ----------------------------------------------------------------------- Table
if (($numdc > 0) || (($numhelpdesk > 0) && ($numadhoc > 0))) {
- $r->print(&coursepick_jscript().
- &Apache::loncommon::coursebrowser_javascript());
- }
- if ($numdc > 0) {
- $r->print(&Apache::loncommon::authorbrowser_javascript());
+ $r->print(&coursepick_jscript());
+ $r->print(&Apache::loncommon::coursebrowser_javascript().
+ &Apache::loncommon::authorbrowser_javascript());
}
unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
@@ -1559,9 +1353,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 '') {
@@ -1622,6 +1416,9 @@ sub gather_roles {
$skipcal = 1;
}
}
+ if ($ttype eq 'Placement') {
+ $ttype = 'Placement Test';
+ }
if ($tsection) {
$twhere.='
'.&mt('Section').': '.$tsection;
}
@@ -1737,7 +1534,7 @@ sub roletable_headers {
}
sub roletypes {
- my @types = ('Domain','Authoring Space','Course','Community','Unavailable','System');
+ my @types = ('Domain','Authoring Space','Course','Placement Test','Community','Unavailable','System');
return @types;
}
@@ -1788,26 +1585,20 @@ sub print_rolerows {
}
sub findcourse_advice {
- my ($r,$cattype,$elapsed) = @_;
+ my ($r,$cattype) = @_;
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, 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.').'