--- loncom/auth/lonroles.pm 2009/10/26 21:16:38 1.236
+++ loncom/auth/lonroles.pm 2010/03/16 19:55:31 1.245
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.236 2009/10/26 21:16:38 raeburn Exp $
+# $Id: lonroles.pm,v 1.245 2010/03/16 19:55:31 droeschl Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -138,25 +138,18 @@ use Apache::lonannounce;
use Apache::lonlocal;
use Apache::lonpageflip();
use Apache::lonnavdisplay();
+use Apache::loncoursequeueadmin;
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,
@@ -171,12 +164,6 @@ sub redirect_user {
$url=~s/ /\%20/g;
$r->print(<
-//
-
-$navwindow
$msg
$end_page
ENDREDIR
@@ -255,12 +242,12 @@ sub handler {
# 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) {
-# Is this an ad-hoc CC-role?
- if (my ($domain,$coursenum) =
- ($envkey =~ m-^form\.cc\./($match_domain)/($match_courseid)$-)) {
+# 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,'cc');
+ $then,$refresh,$now,$ccrole);
}
last;
}
@@ -491,8 +478,8 @@ ENDENTERKEY
$courseid = substr($courseid, 1);
}
$courseid =~ s/\//_/;
- if ($role eq 'cc' && $env{'course.' . $courseid .
- '.course.helper.not.run'}) {
+ if ((($role eq 'cc') || ($role eq 'co'))
+ && ($env{'course.' . $courseid .'.course.helper.not.run'})) {
$furl = "/adm/helper/course.initialization.helper";
# Send the user to the course they selected
} elsif ($env{'request.course.id'}) {
@@ -502,10 +489,9 @@ ENDENTERKEY
my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&');
$dest .= '?symb='.$esc_symb;
}
- &redirect_user($r,&mt('Entering [_1]',
- $env{'course.'.$courseid.'.description'}),
- $dest,$msg,
- $env{'environment.remotenavmap'});
+ &redirect_user($r, &mt('Entering [_1]',
+ $env{'course.'.$courseid.'.description'}),
+ $dest, $msg);
return OK;
}
if (&Apache::lonnet::allowed('whn',
@@ -518,9 +504,8 @@ ENDENTERKEY
unless ($startpage eq 'firstres') {
$msg = &mt('Entering [_1] ...',
$env{'course.'.$courseid.'.description'});
- &redirect_user($r,&mt('New in course'),
- '/adm/whatsnew?refpage=start',$msg,
- $env{'environment.remotenavmap'});
+ &redirect_user($r, &mt('New in course'),
+ '/adm/whatsnew?refpage=start', $msg);
return OK;
}
}
@@ -532,10 +517,9 @@ ENDENTERKEY
}
$msg = &mt('Entering [_1] ...',
$env{'course.'.$courseid.'.description'});
- &redirect_user($r,&mt('Entering [_1]',
- $env{'course.'.$courseid.'.description'}),
- $furl,$msg,
- $env{'environment.remotenavmap'});
+ &redirect_user($r, &mt('Entering [_1]',
+ $env{'course.'.$courseid.'.description'}),
+ $furl, $msg);
}
return OK;
}
@@ -704,13 +688,14 @@ ENDHEADER
$refresh = $now;
&Apache::lonnet::appenv({'user.refresh.time' => $refresh});
if ($env{'user.adv'}) {
- $r->print(
- '
'
+ .' '
+ .'
');
} else {
if ($countactive > 0) {
- &queued_selfenrollment($r);
+ $r->print(&Apache::loncoursequeueadmin::queued_selfenrollment());
my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
$r->print(
@@ -974,7 +959,7 @@ sub gather_roles {
} elsif ($trest) {
my $tcourseid=$tdom.'_'.$trest;
$ttype = &Apache::loncommon::course_type($tcourseid);
- $trole = &Apache::lonnet::plaintext($role,$ttype);
+ $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
if ($env{'course.'.$tcourseid.'.description'}) {
$twhere=$env{'course.'.$tcourseid.'.description'};
$sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
@@ -993,7 +978,7 @@ sub gather_roles {
&Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
'';
$ttype = $newhash{'type'};
- $trole = &Apache::lonnet::plaintext($role,$ttype);
+ $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
} else {
$twhere=&mt('Currently not available');
$env{'course.'.$tcourseid.'.description'}=$twhere;
@@ -1109,7 +1094,7 @@ sub roletable_headers {
}
sub roletypes {
- my @types = ('Domain','Construction Space','Course','Unavailable','System');
+ my @types = ('Domain','Construction Space','Course','Community','Unavailable','System');
return @types;
}
@@ -1173,8 +1158,8 @@ sub findcourse_advice {
}
$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.').'
');
- &queued_selfenrollment($r);
+ $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;
}
@@ -1188,14 +1173,20 @@ sub requestcourse_advice {
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 create 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):').'
');
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(&mt('[_1] in domain: [_2]',
- '
'
+ );
foreach my $dom (@{$request_doms{$type}}) {
unless (grep(/^\Q$dom\E/,@reqdoms)) {
push(@reqdoms,$dom);
@@ -1225,49 +1216,6 @@ sub requestcourse_advice {
return;
}
-sub queued_selfenrollment {
- my ($r) = @_;
- my %selfenrollrequests = &Apache::lonnet::dump('selfenrollrequests');
- my %reqs_by_date;
- foreach my $item (keys(%selfenrollrequests)) {
- if (ref($selfenrollrequests{$item}) eq 'HASH') {
- if ($selfenrollrequests{$item}{'status'} eq 'request') {
- if ($selfenrollrequests{$item}{'timestamp'}) {
- push(@{$reqs_by_date{$selfenrollrequests{$item}{'timestamp'}}},$item);
- }
- }
- }
- }
- if (keys(%reqs_by_date)) {
- my $rolename = &Apache::lonnet::plaintext('st');
- $r->print(''.&mt('Enrollment requests pending Course Coordinator approval').' '.
- &Apache::loncommon::start_data_table().
- &Apache::loncommon::start_data_table_header_row().
- '
'.&mt('Date requested').'
'.&mt('Course title').'
'.
- '
'.&mt('User role').'
'.&mt('Section').'
'.
- &Apache::loncommon::end_data_table_header_row());
- my @sorted = sort { $a <=> $b } (keys(%reqs_by_date));
- foreach my $item (@sorted) {
- if (ref($reqs_by_date{$item}) eq 'ARRAY') {
- foreach my $crs (@{$reqs_by_date{$item}}) {
- my %courseinfo = &Apache::lonnet::coursedescription($crs);
- my $usec = $selfenrollrequests{$crs}{'section'};
- if ($usec eq '') {
- $usec = &mt('No section');
- }
- $r->print(&Apache::loncommon::start_data_table_row().
- '
'.&Apache::lonlocal::locallocaltime($item).'
'.
- '
'.$courseinfo{'description'}.'
'.
- '
'.$rolename.'
'.$usec.'
'.
- &Apache::loncommon::end_data_table_row());
- }
- }
- }
- $r->print(&Apache::loncommon::end_data_table());
- }
- return;
-}
-
sub privileges_info {
my ($which) = @_;
my $output;
@@ -1447,10 +1395,11 @@ sub check_fordc {
sub adhoc_course_role {
my ($refresh,$then) = @_;
- my ($cdom,$cnum);
+ my ($cdom,$cnum,$crstype);
$cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
$cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- if (&check_forcc($cdom,$cnum,$refresh,$then)) {
+ $crstype = &Apache::loncommon::course_type();
+ if (&check_forcc($cdom,$cnum,$refresh,$then,$crstype)) {
my $setprivs;
if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
$setprivs = 1;
@@ -1500,11 +1449,16 @@ sub adhoc_course_role {
}
sub check_forcc {
- my ($cdom,$cnum,$refresh,$then) = @_;
- my $is_cc;
+ my ($cdom,$cnum,$refresh,$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.cc./'.$cdom.'/'.$cnum;
+ my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
if (defined($env{$envkey})) {
$is_cc = 1;
my ($tstart,$tend)=split(/\./,$env{$envkey});
@@ -1521,7 +1475,7 @@ sub courselink {
my $courseform=&Apache::loncommon::selectcourse_link
('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
- $dcdom,$dcdom,undef);
+ $dcdom,$dcdom,undef,'Course/Community');
my $hiddenitems = ''.
''.
''.
@@ -1531,7 +1485,7 @@ sub courselink {
sub coursepick_jscript {
my %lt = &Apache::lonlocal::texthash(
- plsu => "Please use the 'Select Course' link to open a separate pick course window where you may select the course or community you wish to enter.",
+ 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.',
);
my $verify_script = <<"END";
@@ -1584,9 +1538,10 @@ sub display_cc_role {
my $advanced = $env{'user.adv'};
my $tryagain = $env{'form.tryagain'};
unless ($rolekey =~/^error\:/) {
- if ($rolekey =~ m-^user\.role.cc\./($match_domain)/($match_courseid)$-) {
- my $tcourseid = $1.'_'.$2;
- my $trolecode = 'cc./'.$1.'/'.$2;
+ if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
+ my $ccrole = $1;
+ my $tcourseid = $2.'_'.$3;
+ my $trolecode = $1.'./'.$2.'/'.$3;
my $twhere;
my $ttype;
my $tbg='LC_roles_is';
@@ -1601,7 +1556,7 @@ sub display_cc_role {
$twhere=&mt('Currently not available');
$env{'course.'.$tcourseid.'.description'}=$twhere;
}
- my $trole = &Apache::lonnet::plaintext('cc',$ttype);
+ my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
$twhere.=" ".&mt('Domain').":".$1;
($roletext,$roletext_end) = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
}
@@ -1617,7 +1572,7 @@ sub adhoc_roles_row {
,'','',$dcdom)
.' ';
my $selectcclink = &courselink($dcdom,$rowtype);
- my $ccrole = &Apache::lonnet::plaintext('cc');
+ my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
my $carole = &Apache::lonnet::plaintext('ca');
my $selectcalink = &coauthorlink($dcdom,$rowtype);
$output.=$ccrole.': '.$selectcclink