--- loncom/auth/lonroles.pm 2016/10/27 22:53:48 1.269.2.28
+++ loncom/auth/lonroles.pm 2012/08/14 17:35:04 1.271
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.269.2.28 2016/10/27 22:53:48 raeburn Exp $
+# $Id: lonroles.pm,v 1.271 2012/08/14 17:35:04 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 REDIRECT);
+use Apache::Constants qw(:common);
use Apache::File();
use Apache::lonmenu;
use Apache::loncommon;
@@ -138,8 +138,6 @@ use Apache::lonlocal;
use Apache::lonpageflip();
use Apache::lonnavdisplay();
use Apache::loncoursequeueadmin;
-use Apache::longroup;
-use Apache::lonrss;
use GDBM_File;
use LONCAPA qw(:DEFAULT :match);
use HTML::Entities;
@@ -151,7 +149,6 @@ sub redirect_user {
&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' => $url,
@@ -166,11 +163,6 @@ sub redirect_user {
$url=~s/ /\%20/g;
$r->print(< $msg ');
+ if ($switchwarning) {
+ $r->print($switchwarning.' '
.&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
- .'
';
+ &update_session_roles();
+ &Apache::lonnet::appenv({'user.update.time' => $now});
+ $update = $now;
+ } else {
+ $reqauthor = ''.
+ &mt('An error occurred while activating your access to authoring space');
+ }
+ } elsif ($val eq 'approval') {
+ my $domconfiguser = &Apache::lonnet::get_domainconfiguser($env{'user.domain'});
+ if (&Apache::lonnet::put('requestauthorqueue',{ $env{'user.name'}.'_'.$val => $now },
+ $env{'user.domain'},$domconfiguser) eq 'ok') {
+ my %userrequest = (
+ author => {
+ timestamp => $now,
+ status => $val,
+ },
+ author_status => $val,
+ );
+ my $req_notifylist;
+ if (ref($domconfig{'requestauthor'}) eq 'HASH') {
+ if (ref($domconfig{'requestauthor'}{'notify'}) eq 'HASH') {
+ my $req_notifylist = $domconfig{'requestauthor'}{'notify'}{'approval'};
+ if ($req_notifylist) {
+ my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+ $env{'user.domain'});
+ my $sender = $env{'user.name'}.':'.$env{'user.domain'};
+ my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
+ &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,
+ "$fullname ($env{'user.name'}:$env{'user.domain'})",undef,$domdesc,
+ $now,'authorreq',$sender);
+ }
+ }
+ }
+ my $userresult =
+ &Apache::lonnet::put('requestauthor',\%userrequest,$env{'user.domain'},$env{'user.name'});
+ $reqauthor = ''.
+ &mt('Your request for authoring space has been submitted for approval.').
+ '';
+ &Apache::lonnet::appenv({'environment.requestauthorqueued' => $val.':'.$now});
+ } else {
+ $reqauthor = ''.
+ &mt('An error occurred saving your request for authoring space.').
+ '';
+ }
+ }
+ }
+ }
+ }
}
my $envkey;
my %dcroles = ();
- my %dhroles = ();
- my ($numdc,$numdh,$numadhoc) = &check_for_adhoc(\%dcroles,\%dhroles,$update,$then);
- my $loncaparev = $r->dir_config('lonVersion');
+ my $numdc = &check_fordc(\%dcroles,$update,$then);
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
+ my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'};
# ================================================================== Roles Init
if ($env{'form.selectrole'}) {
@@ -270,15 +329,8 @@ 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
@@ -300,142 +352,82 @@ 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.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) || ($numdh > 0)) {
+ &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'}});
# 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 trying to enter a course and needs privs to be created
- foreach my $envkey (keys(%env)) {
- if ($numdc) {
+ if ($numdc > 0) {
+ 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}) {
- if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,
- $update,$refresh,$now,$ccrole)) {
- &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time});
- }
+ if (my ($ccrole,$domain,$coursenum) =
+ ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
+ if ($dcroles{$domain}) {
+ &Apache::lonnet::check_adhoc_privs($domain,$coursenum,
+ $update,$refresh,$now,$ccrole);
+ }
+ last;
+ }
+# Is this an ad-hoc CA-role?
+ if (my ($domain,$user) =
+ ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
+ if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) {
+ delete($env{$envkey});
+ $env{'form.au./'.$domain.'/'} = 1;
+ my ($server_status,$home) = &check_author_homeserver($user,$domain);
+ if ($server_status eq 'switchserver') {
+ my $trolecode = 'au./'.$domain.'/';
+ my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
+ $r->internal_redirect($switchserver);
}
last;
}
-# Is this an ad-hoc CA-role?
- if (my ($domain,$user) =
- ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
- if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) {
- delete($env{$envkey});
- $env{'form.au./'.$domain.'/'} = 1;
+ if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
+ if (((($castart) && ($castart < $now)) || !$castart) &&
+ ((!$caend) || (($caend) && ($caend > $now)))) {
my ($server_status,$home) = &check_author_homeserver($user,$domain);
if ($server_status eq 'switchserver') {
- my $trolecode = 'au./'.$domain.'/';
+ my $trolecode = 'ca./'.$domain.'/'.$user;
my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
$r->internal_redirect($switchserver);
- return OK;
}
last;
}
- if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
- if (((($castart) && ($castart < $now)) || !$castart) &&
- ((!$caend) || (($caend) && ($caend > $now)))) {
- my ($server_status,$home) = &check_author_homeserver($user,$domain);
- if ($server_status eq 'switchserver') {
- my $trolecode = 'ca./'.$domain.'/'.$user;
- my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
- $r->internal_redirect($switchserver);
- return OK;
- }
- last;
- }
- }
- # Check if author blocked ca-access
- my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
- if ($blocked{'domcoord.author'} eq 'blocked') {
- delete($env{$envkey});
- $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
- last;
- }
- 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,$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});
- }
- } else {
- delete($env{$envkey});
- }
+ }
+ # Check if author blocked ca-access
+ my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
+ if ($blocked{'domcoord.author'} eq 'blocked') {
+ delete($env{$envkey});
+ $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
last;
}
- }
- if ($numdh) {
-# Is this an ad hoc custom role in a course/community?
- if (my ($domain,$rolename,$coursenum) = ($envkey =~ m{^form\.cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)$})) {
- if ($dhroles{$domain}) {
- my @adhoc;
- if ($env{'environment.adhocroles.'.$domain}) {
- @adhoc = split(',',$env{'environment.adhocroles.'.$domain});
- } else {
- my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
- 'adhocroles.'.$domain);
- if (keys(%adhocroles)) {
- @adhoc = split(',',$adhocroles{'adhocroles.'.$domain});
- }
- }
- if ((@adhoc > 0) && ($rolename ne '')) {
- if (grep(/^\Q$rolename\E$/,@adhoc)) {
- if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,$update,$refresh,$now,
- "cr/$domain/$domain".'-domainconfig/'.$rolename)) {
- &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.cr/$domain/$domain".
- '-domainconfig/'."$rolename.adhoc" => time});
- }
- } else {
- delete($env{$envkey});
- }
- } else {
- delete($env{$envkey});
+ 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,$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);
}
} else {
delete($env{$envkey});
}
- last;
+ } else {
+ delete($env{$envkey});
}
- }
+ last;
+ }
}
}
- 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,$update,$refresh,$now,\$role,\$where,
@@ -451,13 +443,30 @@ sub handler {
my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
my ($switchserver,$switchwarning) =
- &Apache::loncommon::check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,
- $curr_reqd_hash{'internal.releaserequired'});
+ &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;
- $r->print(&Apache::loncommon::check_release_result($switchwarning,$switchserver));
+ my $end_page=&Apache::loncommon::end_page();
+ $r->print(&Apache::loncommon::start_page('Selected course unavailable on this server').
+ '
');
+ 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('
'.&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.').'
';
+ my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});
+ my $standby=&mt('Role selected. Please stand by.');
+ $standby=~s/\n/\\n/g;
+ 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(<
'
+ .''.&mt('Logout').' '
+ .''
+ .&mt('Course/Community Catalog')
+ .'
'.&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.').'
'.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').'
'. - &mt('You have rights to request the creation of courses and/or communities in the following domain(s):'). - '