';
}
}
@@ -2324,9 +2321,10 @@ sub print_request_outcome {
if ($result eq 'created') {
$disposition = 'created';
$reqstatus = 'created';
- $output = &mt('Your course request has been processed and the course has been created.').
- ' '.
- &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 = '
'.&mt('Your course request has been processed and the course has been created.').
+ ' '.$role_result.'
';
$creationresult = 'created';
} else {
$output = ''.
@@ -2393,7 +2391,7 @@ sub print_request_outcome {
$output .= ''.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).' ';
&Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
} elsif ($statusresult ne 'ok') {
- $output .= ''.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).' ';
+ $output .= ''.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).' ';
&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 print_request_outcome {
}
}
+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 .= '
'.$showrole;
+ if ($usec ne '') {
+ $future .= ' - '.&mt('section:').' '.$usec;
+ }
+ $future .= '
';
+ $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 .= '
'.$active.'
';
+ }
+ 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,'','',&Apache::lonlocal::locallocaltime($details->{'accessstart'})).
+ '
'.$future.'
';
+ }
+ return $output;
+}
+
sub notification_information {
my ($disposition,$req_notifylist,$cnum,$now) = @_;
my %emails = &Apache::loncommon::getemails();