[LON-CAPA-cvs] cvs: loncom /interface lonrequestcourse.pm
raeburn
raeburn@source.lon-capa.org
Thu, 10 Dec 2009 18:21:22 -0000
This is a MIME encoded message
--raeburn1260469282
Content-Type: text/plain
raeburn Thu Dec 10 18:21:22 2009 EDT
Modified files:
/loncom/interface lonrequestcourse.pm
Log:
- Accommodate Communities.
--raeburn1260469282
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20091210182122.txt"
Index: loncom/interface/lonrequestcourse.pm
diff -u loncom/interface/lonrequestcourse.pm:1.40 loncom/interface/lonrequestcourse.pm:1.41
--- loncom/interface/lonrequestcourse.pm:1.40 Wed Nov 18 19:15:44 2009
+++ loncom/interface/lonrequestcourse.pm Thu Dec 10 18:21:22 2009
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Request a course
#
-# $Id: lonrequestcourse.pm,v 1.40 2009/11/18 19:15:44 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.41 2009/12/10 18:21:22 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1696,12 +1696,12 @@
}
my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
- my $roleoptions;
- my @roles = &Apache::lonuserutils::roles_by_context('course');
my $type = 'Course';
if ($crstype eq 'community') {
$type = 'Community';
}
+ my $roleoptions;
+ my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
foreach my $role (@roles) {
my $plrole = &Apache::lonnet::plaintext($role,$type);
$roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
@@ -2217,15 +2217,18 @@
}
my $container = 'Course';
+ my $ccrole = 'cc';
if ($env{'form.crstype'} eq 'community') {
$container = 'Community';
+ $ccrole = 'co';
}
$personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
'</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
'</th>';
+
$personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
- '<td>'.&Apache::lonnet::plaintext('cc',$container).'</td>'.
+ '<td>'.&Apache::lonnet::plaintext($ccrole,$container).'</td>'.
'<td>'.&mt('None').'</td></tr>';
for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
if ($env{'form.person_'.$i.'_uname'} ne '') {
@@ -2261,7 +2264,7 @@
if ($showsec eq '') {
$showsec = &mt('None');
}
- if ($env{'form.person_'.$i.'_role'} eq 'cc') {
+ if ($env{'form.person_'.$i.'_role'} eq $ccrole) {
$showsec = &mt('None');
}
my $role = $env{'form.person_'.$i.'_role'};
@@ -2623,6 +2626,10 @@
}
$now = time;
$crstype = $env{'form.crstype'};
+ my $ccrole = 'cc';
+ if ($crstype eq 'community') {
+ $ccrole = 'co';
+ }
my @instsections;
if ($crstype eq 'official') {
if (&Apache::lonnet::auto_run('',$dom)) {
@@ -2684,7 +2691,7 @@
} else {
@{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
}
- if ($role eq 'cc') {
+ if ($role eq $ccrole) {
@{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
} else {
my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
@@ -2847,11 +2854,11 @@
} elsif ($disposition eq 'process') {
my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
- my @roles = &Apache::lonuserutils::roles_by_context('course');
my $type = 'Course';
if ($crstype eq 'community') {
$type = 'Community';
}
+ my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
foreach my $role (@roles) {
$longroles{$role}=&Apache::lonnet::plaintext($role,$type);
}
@@ -2973,20 +2980,24 @@
my $owner = $env{'user.name'}.':'.$env{'user.domain'};
if (ref($details) eq 'HASH') {
if (ref($details->{'personnel'}) eq 'HASH') {
+ my $ccrole = 'cc';
+ if ($crstype eq 'community') {
+ $ccrole = 'co';
+ }
unless (ref($details->{'personnel'}{$owner}) eq 'HASH') {
$details->{'personnel'}{$owner} = {
- 'roles' => ['cc'],
- 'cc' => { 'usec' => [] },
+ 'roles' => [$ccrole],
+ $ccrole => { 'usec' => [] },
};
}
my @roles;
if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
@roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
- unless (grep(/^cc$/,@roles)) {
- push(@roles,'cc');
+ unless (grep(/^\Q$ccrole\E$/,@roles)) {
+ push(@roles,$ccrole);
}
} else {
- @roles = ('cc');
+ @roles = ($ccrole);
}
foreach my $role (@roles) {
my $start = $now;
@@ -3000,7 +3011,7 @@
}
}
my @usecs;
- if ($role ne 'cc') {
+ if ($role ne $ccrole) {
if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
@usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
}
@@ -3065,15 +3076,27 @@
}
if ($active) {
if ($numactive == 1) {
- $output = &mt('Use the following link to enter the course:');
+ if ($crstype eq 'Community') {
+ $output = &mt('Use the following link to enter the community:');
+ } else {
+ $output = &mt('Use the following link to enter the course:');
+ }
} else {
- $output = &mt('Use the following links to your new roles to enter the course:');
+ if ($crstype eq 'Community') {
+ $output = &mt('Use the following links to your new roles to enter the community:');
+ } else {
+ $output = &mt('Use the following links to your new roles to enter the course:');
+ }
}
$output .= ' <ul>'.$active.'</ul><br />';
}
if ($future) {
- $output .= &mt('The following course [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'<a href="/adm/roles">','</a>',&Apache::lonlocal::locallocaltime($details->{'accessstart'})).
- ' <ul>'.$future.'</ul>';
+ if ($crstype eq 'Community') {
+ $output .= &mt('The following community [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'<a href="/adm/roles">','</a>',&Apache::lonlocal::locallocaltime($details->{'accessstart'}))
+ } else {
+ $output .= &mt('The following course [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'<a href="/adm/roles">','</a>',&Apache::lonlocal::locallocaltime($details->{'accessstart'}));
+ }
+ $output .= ' <ul>'.$future.'</ul>';
}
return $output;
}
@@ -3206,31 +3229,34 @@
sub check_autolimit {
my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
- 'userroles',['active','future'],['cc'],[$dom]);
+ 'userroles',['active','future'],['cc','co'],[$dom]);
my ($types,$typename) = &Apache::loncommon::course_types();
my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
- my %count;
- if (ref($types) eq 'ARRAY') {
- foreach my $type (@{$types}) {
- $count{$type} = 0;
- }
- }
+ my $count = 0;
foreach my $key (keys(%requests)) {
my ($cdom,$cnum) = split('_',$key);
- if (exists($crsroles{$cnum.':'.$cdom.':cc'})) {
- if (ref($requests{$key}) eq 'HASH') {
- my $type = $requests{$key}{'crstype'};
- if ($type =~ /^official|unofficial|community$/) {
- $count{$type} ++;
- }
+ if (ref($requests{$key}) eq 'HASH') {
+ next if ($requests{$key}{'crstype'} ne $crstype);
+ if (($crstype eq 'community') &&
+ (exists($crsroles{$cnum.':'.$cdom.':co'}))) {
+ $count ++;
+ } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial')) &&
+ (exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
+ $count ++;
}
}
}
- if ($count{$crstype} < $limit) {
+ if ($count < $limit) {
return 'process';
} else {
if (ref($typename) eq 'HASH') {
- $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').'<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
+ if ($crstype eq 'community') {
+ $$message = &mt('Your request has not been processed because you have reached the limit for the number of communities.').
+ '<br />'.&mt("Your limit is [_1].",$limit);
+ } else {
+ $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').
+ '<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
+ }
}
return 'rejected';
}
--raeburn1260469282--