[LON-CAPA-cvs] cvs: loncom /interface lonrequestcourse.pm
raeburn
raeburn@source.lon-capa.org
Sat, 05 Sep 2009 20:24:15 -0000
This is a MIME encoded message
--raeburn1252182255
Content-Type: text/plain
raeburn Sat Sep 5 20:24:15 2009 EDT
Modified files:
/loncom/interface lonrequestcourse.pm
Log:
- &update_requestors_roles()
- New routine to immediately add roles to course requestor's session
if request is processed immediately.
- Links to new course roles displayed following course creation.
- Change separators used in options in role selector from _ to /
--raeburn1252182255
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20090905202415.txt"
Index: loncom/interface/lonrequestcourse.pm
diff -u loncom/interface/lonrequestcourse.pm:1.27 loncom/interface/lonrequestcourse.pm:1.28
--- loncom/interface/lonrequestcourse.pm:1.27 Mon Aug 31 14:57:06 2009
+++ loncom/interface/lonrequestcourse.pm Sat Sep 5 20:24:15 2009
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Request a course
#
-# $Id: lonrequestcourse.pm,v 1.27 2009/08/31 14:57:06 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.28 2009/09/05 20:24:15 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -102,8 +102,6 @@
=item check_autolimit()
-=item build_batchcreatehash()
-
=item retrieve_settings()
=item get_request_settings()
@@ -1264,14 +1262,13 @@
$type = 'Community';
}
foreach my $role (@roles) {
- my $plrole=&Apache::lonnet::plaintext($role,$type);
+ my $plrole = &Apache::lonnet::plaintext($role,$type);
$roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
}
my %customroles=&Apache::lonuserutils::my_custom_roles();
if (keys(%customroles) > 0) {
foreach my $cust (sort(keys(%customroles))) {
- my $custrole='cr_cr_'.$env{'user.domain'}.
- '_'.$env{'user.name'}.'_'.$cust;
+ my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust";
$roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
}
}
@@ -1778,13 +1775,13 @@
if ($env{'form.person_'.$i.'_role'} eq 'cc') {
$showsec = &mt('None');
}
+ my $role = $env{'form.person_'.$i.'_role'};
$personnel_values .=
'<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
$env{'form.person_'.$i.'_lastname'}.'</td>'.
'<td>'.$env{'form.person_'.$i.'_uname'}.':'.
$env{'form.person_'.$i.'_dom'}.'</td>'.
- '<td>'.&Apache::lonnet::plaintext($env{'form.person_'.$i.'_role'},
- $container).'</td>'.
+ '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
'<td>'.$showsec.'</td></tr>';
}
}
@@ -2324,9 +2321,10 @@
if ($result eq 'created') {
$disposition = 'created';
$reqstatus = 'created';
- $output = &mt('Your course request has been processed and the course has been created.').
- '<br />'.
- &mt('You will need to logout and log-in again to be able to select a role in the course.');
+ my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
+ \%longroles);
+ $output = '<p>'.&mt('Your course request has been processed and the course has been created.').
+ '<br />'.$role_result.'</p>';
$creationresult = 'created';
} else {
$output = '<span class="LC_error">'.
@@ -2393,7 +2391,7 @@
$output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'</span><br />';
&Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
} elsif ($statusresult ne 'ok') {
- $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'</span><br />';
+ $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'</span><br />';
&Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
}
if ($modified && $queued && $storeresult eq 'ok') {
@@ -2411,6 +2409,113 @@
}
}
+sub update_requestors_roles {
+ my ($dom,$cnum,$crstype,$details,$longroles) = @_;
+ my $now = time;
+ my ($active,$future,$numactive,$numfuture,$output);
+ my $owner = $env{'user.name'}.':'.$env{'user.domain'};
+ if (ref($details) eq 'HASH') {
+ if (ref($details->{'personnel'}) eq 'HASH') {
+ if (ref($details->{'personnel'}{$owner}) eq 'HASH') {
+ my @roles;
+ if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
+ @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
+ unless (grep(/^cc$/,@roles)) {
+ push(@roles,'cc');
+ }
+ } else {
+ @roles = ('cc');
+ }
+ foreach my $role (@roles) {
+ my $start = $now;
+ my $end = '0';
+ if ($role eq 'st') {
+ if ($details->{'accessstart'} ne '') {
+ $start = $details->{'accessstart'};
+ }
+ if ($details->{'accessend'} ne '') {
+ $end = $details->{'accessend'};
+ }
+ }
+ my @usecs;
+ if ($role ne 'cc') {
+ if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
+ @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
+ }
+ }
+ if ($role eq 'st') {
+ if (@usecs > 1) {
+ my $firstsec = $usecs[0];
+ @usecs = ($firstsec);
+ }
+ }
+ if (@usecs == 0) {
+ push(@usecs,'');
+ }
+ foreach my $usec (@usecs) {
+ my (%userroles,%newrole,%newgroups,$spec,$area);
+ my $area = '/'.$dom.'/'.$cnum;
+ my $spec = $role.'.'.$area;
+ if ($usec ne '') {
+ $spec .= '/'.$usec;
+ $area .= '/'.$usec;
+ }
+ if ($role =~ /^cr\//) {
+ &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
+ $cnum,$spec,$area);
+ } else {
+ &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
+ $spec,$cnum,$area);
+ }
+ &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
+ \%newgroups);
+ $userroles{'user.role.'.$spec} = $start.'.'.$end;
+ &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
+ if (($end == 0) || ($end > $now)) {
+ my $showrole = $role;
+ if ($role =~ /^cr\//) {
+ $showrole = &Apache::lonnet::plaintext($role,$crstype);
+ } elsif (ref($longroles) eq 'HASH') {
+ if ($longroles->{$role} ne '') {
+ $showrole = $longroles->{$role};
+ }
+ }
+ if ($start <= $now) {
+ $active .= '<li><a href="/adm/roles?selectrole=1&'. $spec.'=1">'.$showrole;
+ if ($usec ne '') {
+ $active .= ' - '.&mt('section:').' '.$usec;
+ }
+ $active .= '</a></li>';
+ $numactive ++;
+ } else {
+ $future .= '<li>'.$showrole;
+ if ($usec ne '') {
+ $future .= ' - '.&mt('section:').' '.$usec;
+ }
+ $future .= '</li>';
+ $numfuture ++;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if ($active) {
+ if ($numactive == 1) {
+ $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:');
+ }
+ $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>';
+ }
+ return $output;
+}
+
sub notification_information {
my ($disposition,$req_notifylist,$cnum,$now) = @_;
my %emails = &Apache::loncommon::getemails();
--raeburn1252182255--