--- loncom/auth/lonroles.pm 2014/03/25 10:18:04 1.256.2.7
+++ loncom/auth/lonroles.pm 2016/10/19 13:12:58 1.317
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.256.2.7 2014/03/25 10:18:04 raeburn Exp $
+# $Id: lonroles.pm,v 1.317 2016/10/19 13:12:58 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -57,8 +57,7 @@ course they should act on, etc. Both in
handler determines via C's C<&allowed> function that a certain
action is not allowed, C is used as error handler. This
allows the user to select another role which may have permission to do
-what they were trying to do. C can also be accessed via the
-B button in the Remote Control.
+what they were trying to do.
=begin latex
@@ -129,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;
@@ -139,25 +138,20 @@ use Apache::lonlocal;
use Apache::lonpageflip();
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 redirect_user {
- my ($r,$title,$url,$msg,$launch_nav) = @_;
+ my ($r,$title,$url,$msg) = @_;
$msg = $title if (! defined($msg));
&Apache::loncommon::content_type($r,'text/html');
&Apache::loncommon::no_cache($r);
$r->send_http_header;
- my $swinfo=&Apache::lonmenu::rawconfig();
- my $navwindow;
- if ($launch_nav eq 'on') {
- $navwindow.=&Apache::lonnavdisplay::launch_win('now',undef,undef,
- ($url =~ m-^/adm/whatsnew-));
- } else {
- $navwindow.=&Apache::lonnavmaps::close();
- }
# Breadcrumbs
my $brcrum = [{'href' => $url,
@@ -172,12 +166,6 @@ sub redirect_user {
$url=~s/ /\%20/g;
$r->print(<
-//
-
-$navwindow
$msg
$end_page
ENDREDIR
@@ -215,17 +203,61 @@ 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'};
+ my $update=$env{'user.update.time'};
if (!$refresh) {
$refresh = $then;
}
+ if (!$update) {
+ $update = $then;
+ }
+
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
+
+# -------------------------------------------------- Check if setting hot list
+ my $hotlist;
+ if ($env{'form.action'} eq 'verify_and_change_rolespref') {
+ $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r);
+ }
+
+# -------------------------------------------------------- Check for new roles
+ my $updateresult;
+ if ($env{'form.state'} eq 'doupdate') {
+ my $show_course=&Apache::loncommon::show_course();
+ my $checkingtxt;
+ if ($show_course) {
+ $checkingtxt = &mt('Checking for new courses ...');
+ } else {
+ $checkingtxt = &mt('Checking for new roles ...');
+ }
+ $updateresult = $checkingtxt;
+ $updateresult .= &update_session_roles();
+ &Apache::lonnet::appenv({'user.update.time' => $now});
+ $update = $now;
+ &Apache::loncoursequeueadmin::reqauthor_check();
+ }
+
+# -------------------------------------------------- Check for author requests
+ my $reqauthor;
+ if ($env{'form.state'} eq 'requestauthor') {
+ $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update);
+ }
+
my $envkey;
my %dcroles = ();
- my $numdc = &check_fordc(\%dcroles,$then);
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
- my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'};
+ my %dhroles = ();
+ my ($numdc,$numdh,$numadhoc) = &check_for_adhoc(\%dcroles,\%dhroles,$update,$then);
+ my $loncaparev = $r->dir_config('lonVersion');
# ================================================================== Roles Init
if ($env{'form.selectrole'}) {
@@ -233,8 +265,15 @@ sub handler {
my $locknum=&Apache::lonnet::get_locks();
if ($locknum) { return 409; }
+ my $custom_adhoc;
if ($env{'form.newrole'}) {
$env{'form.'.$env{'form.newrole'}}=1;
+# Check if this is a Domain Helpdesk role trying to enter a course
+ if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/\w+\./\1/$match_courseid$}) {
+ if ($dhroles{$1}) {
+ $custom_adhoc = 1;
+ }
+ }
}
if ($env{'request.course.id'}) {
# Check if user is CC trying to select a course role
@@ -243,35 +282,57 @@ sub handler {
if (defined($env{'user.role.'.$env{'form.switchrole'}})) {
my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
if (!$end || $end > $now) {
- if (!$start || $start < $refresh) {
+ if (!$start || $start < $update) {
$switch_is_active = 1;
}
}
}
unless ($switch_is_active) {
- &adhoc_course_role($refresh,$then);
+ &adhoc_course_role($refresh,$update,$then);
}
}
my %temp=('logout_'.$env{'request.course.id'} => time);
&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.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 Domain Helpdesk role trying to enter a course needs privs to be created
+ if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)$}) {
+ my $cdom = $1;
+ my $rolename = $2;
+ my $cnum = $3;
+ if ($custom_adhoc) {
+ my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
+ 'adhocroles.'.$cdom);
+ if (keys(%adhocroles)) {
+ my @adhoc = split(',',$adhocroles{'adhocroles.'.$cdom});
+ if (grep(/^\Q$rolename\E$/,@adhoc)) {
+ if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now,
+ "cr/$cdom/$cdom".'-domainconfig/'.$rolename)) {
+ &Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig/'."$rolename.adhoc" => time});
+ }
+ }
+ }
+ }
+ } elsif ($numdc > 0) {
# 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) {
+ foreach my $envkey (keys(%env)) {
# Is this an ad-hoc Coordinator role?
if (my ($ccrole,$domain,$coursenum) =
($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
if ($dcroles{$domain}) {
- &Apache::lonnet::check_adhoc_privs($domain,$coursenum,
- $then,$refresh,$now,$ccrole);
+ if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,
+ $update,$refresh,$now,$ccrole)) {
+ &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time});
+ }
}
last;
}
@@ -286,6 +347,7 @@ sub handler {
my $trolecode = 'au./'.$domain.'/';
my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
$r->internal_redirect($switchserver);
+ return OK;
}
last;
}
@@ -297,6 +359,7 @@ sub handler {
my $trolecode = 'ca./'.$domain.'/'.$user;
my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
$r->internal_redirect($switchserver);
+ return OK;
}
last;
}
@@ -311,13 +374,14 @@ sub handler {
if ($dcroles{$domain}) {
my ($server_status,$home) = &check_author_homeserver($user,$domain);
if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
- &Apache::lonnet::check_adhoc_privs($domain,$user,$then,
+ &Apache::lonnet::check_adhoc_privs($domain,$user,$update,
$refresh,$now,'ca');
if ($server_status eq 'switchserver') {
my $trolecode = 'ca./'.$domain.'/'.$user;
my $switchserver = '/adm/switchserver?'
.'otherserver='.$home.'&role='.$trolecode;
$r->internal_redirect($switchserver);
+ return OK;
}
} else {
delete($env{$envkey});
@@ -330,10 +394,10 @@ sub handler {
}
}
- foreach $envkey (keys %env) {
+ foreach $envkey (keys(%env)) {
next if ($envkey!~/^user\.role\./);
my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
- &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
+ &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
\$trolecode,\$tstatus,\$tstart,\$tend);
if ($env{'form.'.$trolecode}) {
if ($tstatus eq 'is') {
@@ -346,30 +410,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').
- '
');
}
$r->print(&Apache::loncommon::end_page());
return OK;
}
+sub roles_from_env {
+ my ($roleshash,$update) = @_;
+ my $count = 0;
+ if (ref($roleshash) eq 'HASH') {
+ foreach my $envkey (keys(%env)) {
+ if ($envkey =~ m{^user\.role\.(\w+)[./]}) {
+ next if ($1 eq 'gr');
+ $roleshash->{$envkey} = $env{$envkey};
+ my ($start,$end) = split(/\./,$env{$envkey});
+ unless ($end && $end<$update) {
+ $count ++;
+ }
+ }
+ }
+ }
+ return $count;
+}
+
sub gather_roles {
- my ($then,$refresh,$now,$reinit,$nochoose,$roletext,$sortrole,$roleclass,$futureroles,$timezones,$loncaparev) = @_;
+ my ($update,$refresh,$now,$reinit,$nochoose,$roles_in_env,$roletext,$sortrole,$roleclass,$futureroles,
+ $timezones,$loncaparev) = @_;
my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
my $advanced = $env{'user.adv'};
my $tryagain = $env{'form.tryagain'};
my @ids = &Apache::lonnet::current_machine_ids();
- foreach my $envkey (sort(keys(%env))) {
- my $button = 1;
- my $switchserver='';
- my $switchwarning;
- my ($role_text,$role_text_end,$sortkey);
- if ($envkey=~/^user\.role\./) {
- my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);
- &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
+ if (ref($roles_in_env) eq 'HASH') {
+ foreach my $envkey (sort(keys(%{$roles_in_env}))) {
+ my $button = 1;
+ my $switchserver='';
+ my $switchwarning;
+ my ($role_text,$role_text_end,$sortkey,$role,$where,$trolecode,$tstart,
+ $tend,$tremark,$tstatus,$tpstart,$tpend);
+ &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
\$trolecode,\$tstatus,\$tstart,\$tend);
next if (!defined($role) || $role eq '' || $role =~ /^gr/);
$tremark='';
@@ -966,7 +1208,7 @@ sub gather_roles {
if (($tstatus eq 'is')
|| ($tstatus eq 'selected')
|| ($tstatus eq 'future')
- || ($env{'form.showall'})) {
+ || ($env{'form.display'} eq 'showall')) {
my $timezone = &role_timezone($where,$timezones);
if ($tstart) {
$tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
@@ -999,11 +1241,12 @@ sub gather_roles {
if ($role =~ /^cr\//) {
my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
if ($tremark) { $tremark.=' '; }
- $tremark.=&mt('Customrole defined by [_1].',$rauthor.':'.$rdomain);
+ $tremark.=&mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
}
$trole=Apache::lonnet::plaintext($role);
my $ttype;
my $twhere;
+ my $skipcal;
my ($tdom,$trest,$tsection)=
split(/\//,Apache::lonnet::declutter($where));
# First, Co-Authorship roles
@@ -1017,7 +1260,7 @@ sub gather_roles {
}
#next if ($home eq 'no_host');
$home = &Apache::lonnet::hostname($home);
- $ttype='Construction Space';
+ $ttype='Authoring Space';
$twhere=&mt('User').': '.$trest.' '.&mt('Domain').
': '.$tdom.' '.
' '.&mt('Server').': '.$home;
@@ -1036,7 +1279,7 @@ sub gather_roles {
}
#next if ($home eq 'no_host');
$home = &Apache::lonnet::hostname($home);
- $ttype='Construction Space';
+ $ttype='Authoring Space';
$twhere=&mt('Domain').': '.$tdom.' '.&mt('Server').
': '.$home;
$env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
@@ -1059,7 +1302,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;
}
@@ -1082,7 +1325,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;
}
@@ -1093,8 +1336,12 @@ sub gather_roles {
$env{'course.'.$tcourseid.'.description'}=$twhere;
$sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
$ttype = 'Unavailable';
+ $skipcal = 1;
}
}
+ if ($ttype eq 'Placement') {
+ $ttype = 'Placement Test';
+ }
if ($tsection) {
$twhere.=' '.&mt('Section').': '.$tsection;
}
@@ -1111,7 +1358,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;
@@ -1183,7 +1431,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('
'); }
@@ -1209,7 +1457,7 @@ sub roletable_headers {
}
sub roletypes {
- my @types = ('Domain','Construction Space','Course','Community','Unavailable','System');
+ my @types = ('Domain','Authoring Space','Course','Placement Test','Community','Unavailable','System');
return @types;
}
@@ -1232,12 +1480,15 @@ sub print_rolerows {
&Apache::loncommon::end_data_table_row();
}
}
- if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
+ if ($sortrole->{$which} =~ m{^user\.role\.dc\./($match_domain)/}) {
if (ref($dcroles) eq 'HASH') {
if ($dcroles->{$1}) {
$output .= &adhoc_roles_row($1,'');
}
}
+ } elsif (($sortrole->{$which} =~ m{^user\.role\.dh\./($match_domain)/}) &&
+ ($env{'environment.adhocroles.'.$1} ne '')) {
+ $output .= &adhoc_customroles_row($1,'');
}
}
}
@@ -1258,7 +1509,7 @@ sub print_rolerows {
}
sub findcourse_advice {
- my ($r) = @_;
+ 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'})) {
@@ -1273,37 +1524,36 @@ sub findcourse_advice {
} else {
$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.').' ');
}
- $r->print('
'.&mt('Self-Enrollment').'
'.
- '
'.&mt('The [_1]Course/Community Catalog[_2] provides information about all [_3] classes for which LON-CAPA courses have been created, as well as any communities in the domain.','','',$domdesc).' ');
- $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'
'.&mt('The [_1]Course/Community Catalog[_2] provides information about all [_3] classes for which LON-CAPA courses have been created, as well as any communities in the domain.','','',$domdesc).' ');
+ $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'
'.
+ &Apache::loncoursequeueadmin::queued_selfenrollment());
+ }
return;
}
sub requestcourse_advice {
- my ($r) = @_;
+ 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.'')
- .'
'.&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):').
+ '
'.
+ $output.
+ '
'.
+ &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;
}
@@ -1348,7 +1615,7 @@ sub privileges_info {
my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
if ($trest) {
if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
- $ttype='Construction Space';
+ $ttype='Authoring Space';
$twhere='User: '.$trest.', Domain: '.$tdom;
} else {
$ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
@@ -1389,7 +1656,8 @@ sub privileges_info {
}
sub build_roletext {
- my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning) = @_;
+ my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,
+ $tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning,$skipcal) = @_;
my ($roletext,$roletext_end);
my $is_dc=($trolecode =~ m/^dc\./);
my $rowspan=($is_dc) ? ''
@@ -1445,7 +1713,7 @@ sub build_roletext {
$trolecode."','".$buttonname.'\');" />';
}
}
- if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
+ if (($trolecode !~ m/^(dc|ca|au|aa)\./) && (!$skipcal)) {
$tremark.=&Apache::lonannounce::showday(time,1,
&Apache::lonannounce::readcalendar($tdom.'_'.$trest));
}
@@ -1461,24 +1729,6 @@ sub build_roletext {
return ($roletext,$roletext_end);
}
-sub check_needs_switchserver {
- my ($possiblerole) = @_;
- my $needs_switchserver;
- my ($role,$where) = split(/\./,$possiblerole,2);
- my (undef,$tdom,$twho) = split(/\//,$where);
- my ($server_status,$home);
- if (($role eq 'ca') || ($role eq 'aa')) {
- ($server_status,$home) = &check_author_homeserver($twho,$tdom);
- } else {
- ($server_status,$home) = &check_author_homeserver($env{'user.name'},
- $env{'user.domain'});
- }
- if ($server_status eq 'switchserver') {
- $needs_switchserver = 1;
- }
- return $needs_switchserver;
-}
-
sub check_author_homeserver {
my ($uname,$udom)=@_;
if (($uname eq '') || ($udom eq '')) {
@@ -1496,46 +1746,68 @@ sub check_author_homeserver {
}
}
-sub check_fordc {
- my ($dcroles,$then) = @_;
+sub check_for_adhoc {
+ my ($dcroles,$dhroles,$update,$then) = @_;
my $numdc = 0;
+ my $numdh = 0;
+ my $numadhoc = 0;
+ my $num_custom_adhoc = 0;
if ($env{'user.adv'}) {
- foreach my $envkey (sort keys %env) {
- if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
- my $dcdom = $1;
- my $livedc = 1;
+ foreach my $envkey (sort(keys(%env))) {
+ if ($envkey=~/^user\.role\.(dc|dh)\.\/($match_domain)\/$/) {
+ my $role = $1;
+ my $roledom = $2;
+ my $liverole = 1;
my ($tstart,$tend)=split(/\./,$env{$envkey});
- if ($tstart && $tstart>$then) { $livedc = 0; }
- if ($tend && $tend <$then) { $livedc = 0; }
- if ($livedc) {
- $$dcroles{$dcdom} = $envkey;
- $numdc++;
+ my $limit = $update;
+ if ((($role eq 'dc') && ($env{'request.role'} eq 'dc./'.$roledom.'/')) ||
+ (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$roledom.'/'))) {
+ $limit = $then;
+ }
+ if ($tstart && $tstart>$limit) { $liverole = 0; }
+ if ($tend && $tend <$limit) { $liverole = 0; }
+ if ($liverole) {
+ if ($role eq 'dc') {
+ $dcroles->{$roledom} = $envkey;
+ $numdc++;
+ } else {
+ $dhroles->{$roledom} = $envkey;
+ if ($env{'environment.adhocroles.'.$roledom} ne '') {
+ $numadhoc ++;
+ }
+ $numdh++;
+ }
}
}
}
}
- return $numdc;
+ return ($numdc,$numdh,$numadhoc);
}
sub adhoc_course_role {
- my ($refresh,$then) = @_;
+ my ($refresh,$update,$then) = @_;
my ($cdom,$cnum,$crstype);
$cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
$cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
$crstype = &Apache::loncommon::course_type();
- if (&check_forcc($cdom,$cnum,$refresh,$then,$crstype)) {
+ if (&check_forcc($cdom,$cnum,$refresh,$update,$then,$crstype)) {
my $setprivs;
if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
$setprivs = 1;
} else {
my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
if (($start && ($start>$refresh || $start == -1)) ||
- ($end && $end<$then)) {
+ ($end && $end<$update)) {
+ $setprivs = 1;
+ }
+ }
+ unless ($setprivs) {
+ if (!exists($env{'user.priv.'.$env{'form.switchrole'}.'./'})) {
$setprivs = 1;
}
}
if ($setprivs) {
- if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
+ if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)(.*?)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
my $role = $1;
my $custom_role = $2;
my $usec = $3;
@@ -1561,7 +1833,11 @@ sub adhoc_course_role {
$spec .= '/'.$usec;
$area .= '/'.$usec;
}
- &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
+ if ($role =~ /^cr/) {
+ &Apache::lonnet::custom_roleprivs(\%newrole,$role,$cdom,$cnum,$spec,$area);
+ } else {
+ &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
+ }
&Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
my $adhocstart = $refresh-1;
$userroles{'user.role.'.$spec} = $adhocstart.'.';
@@ -1573,134 +1849,49 @@ sub adhoc_course_role {
}
sub check_forcc {
- my ($cdom,$cnum,$refresh,$then,$crstype) = @_;
+ my ($cdom,$cnum,$refresh,$update,$then,$crstype) = @_;
my ($is_cc,$ccrole);
if ($crstype eq 'Community') {
$ccrole = 'co';
} else {
$ccrole = 'cc';
}
- if ($cdom ne '' && $cnum ne '') {
- if (&Apache::lonnet::is_course($cdom,$cnum)) {
- my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
- if (defined($env{$envkey})) {
- $is_cc = 1;
- my ($tstart,$tend)=split(/\./,$env{$envkey});
- if ($tstart && $tstart>$refresh) { $is_cc = 0; }
- if ($tend && $tend <$then) { $is_cc = 0; }
+ if (&Apache::lonnet::is_course($cdom,$cnum)) {
+ my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
+ if (defined($env{$envkey})) {
+ $is_cc = 1;
+ my ($tstart,$tend)=split(/\./,$env{$envkey});
+ my $limit = $update;
+ if ($env{'request.role'} eq $ccrole.'./'.$cdom.'/'.$cnum) {
+ $limit = $then;
}
+ if ($tstart && $tstart>$refresh) { $is_cc = 0; }
+ if ($tend && $tend <$limit) { $is_cc = 0; }
}
}
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);
- 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);
- 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 update_content_constraints {
- my ($cdom,$cnum,$chome,$cid) = @_;
- my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
- my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
- my %checkresponsetypes;
- foreach my $key (keys(%Apache::lonnet::needsrelease)) {
- my ($item,$name,$value) = split(/:/,$key);
- if ($item eq 'resourcetag') {
- if ($name eq 'responsetype') {
- $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
- }
- }
- }
- my $navmap = Apache::lonnavmaps::navmap->new();
- if (defined($navmap)) {
- my %allresponses;
- foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
- my %responses = $res->responseTypes();
- foreach my $key (keys(%responses)) {
- next unless(exists($checkresponsetypes{$key}));
- $allresponses{$key} += $responses{$key};
- }
- }
- foreach my $key (keys(%allresponses)) {
- my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
- if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
- ($reqdmajor,$reqdminor) = ($major,$minor);
- }
- }
- undef($navmap);
- }
- unless (($reqdmajor eq '') && ($reqdminor eq '')) {
- &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
- }
- return;
-}
-
sub courselink {
- my ($dcdom,$rowtype) = @_;
+ my ($roledom,$rowtype,$role) = @_;
my $courseform=&Apache::loncommon::selectcourse_link
- ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
- 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
- $dcdom,$dcdom,undef,'Course/Community');
- my $hiddenitems = ''.
- ''.
- ''.
- '';
+ ('rolechoice','course'.$rowtype.'_'.$roledom.'_'.$role,
+ 'domain'.$rowtype.'_'.$roledom.'_'.$role,
+ 'coursedesc'.$rowtype.'_'.$roledom.'_'.$role,
+ $roledom.':'.$role,undef,'Course/Community');
+ my $hiddenitems = ''.
+ ''.
+ ''.
+ '';
return $courseform.$hiddenitems;
}
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";